def __init__(self, input, n_in, n_out, prefix='Logist'):
# initialize with 0 the weights W as a matrix of shape (n_in, n_out)
self.W = param_init().uniform((n_in, n_out), name=_p(prefix, 'W'))
# initialize the baises b as a vector of n_out 0s
self.b = param_init().constant((n_out,), name=_p(prefix, 'b'))
# compute vector of class-membership probabilities in symbolic form
energy = theano.dot(input, self.W) + self.b
if energy.ndim == 3:
energy_exp = T.exp(energy - T.max(energy, 2, keepdims=True))
pmf = energy_exp / energy_exp.sum(2, keepdims=True)
else:
pmf = T.nnet.softmax(energy)
self.p_y_given_x = pmf
self.y_pred = T.argmax(self.p_y_given_x, axis=-1)
# compute prediction as class whose probability is maximal in
# symbolic form
# parameters of the model
self.params = [self.W, self.b]
评论列表
文章目录