[mlpack] 03/20: Initialize visitationOrder for shuffle true and false, to avoid location error if shuffle is false.
Barak A. Pearlmutter
barak+git at pearlmutter.net
Thu May 25 20:44:08 UTC 2017
This is an automated email from the git hooks/post-receive script.
bap pushed a commit to branch master
in repository mlpack.
commit ee657316dd04fbcd46defea5ef6447ead5719002
Author: Marcus Edel <marcus.edel at fu-berlin.de>
Date: Wed Apr 26 15:47:42 2017 +0200
Initialize visitationOrder for shuffle true and false, to avoid location error if shuffle is false.
---
.../core/optimizers/minibatch_sgd/minibatch_sgd_impl.hpp | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/src/mlpack/core/optimizers/minibatch_sgd/minibatch_sgd_impl.hpp b/src/mlpack/core/optimizers/minibatch_sgd/minibatch_sgd_impl.hpp
index 5b95b41..35894a7 100644
--- a/src/mlpack/core/optimizers/minibatch_sgd/minibatch_sgd_impl.hpp
+++ b/src/mlpack/core/optimizers/minibatch_sgd/minibatch_sgd_impl.hpp
@@ -44,11 +44,9 @@ double MiniBatchSGD<DecomposableFunctionType>::Optimize(arma::mat& iterate)
if (numFunctions % batchSize != 0)
++numBatches; // Capture last few.
- // This is only used if shuffle is true.
- arma::Col<size_t> visitationOrder;
- if (shuffle)
- visitationOrder = arma::shuffle(arma::linspace<arma::Col<size_t>>(0,
- (numBatches - 1), numBatches));
+ // Batch visitation order.
+ arma::Col<size_t> visitationOrder = arma::shuffle(
+ arma::linspace<arma::Col<size_t>>(0, (numBatches - 1), numBatches));
// To keep track of where we are and how things are going.
size_t currentBatch = 0;
@@ -95,8 +93,7 @@ double MiniBatchSGD<DecomposableFunctionType>::Optimize(arma::mat& iterate)
}
// Evaluate the gradient for this mini-batch.
- const size_t offset = (shuffle) ? batchSize * visitationOrder[currentBatch]
- : batchSize * currentBatch;
+ const size_t offset = batchSize * visitationOrder[currentBatch];
function.Gradient(iterate, offset, gradient);
if (visitationOrder[currentBatch] != numBatches - 1)
{
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git
More information about the debian-science-commits
mailing list