如何使用 theano.gradient.hessian?需要的例子 [英] How to use theano.gradient.hessian? Example needed

查看:18
本文介绍了如何使用 theano.gradient.hessian?需要的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下代码:

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]

然后我遇到了以下错误

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

我是 Python 新手,正在探索 Theano 以构建神经网络.

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

推荐答案

h 是一个接受两个参数的函数.你给它一个参数,它是一个包含两个元素的列表.

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

尝试将 h([x,y]) 更改为 h(x,y).

这篇关于如何使用 theano.gradient.hessian?需要的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆