Initialize the parameters for the multilayer perceptron :type rng: numpy.random.RandomState :param rng: a random number generator used to initialize weights :type input: theano.tensor.TensorType :param input: symbolic variable that describes the input of the
(self, rng, input, n_in, n_hidden, n_out)
| 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() |
| 173 | + abs(self.logRegressionLayer.W).sum() |
| 174 | ) |
| 175 | |
| 176 | # square of L2 norm ; one regularization option is to enforce |
| 177 | # square of L2 norm to be small |
| 178 | self.L2_sqr = ( |
| 179 | (self.hiddenLayer.W ** 2).sum() |
| 180 | + (self.logRegressionLayer.W ** 2).sum() |
| 181 | ) |
| 182 | |
| 183 | # negative log likelihood of the MLP is given by the negative |
nothing calls this directly
no test coverage detected