小编Kev*_*cki的帖子

结合Theano中的标量和矢量来计算Hessian

我正在尝试使用Theano来计算关于向量以及几个标量的函数的粗糙度(编辑:也就是说,我基本上希望附加到我正在计算粗麻布的向量的标量) .这是一个最小的例子:

import theano
import theano.tensor as T
A = T.vector('A')
b,c = T.scalars('b','c')
y = T.sum(A)*b*c
Run Code Online (Sandbox Code Playgroud)

我的第一次尝试是:

hy = T.hessian(y,[A,b,c])
Run Code Online (Sandbox Code Playgroud)

哪个失败了 AssertionError: tensor.hessian expects a (list of) 1 dimensional variable as 'wrt'

我的第二次尝试是将A,b和c与:

wrt = T.concatenate([A,T.stack(b,c)])
hy = T.hessian(y,[wrt])
Run Code Online (Sandbox Code Playgroud)

哪个失败了 DisconnectedInputError: grad method was asked to compute the gradient with respect to a variable that is not part of the computational graph of the cost, or is used only by a non-differentiable operator: Join.0

在这种情况下计算粗麻线的正确方法是什么?

更新:为了澄清我在寻找什么,假设A是2元素向量.然后黑森州将是:

[[d2y/d2A1, d2y/dA1dA2, d2y/dA1dB, …
Run Code Online (Sandbox Code Playgroud)

python concatenation theano hessian-matrix

5
推荐指数
1
解决办法
837
查看次数

标签 统计

concatenation ×1

hessian-matrix ×1

python ×1

theano ×1