diff --git a/code/DBN.py b/code/DBN.py index 3b2bd230..e1bb66df 100644 --- a/code/DBN.py +++ b/code/DBN.py @@ -340,7 +340,7 @@ def test_DBN(finetune_lr=0.1, pretraining_epochs=100, c.append(pretraining_fns[i](index=batch_index, lr=pretrain_lr)) print('Pre-training layer %i, epoch %d, cost ' % (i, epoch), end=' ') - print(numpy.mean(c)) + print(numpy.mean(c, dtype='float64')) end_time = timeit.default_timer() # end-snippet-2 @@ -391,7 +391,7 @@ def test_DBN(finetune_lr=0.1, pretraining_epochs=100, if (iter + 1) % validation_frequency == 0: validation_losses = validate_model() - this_validation_loss = numpy.mean(validation_losses) + this_validation_loss = numpy.mean(validation_losses, dtype='float64') print('epoch %i, minibatch %i/%i, validation error %f %%' % ( epoch, minibatch_index + 1, @@ -414,7 +414,7 @@ def test_DBN(finetune_lr=0.1, pretraining_epochs=100, # test it on the test set test_losses = test_model() - test_score = numpy.mean(test_losses) + test_score = numpy.mean(test_losses, dtype='float64') print((' epoch %i, minibatch %i/%i, test error of ' 'best model %f %%') % (epoch, minibatch_index + 1, n_train_batches, diff --git a/code/SdA.py b/code/SdA.py index 3d9589ac..8da74797 100644 --- a/code/SdA.py +++ b/code/SdA.py @@ -40,7 +40,7 @@ import theano import theano.tensor as T -from theano.tensor.shared_randomstreams import RandomStreams +from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams from logistic_sgd import LogisticRegression, load_data from mlp import HiddenLayer @@ -394,7 +394,7 @@ def test_SdA(finetune_lr=0.1, pretraining_epochs=15, c.append(pretraining_fns[i](index=batch_index, corruption=corruption_levels[i], lr=pretrain_lr)) - print('Pre-training layer %i, epoch %d, cost %f' % (i, epoch, numpy.mean(c))) + print('Pre-training layer %i, epoch %d, cost %f' % (i, epoch, numpy.mean(c, dtype='float64'))) end_time = timeit.default_timer() @@ -442,7 +442,7 @@ def test_SdA(finetune_lr=0.1, pretraining_epochs=15, if (iter + 1) % validation_frequency == 0: validation_losses = validate_model() - this_validation_loss = numpy.mean(validation_losses) + this_validation_loss = numpy.mean(validation_losses, dtype='float64') print('epoch %i, minibatch %i/%i, validation error %f %%' % (epoch, minibatch_index + 1, n_train_batches, this_validation_loss * 100.)) @@ -463,7 +463,7 @@ def test_SdA(finetune_lr=0.1, pretraining_epochs=15, # test it on the test set test_losses = test_model() - test_score = numpy.mean(test_losses) + test_score = numpy.mean(test_losses, dtype='float64') print((' epoch %i, minibatch %i/%i, test error of ' 'best model %f %%') % (epoch, minibatch_index + 1, n_train_batches, diff --git a/code/dA.py b/code/dA.py index 0d9efa54..93a696f8 100644 --- a/code/dA.py +++ b/code/dA.py @@ -40,7 +40,7 @@ import theano import theano.tensor as T -from theano.tensor.shared_randomstreams import RandomStreams +from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams from logistic_sgd import load_data from utils import tile_raster_images @@ -336,7 +336,7 @@ def test_dA(learning_rate=0.1, training_epochs=15, for batch_index in range(n_train_batches): c.append(train_da(batch_index)) - print('Training epoch %d, cost ' % epoch, numpy.mean(c)) + print('Training epoch %d, cost ' % epoch, numpy.mean(c, dtype='float64')) end_time = timeit.default_timer() @@ -394,7 +394,7 @@ def test_dA(learning_rate=0.1, training_epochs=15, for batch_index in range(n_train_batches): c.append(train_da(batch_index)) - print('Training epoch %d, cost ' % epoch, numpy.mean(c)) + print('Training epoch %d, cost ' % epoch, numpy.mean(c, dtype='float64')) end_time = timeit.default_timer() diff --git a/code/hmc/hmc.py b/code/hmc/hmc.py index aeb49937..cf4d20a1 100644 --- a/code/hmc/hmc.py +++ b/code/hmc/hmc.py @@ -7,6 +7,7 @@ from theano import function, shared from theano import tensor as TT import theano +import theano.sandbox.rng_mrg sharedX = (lambda X, name: shared(numpy.asarray(X, dtype=theano.config.floatX), name=name)) @@ -275,14 +276,14 @@ def hmc_updates(positions, stepsize, avg_acceptance_rate, final_pos, accept, """ - ## POSITION UPDATES ## + # POSITION UPDATES # # broadcast `accept` scalar to tensor with the same dimensions as # final_pos. accept_matrix = accept.dimshuffle(0, *(('x',) * (final_pos.ndim - 1))) # if accept is True, update to `final_pos` else stay put new_positions = TT.switch(accept_matrix, final_pos, positions) # end-snippet-5 start-snippet-7 - ## STEPSIZE UPDATES ## + # STEPSIZE UPDATES # # if acceptance rate is too low, our sampler is too "noisy" and we reduce # the stepsize. If it is too high, our sampler is too conservative, we can # get away with a larger stepsize (resulting in better mixing). @@ -292,7 +293,7 @@ def hmc_updates(positions, stepsize, avg_acceptance_rate, final_pos, accept, new_stepsize = TT.clip(_new_stepsize, stepsize_min, stepsize_max) # end-snippet-7 start-snippet-6 - ## ACCEPT RATE UPDATES ## + # ACCEPT RATE UPDATES # # perform exponential moving average mean_dtype = theano.scalar.upcast(accept.dtype, avg_acceptance_rate.dtype) new_acceptance_rate = TT.add( @@ -358,7 +359,7 @@ def new_from_shared_positions( stepsize = sharedX(initial_stepsize, 'hmc_stepsize') avg_acceptance_rate = sharedX(target_acceptance_rate, 'avg_acceptance_rate') - s_rng = TT.shared_randomstreams.RandomStreams(seed) + s_rng = theano.sandbox.rng_mrg.MRG_RandomStreams(seed) # define graph for an `n_steps` HMC simulation accept, final_pos = hmc_move( diff --git a/code/lstm.py b/code/lstm.py index 1c285928..a3010a9f 100644 --- a/code/lstm.py +++ b/code/lstm.py @@ -605,8 +605,8 @@ def train_lstm( best_p = unzip(tparams) bad_counter = 0 - print( ('Train ', train_err, 'Valid ', valid_err, - 'Test ', test_err) ) + print('Train ', train_err, 'Valid ', valid_err, + 'Test ', test_err) if (len(history_errs) > patience and valid_err >= numpy.array(history_errs)[:-patience, diff --git a/code/rbm.py b/code/rbm.py index 3800cca7..6e4f1012 100644 --- a/code/rbm.py +++ b/code/rbm.py @@ -20,7 +20,7 @@ import theano.tensor as T import os -from theano.tensor.shared_randomstreams import RandomStreams +from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams from utils import tile_raster_images from logistic_sgd import load_data diff --git a/code/rnnrbm.py b/code/rnnrbm.py index b8420b9b..900ffdc6 100644 --- a/code/rnnrbm.py +++ b/code/rnnrbm.py @@ -19,7 +19,7 @@ from midi.utils import midiread, midiwrite import theano import theano.tensor as T -from theano.tensor.shared_randomstreams import RandomStreams +from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams #Don't use a python long as this don't work on 32 bits computers. numpy.random.seed(0xbeef)