MCPcopy Index your code
hub / github.com/lisa-lab/DeepLearningTutorials / MLP

Class MLP

code/mlp.py:115–198  ·  view source on GitHub ↗

Multi-Layer Perceptron Class A multilayer perceptron is a feedforward artificial neural network model that has one layer or more of hidden units and nonlinear activations. Intermediate layers usually have as activation function tanh or the sigmoid function (defined here by a ``Hidde

Source from the content-addressed store, hash-verified

113
114# start-snippet-2
115class MLP(object):
116 """Multi-Layer Perceptron Class
117
118 A multilayer perceptron is a feedforward artificial neural network model
119 that has one layer or more of hidden units and nonlinear activations.
120 Intermediate layers usually have as activation function tanh or the
121 sigmoid function (defined here by a ``HiddenLayer`` class) while the
122 top layer is a softmax layer (defined here by a ``LogisticRegression``
123 class).
124 """
125
126 def __init__(self, rng, input, n_in, n_hidden, n_out):
127 """Initialize the parameters for the multilayer perceptron
128
129 :type rng: numpy.random.RandomState
130 :param rng: a random number generator used to initialize weights
131
132 :type input: theano.tensor.TensorType
133 :param input: symbolic variable that describes the input of the
134 architecture (one minibatch)
135
136 :type n_in: int
137 :param n_in: number of input units, the dimension of the space in
138 which the datapoints lie
139
140 :type n_hidden: int
141 :param n_hidden: number of hidden units
142
143 :type n_out: int
144 :param n_out: number of output units, the dimension of the space in
145 which the labels lie
146
147 """
148
149 # Since we are dealing with a one hidden layer MLP, this will translate
150 # into a HiddenLayer with a tanh activation function connected to the
151 # LogisticRegression layer; the activation function can be replaced by
152 # sigmoid or any other nonlinear function
153 self.hiddenLayer = HiddenLayer(
154 rng=rng,
155 input=input,
156 n_in=n_in,
157 n_out=n_hidden,
158 activation=T.tanh
159 )
160
161 # The logistic regression layer gets as input the hidden units
162 # of the hidden layer
163 self.logRegressionLayer = LogisticRegression(
164 input=self.hiddenLayer.output,
165 n_in=n_hidden,
166 n_out=n_out
167 )
168 # end-snippet-2 start-snippet-3
169 # L1 norm ; one regularization option is to enforce L1 norm to
170 # be small
171 self.L1 = (
172 abs(self.hiddenLayer.W).sum()

Callers 1

test_mlpFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_mlpFunction · 0.68