comparison deep/stacked_dae/v_sylvain/stacked_dae.py @ 233:02ed13244133

version pour utilisation du module dataset
author SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
date Sun, 14 Mar 2010 15:07:17 -0400
parents 8a94a5c808cd
children ecb69e17950b
comparison
equal deleted inserted replaced
232:4ce1fc11f4b2 233:02ed13244133
191 print "pretrain_lr", pretrain_lr 191 print "pretrain_lr", pretrain_lr
192 print "finetune_lr", finetune_lr 192 print "finetune_lr", finetune_lr
193 print "input_divider", input_divider 193 print "input_divider", input_divider
194 print "----" 194 print "----"
195 195
196 self.shared_divider = theano.shared(numpy.asarray(input_divider, dtype=theano.config.floatX)) 196 #self.shared_divider = theano.shared(numpy.asarray(input_divider, dtype=theano.config.floatX))
197 197
198 if len(hidden_layers_sizes) < 1 : 198 if len(hidden_layers_sizes) < 1 :
199 raiseException (' You must have at least one hidden layer ') 199 raiseException (' You must have at least one hidden layer ')
200 200
201 201
202 # allocate symbolic variables for the data 202 # allocate symbolic variables for the data
203 index = T.lscalar() # index to a [mini]batch 203 ##index = T.lscalar() # index to a [mini]batch
204 self.x = T.matrix('x') # the data is presented as rasterized images 204 self.x = T.matrix('x') # the data is presented as rasterized images
205 self.y = T.ivector('y') # the labels are presented as 1D vector of 205 self.y = T.ivector('y') # the labels are presented as 1D vector of
206 # [int] labels 206 # [int] labels
207 207
208 for i in xrange( self.n_layers ): 208 for i in xrange( self.n_layers ):
245 updates = {} 245 updates = {}
246 for param, gparam in zip(dA_layer.params, gparams): 246 for param, gparam in zip(dA_layer.params, gparams):
247 updates[param] = param - gparam * pretrain_lr 247 updates[param] = param - gparam * pretrain_lr
248 248
249 # create a function that trains the dA 249 # create a function that trains the dA
250 update_fn = theano.function([index], dA_layer.cost, \ 250 update_fn = theano.function([ensemble], dA_layer.cost, \
251 updates = updates, 251 updates = updates,
252 givens = { 252 givens = {
253 self.x : train_set_x[index*batch_size:(index+1)*batch_size] / self.shared_divider}) 253 self.x : ensemble})
254 # collect this function into a list 254 # collect this function into a list
255 self.pretrain_functions += [update_fn] 255 self.pretrain_functions += [update_fn]
256 256
257 257
258 # We now need to add a logistic layer on top of the MLP 258 # We now need to add a logistic layer on top of the MLP
271 # compute list of updates 271 # compute list of updates
272 updates = {} 272 updates = {}
273 for param,gparam in zip(self.params, gparams): 273 for param,gparam in zip(self.params, gparams):
274 updates[param] = param - gparam*finetune_lr 274 updates[param] = param - gparam*finetune_lr
275 275
276 self.finetune = theano.function([index], cost, 276 self.finetune = theano.function([ensemble_x,ensemble_y], cost,
277 updates = updates, 277 updates = updates,
278 givens = { 278 givens = {
279 self.x : train_set_x[index*batch_size:(index+1)*batch_size]/self.shared_divider, 279 #self.x : train_set_x[index*batch_size:(index+1)*batch_size]/self.shared_divider,
280 self.y : train_set_y[index*batch_size:(index+1)*batch_size]} ) 280 #self.y : train_set_y[index*batch_size:(index+1)*batch_size]} )
281 self.x : ensemble_x,
282 self.y : ensemble_y} )
281 283
282 # symbolic variable that points to the number of errors made on the 284 # symbolic variable that points to the number of errors made on the
283 # minibatch given by self.x and self.y 285 # minibatch given by self.x and self.y
284 286
285 self.errors = self.logLayer.errors(self.y) 287 self.errors = self.logLayer.errors(self.y)