Generates a list of functions, each of them implementing one step in trainnig the dA corresponding to the layer with same index. The function will require as input the minibatch index, and to train a dA you just need to iterate, calling the corresponding function on
(self, train_set_x, batch_size)
| 181 | self.errors = self.logLayer.errors(self.y) |
| 182 | |
| 183 | def pretraining_functions(self, train_set_x, batch_size): |
| 184 | ''' Generates a list of functions, each of them implementing one |
| 185 | step in trainnig the dA corresponding to the layer with same index. |
| 186 | The function will require as input the minibatch index, and to train |
| 187 | a dA you just need to iterate, calling the corresponding function on |
| 188 | all minibatch indexes. |
| 189 | |
| 190 | :type train_set_x: theano.tensor.TensorType |
| 191 | :param train_set_x: Shared variable that contains all datapoints used |
| 192 | for training the dA |
| 193 | |
| 194 | :type batch_size: int |
| 195 | :param batch_size: size of a [mini]batch |
| 196 | |
| 197 | :type learning_rate: float |
| 198 | :param learning_rate: learning rate used during training for any of |
| 199 | the dA layers |
| 200 | ''' |
| 201 | |
| 202 | # index to a [mini]batch |
| 203 | index = T.lscalar('index') # index to a minibatch |
| 204 | corruption_level = T.scalar('corruption') # % of corruption to use |
| 205 | learning_rate = T.scalar('lr') # learning rate to use |
| 206 | # begining of a batch, given `index` |
| 207 | batch_begin = index * batch_size |
| 208 | # ending of a batch given `index` |
| 209 | batch_end = batch_begin + batch_size |
| 210 | |
| 211 | pretrain_fns = [] |
| 212 | for dA in self.dA_layers: |
| 213 | # get the cost and the updates list |
| 214 | cost, updates = dA.get_cost_updates(corruption_level, |
| 215 | learning_rate) |
| 216 | # compile the theano function |
| 217 | fn = theano.function( |
| 218 | inputs=[ |
| 219 | index, |
| 220 | theano.In(corruption_level, value=0.2), |
| 221 | theano.In(learning_rate, value=0.1) |
| 222 | ], |
| 223 | outputs=cost, |
| 224 | updates=updates, |
| 225 | givens={ |
| 226 | self.x: train_set_x[batch_begin: batch_end] |
| 227 | } |
| 228 | ) |
| 229 | # append `fn` to the list of functions |
| 230 | pretrain_fns.append(fn) |
| 231 | |
| 232 | return pretrain_fns |
| 233 | |
| 234 | def build_finetune_functions(self, datasets, batch_size, learning_rate): |
| 235 | '''Generates a function `train` that implements one step of |