11 #ifndef MLPACK_CORE_MATH_RANDOM_HPP 12 #define MLPACK_CORE_MATH_RANDOM_HPP 15 #include <mlpack/mlpack_export.hpp> 27 extern MLPACK_EXPORT std::mt19937
randGen;
42 randGen.seed((uint32_t) seed);
43 srand((
unsigned int) seed);
44 #if ARMA_VERSION_MAJOR > 3 || \ 45 (ARMA_VERSION_MAJOR == 3 && ARMA_VERSION_MINOR >= 930) 48 arma::arma_rng::set_seed(seed);
63 inline double Random(
const double lo,
const double hi)
73 return (
int) std::floor((
double) hiExclusive *
randUniformDist(randGen));
79 inline int RandInt(
const int lo,
const int hiExclusive)
81 return lo + (int) std::floor((
double) (hiExclusive - lo)
100 inline double RandNormal(
const double mean,
const double variance)
115 const size_t hiExclusive,
116 const size_t maxNumSamples,
117 arma::uvec& distinctSamples)
119 const size_t samplesRangeSize = hiExclusive - loInclusive;
121 if (samplesRangeSize > maxNumSamples)
123 arma::Col<size_t> samples;
125 samples.zeros(samplesRangeSize);
127 for (
size_t i = 0; i < maxNumSamples; i++)
130 distinctSamples = arma::find(samples > 0);
133 distinctSamples += loInclusive;
137 distinctSamples.set_size(samplesRangeSize);
138 for (
size_t i = 0; i < samplesRangeSize; i++)
139 distinctSamples[i] = loInclusive + i;
146 #endif // MLPACK_CORE_MATH_MATH_LIB_HPP void ObtainDistinctSamples(const size_t loInclusive, const size_t hiExclusive, const size_t maxNumSamples, arma::uvec &distinctSamples)
Obtains no more than maxNumSamples distinct samples.
MLPACK_EXPORT std::uniform_real_distribution randUniformDist
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
void RandomSeed(const size_t seed)
Set the random seed used by the random functions (Random() and RandInt()).
double RandNormal()
Generates a normally distributed random number with mean 0 and variance 1.
double Random()
Generates a uniform random number between 0 and 1.
MLPACK_EXPORT std::normal_distribution randNormalDist
int RandInt(const int hiExclusive)
Generates a uniform random integer.
MLPACK_EXPORT std::mt19937 randGen
MLPACK_EXPORT is required for global variables; it exports the symbols correctly on Windows...