How to use theano.gradient.hessian? Example needed

核能气质少年 提交于 2019-12-13 02:04:49

问题


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.


回答1:


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).



来源:https://stackoverflow.com/questions/30500332/how-to-use-theano-gradient-hessian-example-needed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!