Skip to content

Commit d403591

Browse files
committed
Compute mean in higher precision to avoid overflow.
1 parent 93c9a36 commit d403591

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

code/DBN.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def test_DBN(finetune_lr=0.1, pretraining_epochs=100,
340340
c.append(pretraining_fns[i](index=batch_index,
341341
lr=pretrain_lr))
342342
print('Pre-training layer %i, epoch %d, cost ' % (i, epoch), end=' ')
343-
print(numpy.mean(c))
343+
print(numpy.mean(c, dtype='float64'))
344344

345345
end_time = timeit.default_timer()
346346
# end-snippet-2
@@ -391,7 +391,7 @@ def test_DBN(finetune_lr=0.1, pretraining_epochs=100,
391391
if (iter + 1) % validation_frequency == 0:
392392

393393
validation_losses = validate_model()
394-
this_validation_loss = numpy.mean(validation_losses)
394+
this_validation_loss = numpy.mean(validation_losses, dtype='float64')
395395
print('epoch %i, minibatch %i/%i, validation error %f %%' % (
396396
epoch,
397397
minibatch_index + 1,
@@ -414,7 +414,7 @@ def test_DBN(finetune_lr=0.1, pretraining_epochs=100,
414414

415415
# test it on the test set
416416
test_losses = test_model()
417-
test_score = numpy.mean(test_losses)
417+
test_score = numpy.mean(test_losses, dtype='float64')
418418
print((' epoch %i, minibatch %i/%i, test error of '
419419
'best model %f %%') %
420420
(epoch, minibatch_index + 1, n_train_batches,

code/dA.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def test_dA(learning_rate=0.1, training_epochs=15,
336336
for batch_index in range(n_train_batches):
337337
c.append(train_da(batch_index))
338338

339-
print('Training epoch %d, cost ' % epoch, numpy.mean(c))
339+
print('Training epoch %d, cost ' % epoch, numpy.mean(c, dtype='float64'))
340340

341341
end_time = timeit.default_timer()
342342

@@ -394,7 +394,7 @@ def test_dA(learning_rate=0.1, training_epochs=15,
394394
for batch_index in range(n_train_batches):
395395
c.append(train_da(batch_index))
396396

397-
print('Training epoch %d, cost ' % epoch, numpy.mean(c))
397+
print('Training epoch %d, cost ' % epoch, numpy.mean(c, dtype='float64'))
398398

399399
end_time = timeit.default_timer()
400400

0 commit comments

Comments
 (0)