簡體   English   中英

T.hessian在theano中給出NotImplementedError()

[英]T.hessian gives NotImplementedError() in theano

它如何運作

    g_W = T.grad(cost=cost, wrt=classifier.vparamW) 

而這

    H_W=T.hessian(cost=cost, wrt=classifier.vparamW)

給出NotImplementedError()可能是這種成本函數中的問題:

    -T.mean(T.log(self.p_y_given_x)[T.arange(y.shape[0]), y]) 

這里y是從0到n-1的類標簽的向量,

    self.p_y_given_x = T.nnet.softmax(T.dot(input, self.W) + self.b) 

我無法使用提供的有限代碼來重現此問題。 但是,這是T.gradT.hessian的完整工作演示。

import numpy
import theano
import theano.tensor as T

x = T.matrix()
w_flat = theano.shared(numpy.random.randn(3, 2).astype(theano.config.floatX).flatten())
w = w_flat.reshape((3, 2))
cost = T.pow(theano.dot(x, w), 2).sum()
g_w = T.grad(cost=cost, wrt=[w])
h_w = T.hessian(cost=cost, wrt=[w_flat])
f = theano.function([x], outputs=g_w + h_w)
for output in f(numpy.random.randn(4, 3).astype(theano.config.floatX)):
    print output.shape, '\n', output

請注意, T.hessianwrt值必須是一個向量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM