Use existing random number generator for std::shuffle

This commit is contained in:
Shikhar Bhardwaj
2017-07-24 14:03:22 +05:30
parent 25282ca43f
commit c60f3af3aa
3 changed files with 5 additions and 10 deletions
@@ -13,6 +13,7 @@
#define MLPACK_CORE_OPTIMIZERS_PARALLEL_SGD_HPP
#include <mlpack/prereqs.hpp>
#include <mlpack/core/math/random.hpp>
#include "decay_policies/constant_step.hpp"
namespace mlpack {
@@ -45,10 +45,6 @@ double ParallelSGD<DecayPolicyType>::Optimize(
arma::Col<size_t> visitationOrder = arma::linspace<arma::Col<size_t>>(0,
(function.NumFunctions() - 1), function.NumFunctions());
// A random number generator instance to be used for shuffling the order of
// visitation.
std::mt19937 gen{ std::random_device()() };
// Iterate till the objective is within tolerance or the maximum number of
// allowed iterations is reached. If maxIterations is 0, this will iterate
// till convergence.
@@ -88,7 +84,8 @@ double ParallelSGD<DecayPolicyType>::Optimize(
// Shuffle for uniform sampling of functions by each thread.
if (shuffle) // Determine order of visitation.
std::shuffle(visitationOrder.begin(), visitationOrder.end(), gen);
std::shuffle(visitationOrder.begin(), visitationOrder.end(),
mlpack::math::randGen);
#pragma omp parallel
{
@@ -232,10 +232,6 @@ inline double ParallelSGD<ExponentialBackoff>::Optimize(
arma::Col<size_t> visitationOrder = arma::linspace<arma::Col<size_t>>(0,
(function.NumFunctions() - 1), function.NumFunctions());
// A random number generator instance to be used for shuffling the order of
// visitation.
std::mt19937 gen{ std::random_device()() };
const arma::mat data = function.Dataset();
// Iterate till the objective is within tolerance or the maximum number of
@@ -276,7 +272,8 @@ inline double ParallelSGD<ExponentialBackoff>::Optimize(
double stepSize = decayPolicy.StepSize(i);
if (shuffle) // Determine order of visitation.
std::shuffle(visitationOrder.begin(), visitationOrder.end(), gen);
std::shuffle(visitationOrder.begin(), visitationOrder.end(),
mlpack::math::randGen);
#pragma omp parallel
{