0
我正在學習如何使用Theano實現邏輯迴歸的教程。列出的行給我一個錯誤。我不知道如何解決它。在theano中使用grad的錯誤
from theano import tensor
TS = tensor.matrix('training-set')
W = tensor.matrix('weights')
E = tensor.matrix('expected')
O = tensor.dot(TS,W)
def_err = ((E-O)**2).sum()
e = function([W,TS,E],def_err)
grad_err = function([W,TS,E],grad(e,W))
這是我收到的錯誤:
\in grad(cost, wrt, consider_constant, disconnected_inputs, add_names, known_grads, return_disconnected, null_gradients)
428 raise AssertionError("cost and known_grads can't both be None.")
429
--> 430 if cost is not None and isinstance(cost.type, NullType):
431 raise ValueError("Can't differentiate a NaN cost."
432 "cost is NaN because " +
AttributeError: 'Function' object has no attribute 'type'