简体   繁体   中英

How to use theano.gradient.hessian? Example needed

I tried the code below:

x=T.dvector('x')
y=T.dvector('y')
input=[x,y]
s=T.sum(x**2+y**2)
f=theano.gradient.hessian(s,wrt=input)
h=function(input,f)

Then I run it with following real values

x=[1,2]
y=[1,2]
h([x,y]

Then I encountered following error

TypeError: ('Bad input argument to theano function with name "<ipython-input-115-32fd257c46ad>:7"  at index 0(0-based)', 'Wrong number of dimensions: expected 1, got 2 with shape (2L, 2L).')

I am new to python and am exploring Theano for building neural networks.

h is a function that accepts two parameters. You are giving it a single parameter which is a list containing two elements.

Try changing h([x,y]) to h(x,y) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM