This code I think works for me. Maybe this can help you with what you
want. I'm not sure what you are looking for without more explanation but
this takes a function and returns the gradient and hessian. I used it for
a homework assignment:
import theano
from theano import tensor as T
from theano.gradient import hessian
import math
import numpy as np
from numpy import linalg as LA
x = T.dscalar()
y = T.dscalar()
z = T.dscalar()
xnum = 1/math.sqrt(3)#values of x and y go here
ynum = 1/math.sqrt(3)
result = hf = [0 for each in range(2)]
f = x*y+x*T.sqrt(1-x**2-y**2)+y*T.sqrt(1-x**2-y**2)#function to solve
gf = T.grad(f,wrt=[x,y])#calculates the gradient
hf[0] = T.grad(gf[0], wrt=[x,y])#calculates the hessian here
hf[1] = T.grad(gf[1], wrt=[x,y])#and here they also have a hessian function but
couldn't get it to work well
result[0] = theano.function([x,y],hf[0])
result[1] = theano.function([x,y],hf[1])
numvalue = np.matrix([[result[0](xnum,ynum)[0],result[0](xnum,ynum)[1]]
,[result[1](xnum,ynum)[0],result[1](xnum,ynum)[1]]])
print(LA.eig(numvalue))#prints eigenvalues of hessian
On Monday, January 23, 2017 at 3:54:42 PM UTC-5, Pradeep A. Joglekar wrote:
>
> When I type x =scalar('myvar', dtype='int32'), I get error name scalar is
> not defined. How to proceed?
> Thanks,
> Pradeep
>
--
---
You received this message because you are subscribed to the Google Groups
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.