T.hessian дает NotImplementedError () в 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) 

person Andrii Zadaianchuk    schedule 03.11.2015    source источник


Ответы (1)


Я не могу воспроизвести эту проблему с помощью предоставленного ограниченного кода. Однако вот полностью рабочая демонстрация T.grad и T.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

Обратите внимание, что значение wrt для T.hessian должно быть вектором.

person Daniel Renshaw    schedule 03.11.2015