Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import numpy
- import theano
- import theano.tensor as T
- class DenseLayer(object):
- def __init__(self, rng, input, n_in, n_out, W=None, b=None,
- activation=T.tanh):
- self.input = input
- if W is None:
- W_values = numpy.asarray(
- numpy.random.uniform(
- low=-numpy.sqrt(6. / (n_in + n_out)),
- high=numpy.sqrt(6. / (n_in + n_out)),
- size=(n_in, n_out)
- ),
- dtype=theano.config.floatX # @UndefinedVariable
- )
- W = theano.shared(value=W_values, name='W', borrow=True)
- if b is None:
- b_values = numpy.zeros((n_out,), dtype=theano.config.floatX) # @UndefinedVariable
- b = theano.shared(value=b_values, name='b', borrow=True)
- self.W = W
- self.b = b
- if activation is None:
- self.y_pred = T.dot(input, self.W) + self.b
- else:
- self.output = activation(T.dot(input, self.W) + self.b)
- self.params = [self.W, self.b]
- def mse(self, y):
- return T.mean((self.y_pred.T-y)**2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement