Skip to content

Commit 0301c94

Browse files
author
Razvan Pascanu
committed
merge
1 parent b241bde commit 0301c94

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

code/SdA.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ def __init__(self, n_visible= 784, n_hidden= 500, input= None):
207207
# Equation (3)
208208
self.z = T.nnet.sigmoid(T.dot(self.y, self.W_prime) + self.b_prime)
209209
# Equation (4)
210+
# note : we sum over the size of a datapoint; if we are using minibatches,
211+
# L will be a vector, with one entry per example in minibatch
210212
self.L = - T.sum( self.x*T.log(self.z) + (1-self.x)*T.log(1-self.z), axis=1 )
211213
# note : L is now a vector, where each element is the cross-entropy cost
212214
# of the reconstruction of the corresponding example of the
@@ -262,17 +264,13 @@ def __init__(self, input, n_ins, hidden_layers_sizes, n_outs):
262264
# input size is that of the previous layer
263265
# input is the output of the last layer inserted in our list
264266
# of layers `self.layers`
265-
print i
266-
print theano.pp(self.layers[-1].hidden_values)
267267
layer = dA( hidden_layers_sizes[i-1], \
268268
hidden_layers_sizes[i], \
269269
input = self.layers[-1].hidden_values )
270270
self.layers += [layer]
271271

272272

273273
self.n_layers = len(self.layers)
274-
print '------------------------------------------'
275-
print theano.pp(self.layers[-1].hidden_values)
276274
# now we need to use same weights and biases to define an MLP
277275
# We can simply use the `hidden_values` of the top layer, which
278276
# computes the input that we would normally feed to the logistic
@@ -304,7 +302,7 @@ def errors(self, y):
304302

305303

306304

307-
def sgd_optimization_mnist( learning_rate=0.1, pretraining_epochs = 10, \
305+
def sgd_optimization_mnist( learning_rate=0.1, pretraining_epochs = 15, \
308306
pretraining_lr = 0.1, training_epochs = 1000, dataset='mnist.pkl.gz'):
309307
"""
310308
Demonstrate stochastic gradient descent optimization for a multilayer
@@ -359,7 +357,7 @@ def shared_dataset(data_xy):
359357

360358
# construct the logistic regression class
361359
classifier = SdA( input=x, n_ins=28*28, \
362-
hidden_layers_sizes = [700, 700, 700], n_outs=10)
360+
hidden_layers_sizes = [1000, 1000, 1000], n_outs=10)
363361

364362
## Pre-train layer-wise
365363
for i in xrange(classifier.n_layers):
@@ -385,7 +383,7 @@ def shared_dataset(data_xy):
385383
# go through the training set
386384
for batch_index in xrange(n_train_batches):
387385
c = layer_update(batch_index)
388-
print 'Pre-training layer %i, epoch %d'%(i,epoch),c
386+
print 'Pre-training layer %i, epoch %d'%(i,epoch),c[0]
389387

390388

391389

@@ -460,10 +458,8 @@ def shared_dataset(data_xy):
460458
iter = epoch * n_train_batches + minibatch_index
461459

462460
if (iter+1) % validation_frequency == 0:
463-
print cost_ij
464461
cost_ij = []
465462
validation_losses = [validate_model(i) for i in xrange(n_valid_batches)]
466-
print validation_losses
467463
this_validation_loss = numpy.mean(validation_losses)
468464
print('epoch %i, minibatch %i/%i, validation error %f %%' % \
469465
(epoch, minibatch_index+1, n_train_batches, \

0 commit comments

Comments
 (0)