MachineIntelligenceCore:Algorithms
|
Random generator - defined in the form of a singleton, with double-checked locking pattern (DCLP) based access to instance. More...
#include <RandomGenerator.hpp>
Public Member Functions | |
uint64_t | uniRandInt (int min=0, int max=RAND_MAX) |
double | uniRandReal (double min=0, double max=1) |
double | normRandReal (double mean=0, double variance=1) |
Static Public Member Functions | |
static RandomGenerator * | getInstance () |
Private Member Functions | |
RandomGenerator () | |
Private Attributes | |
std::random_device | rd |
std::mt19937_64 | rng_mt19937_64 |
std::uniform_int_distribution | uniform_int_dist |
Uniform distribution from 0 to RAND_MAX (integers). More... | |
std::uniform_real_distribution | uniform_real_dist |
Uniform distribution from 0 to 1 (real values). More... | |
std::normal_distribution | normal_real_dist |
Normal distribution from 0 to 1 (real values). More... | |
Static Private Attributes | |
static boost::atomic < RandomGenerator * > | instance_ |
static boost::mutex | instantiation_mutex |
Random generator - defined in the form of a singleton, with double-checked locking pattern (DCLP) based access to instance.
Definition at line 38 of file RandomGenerator.hpp.
|
private |
Private constructor. Initialize pseudo-random generator and distributions parameters.
Definition at line 58 of file RandomGenerator.cpp.
Referenced by getInstance().
|
static |
Method for accessing the object instance, with double-checked locking optimization.
Definition at line 37 of file RandomGenerator.cpp.
References instance_, instantiation_mutex, and RandomGenerator().
double mic::utils::RandomGenerator::normRandReal | ( | double | mean = 0 , |
double | variance = 1 |
||
) |
Return a random real number - normal distribution.
mean | Mean. |
variance | Variance. |
Definition at line 81 of file RandomGenerator.cpp.
References normal_real_dist, and rng_mt19937_64.
uint64_t mic::utils::RandomGenerator::uniRandInt | ( | int | min = 0 , |
int | max = RAND_MAX |
||
) |
Return a random integer from range <0, RAND_MAX> - uniform distribution.
Definition at line 69 of file RandomGenerator.cpp.
References rng_mt19937_64.
double mic::utils::RandomGenerator::uniRandReal | ( | double | min = 0 , |
double | max = 1 |
||
) |
Return a random real number from range <min, max> - uniform distribution.
min | Min value. |
max | Max value. |
Definition at line 76 of file RandomGenerator.cpp.
References rng_mt19937_64, and uniform_real_dist.
|
staticprivate |
Private instance - accessed as atomic operation.
Definition at line 74 of file RandomGenerator.hpp.
Referenced by getInstance().
|
staticprivate |
Mutex used for instantiation of the instance.
Definition at line 79 of file RandomGenerator.hpp.
Referenced by getInstance().
|
private |
Normal distribution from 0 to 1 (real values).
Definition at line 103 of file RandomGenerator.hpp.
Referenced by normRandReal().
|
private |
Random device used for generation of random numbers.
Definition at line 89 of file RandomGenerator.hpp.
|
private |
Mersenne Twister pseudo-random generator of 32-bit numbers with a state size of 19937 bits.
Definition at line 94 of file RandomGenerator.hpp.
Referenced by normRandReal(), uniRandInt(), and uniRandReal().
|
private |
Uniform distribution from 0 to RAND_MAX (integers).
Definition at line 97 of file RandomGenerator.hpp.
|
private |
Uniform distribution from 0 to 1 (real values).
Definition at line 100 of file RandomGenerator.hpp.
Referenced by uniRandReal().