Hy everyone,
I would like to price vanilla options with Nd4J.
So i am looking to achieve the operation with Nd4J
max(0,X[i]-K) => Y[i]
with
X the input INDArray
K a float
Y the output INDArray
Is someone have an idea how to proceed ?
Thanks by advance for the time you could according to me
I am answering to myslef
INDArray Y=Transforms.max(X.add(-K), 0f);
Related
I have used CVXPY and some of its LP solvers to determine whether a solution to an A*x <= b problem is feasible, and now I would like to try PySCIPOpt. I could not find an example of this in the docs, and I'm having trouble figuring out the right syntax. With CVXPY the code is simply:
def do_cvxpy(A, b, solver):
x = cvxpy.Variable(A.shape[1])
constraints = [A#x <= b] #The # denotes matrix multiplication in CVXPY
obj = cvxpy.Minimize(0)
prob = cvxpy.Problem(obj, constraints)
prob.solve(solver=solver)
return prob.status
I think with PySCIPOpt one cannot use matrix notation as above, but must treat vectors and matrices as collections of scalar variables, each of which has to be added individually, so I tried this:
def do_scip(A, b):
model = Model("XYZ")
x = {}
for i in range(A.shape[1]):
x[i] = model.addVar(vtype="C", name="x(%s)" % i)
model.setObjective(0) #Is this right for a feasibility-only problem?
model.addCons(A*x <= b) #This is certainly the wrong syntax
model.optimize()
return model.getStatus()
Could anyone please help me out with the correct form for the constraint in addCons() for this kind of problem, and confirm that an acceptable way to ask whether a solution is feasible is to simply pass 0 as the objective?
I'm still not positive about the setObjective(0), but at least I can get the code to run without errors by "unpacking" the A matrix and the b vector and adding each element as a constraint:
for i in range(ncols):
for j in range(nrows):
model.addCons(A[j,i]*x[i] <= b[i])
I also discovered that CVXPY actually has an interface to SCIP, but it gives me an error when I try to use it:
getSolObjVal cannot only be called in stage SOLVING without a valid solution
which seems to suggest that the interface cannot be used for feasibility-only problems.
It seems that there is no simple way to assign a value to the diagonal of a Tensor. Ideally I am looking for a command like numpy.fill_diagonal.
Currently I accomplish this by doing:
tf.matrix_set_diag(
matrix,
tf.zeros_like(matrix.shape[0:-1]),
name=None
)
Is there a better way?
I think your answer should be:
tf.matrix_set_diag(matrix, tf.zeros(matrix.shape[0:-1]), name=None)
This should be updated to tf.linalg.set_diag, which can be found here
I've been told I need to normalise my MSE for my thesis involving neural networks.
Equations for NMSE seem a bit few and far-between. I have the following and want to corroborate it if possible:
Is the standard deviation term supposed to be calculated from the target values or the predicted values?
Also, what are the main advantages for using MSE over NMSE? Is it just that it makes error comparisons easier, because of the simpler scale?
Many thanks for any help!
def nmser(x,y):
z=0
if len(x)==len(y):
for k in range(len(x)):
z = z + (((x[k]-y[k])**2)/x[k])
z = z/(len(x))
return z
A simple question but I am confused.
Which one is bigger,
O(n^2log(n)) or O(n^3)?
Thanks in advance.
Adding onto the comments, you can always plot it on a graph or plug in very large numbers into a calculator and see where the values. O(n) > O(logn), and as this is O(N^2) * X, where one X is O(n) and another is O(logn), you can find out that O(N^3) is larger as you are multiplying.
Useful tool: http://www.wolframalpha.com/widgets/view.jsp?id=57ad04c0f04cc92e742205985c18023e
I am trying to make a diagonal translation using object animator in Android. Following code makes a translation in Y Axis.
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(button, "translationY", -value);
Any suggestions?
Thanks in advance
You can use an AnimatorSet with two ObjectAnimators, one performing the Y translation (as in the example in your question), and a very similar one doing the X translation. Make sure to use the playTogether(..) method of the AnimatorSet and you can animate both X and Y at the same time!