d = SX.sym("d")
p = SX.zeros(2,1)
p[1,0] = 1/(1+exp(-(t-d)))
p[0,0] = 1 - p[1,0]
f = SXFunction([t,d],[p])
f.init()
print f([0,0]) # yes, returns 0.5 and 0.5
But I cannot obtain the derivatives...
df = f.derivative(1,0)
df.init() # must initiate
df.setInput(0,0) # (value, index)
df.setInput(0,1)
df.evaluate()
print df.getOutput() # NOT -0.25 and 0.25
My questions are
1. How to obtain derivatives correctly?
2. What is the second arg in f.derivative(1,0)? The document reads adjoint derivative. If I want to get hessian, just change the first arg.1 to 2?
3. In next stage, I want the lengths of t and d to vary because their lengths depend on the data structure. Everytime, the user may input different size of data. Is it possible to convert the code c code (going to be used by R program), but the length still can change flexibly?
Thanks.
f = SXFunction([input expression(s)],[output expression(s)])
f.init()
[numerical results] = f([numerical argument(s)]
d = SX.sym("d")
p = SX.zeros(2,1)
p[1,0] = 1/(1+exp(-(t-d)))
p[0,0] = 1 - p[1,0]
f = SXFunction([t,d],[p])
f.init()
df = jacobian(p,t)
dp = SX.zeros(2,1)
d1 = SXFunction([df],[dp])
XFunctionInternal::XFunctionInternal: Xfunction input arguments must be purely symbolic.
Argument #0 is not symbolic
I check the type of df, it is SX expression. No idea why it said df is not symbolic? Thanks.
import scipy # default abbrev. is sp
from scipy import stats as st
import numpy # default abbrev. is np
t = st.multivariate_normal.rvs(mean0,cov0,people); t = t.reshape(people,dim0)
a = np.matrix('1;2')
###### use MX
theta = MX.sym("theta",people,dim0)
alpha = MX.sym("alpha",dim0,1)
delta = MX.sym("delta")
probability = MX.zeros(people,point)
probability[:,1] = 1/(1+exp(-(mul(theta,alpha)-delta)))
probability[:,0] = 1 - probability[:,1]
probability = [probability[:,0],probability[:,1]]
p = MXFunction([alpha,delta,theta],probability) # symbol into function
p.init() # initiate function
#print p([a,0,t])
dp1 = MXFunction.hessian(p,0,0)
dp1.init() # initiate function
print dp1([a,0,t])
My question is about dp1. It returns alpha's hessian matrix. I know I can also get delta's and theta's respectively. But how to get their hessian matrix simultaneously? The full hessian matrix? Thanks.