def __init__(self, rng, input, n_in, n_out, share_with=None, activation=None):
self.input = input
self.n_in = n_in
self.n_out = n_out
self.activation = activation
if share_with:
self.W = share_with.W
self.b = share_with.b
self.W_delta = share_with.W_delta
self.b_delta = share_with.b_delta
else:
W_values = np.asarray(
rng.uniform(
low=-np.sqrt(6. / (n_in + n_out)),
high=np.sqrt(6. / (n_in + n_out)),
size=(n_in, n_out)
),
dtype=theano.config.floatX
)
if activation == nnet.sigmoid:
W_values *= 4
self.W = theano.shared(value=W_values, name='W', borrow=True)
b_values = np.zeros((n_out,), dtype=theano.config.floatX)
self.b = theano.shared(value=b_values, name='b', borrow=True)
self.W_delta = theano.shared(
np.zeros((n_in, n_out), dtype=theano.config.floatX),
borrow=True
)
self.b_delta = theano.shared(value=b_values, borrow=True)
self.params = [self.W, self.b]
self.deltas = [self.W_delta, self.b_delta]
lin_output = T.dot(self.input, self.W) + self.b
if activation == 'tanh':
self.output = T.tanh(lin_output)
elif activation == 'sigmoid':
self.output = nnet.sigmoid(lin_output)
elif activation == 'relu':
self.output = T.maximum(lin_output, 0)
else:
self.output = lin_output