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 #if (!defined(BINDING_TYPE) || BINDING_TYPE != BINDING_TYPE_TEST) 43 randGen.seed((uint32_t) seed);
44 #if (BINDING_TYPE == BINDING_TYPE_R) 48 srand((
unsigned int) seed);
50 arma::arma_rng::set_seed(seed);
63 #if (BINDING_TYPE == BINDING_TYPE_TEST) 66 const static size_t seed = rand();
67 randGen.seed((uint32_t) seed);
68 srand((
unsigned int) seed);
69 arma::arma_rng::set_seed(seed);
74 randGen.seed((uint32_t) seed);
75 srand((
unsigned int) seed);
76 arma::arma_rng::set_seed(seed);
91 inline double Random(
const double lo,
const double hi)
112 return (
int) std::floor((
double) hiExclusive *
randUniformDist(randGen));
118 inline int RandInt(
const int lo,
const int hiExclusive)
120 return lo + (int) std::floor((
double) (hiExclusive - lo)
139 inline double RandNormal(
const double mean,
const double variance)
154 const size_t hiExclusive,
155 const size_t maxNumSamples,
156 arma::uvec& distinctSamples)
158 const size_t samplesRangeSize = hiExclusive - loInclusive;
160 if (samplesRangeSize > maxNumSamples)
162 arma::Col<size_t> samples;
164 samples.zeros(samplesRangeSize);
166 for (
size_t i = 0; i < maxNumSamples; ++i)
169 distinctSamples = arma::find(samples > 0);
172 distinctSamples += loInclusive;
176 distinctSamples.set_size(samplesRangeSize);
177 for (
size_t i = 0; i < samplesRangeSize; ++i)
178 distinctSamples[i] = loInclusive + i;
185 #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.
double RandBernoulli(const double input)
Generates a 0/1 specified by the input.
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()).
MLPACK_EXPORT std::uniform_real_distribution randUniformDist
double RandNormal()
Generates a normally distributed random number with mean 0 and variance 1.
MLPACK_EXPORT std::normal_distribution randNormalDist
void FixedRandomSeed()
Set the random seed to a fixed number.
MLPACK_EXPORT std::mt19937 randGen
MLPACK_EXPORT is required for global variables; it exports the symbols correctly on Windows...
double Random()
Generates a uniform random number between 0 and 1.
int RandInt(const int hiExclusive)
Generates a uniform random integer.
void CustomRandomSeed(const size_t seed)