Skip to content

Commit

Permalink
Compute mean in higher precision to avoid overflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
abergeron committed Oct 24, 2016
1 parent 93c9a36 commit d403591
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions code/DBN.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions code/dA.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit d403591

Please sign in to comment.