LSST Applications g0f08755f38+9c285cab97,g1635faa6d4+13f3999e92,g1653933729+a8ce1bb630,g1a0ca8cf93+bf6eb00ceb,g28da252d5a+0829b12dee,g29321ee8c0+5700dc9eac,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+fde0dd39b6,g5fbc88fb19+17cd334064,g781aacb6e4+a8ce1bb630,g80478fca09+55a9465950,g82479be7b0+d730eedb7d,g858d7b2824+9c285cab97,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+2a84bb7594,gacf8899fa4+c69c5206e8,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+9634bc57db,gcf0d15dbbd+4b7d09cae4,gda3e153d99+9c285cab97,gda6a2b7d83+4b7d09cae4,gdaeeff99f8+1711a396fd,ge2409df99d+5e831397f4,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+41c94011de,gf3fb38a9a8+8f07a9901b,gfb92a5be7c+9c285cab97,w.2024.46
LSST Data Management Base Package
|
A class that can be used to generate sequences of random numbers according to a number of different algorithms. More...
#include <Random.h>
Public Types | |
enum | Algorithm { MT19937 = 0 , RANLXS0 , RANLXS1 , RANLXS2 , RANLXD1 , RANLXD2 , RANLUX , RANLUX389 , CMRG , MRG , TAUS , TAUS2 , GFSR4 , NUM_ALGORITHMS } |
Identifiers for the list of supported algorithms. More... | |
using | State = std::string |
Accessors for the opaque state of the random number generator. | |
Public Member Functions | |
Random (Algorithm algorithm=MT19937, unsigned long seed=1) | |
Creates a random number generator that uses the given algorithm to produce random numbers, and seeds it with the specified value. | |
Random (std::string const &algorithm, unsigned long seed=1) | |
Creates a random number generator that uses the algorithm with the given name to produce random numbers, and seeds it with the specified value. | |
Random (Random const &)=default | |
Random (Random &&)=default | |
Random & | operator= (Random const &)=default |
Random & | operator= (Random &&)=default |
~Random ()=default | |
Random | deepCopy () const |
Creates a deep copy of this random number generator. | |
State | getState () const |
void | setState (State const &state) |
std::size_t | getStateSize () const |
Algorithm | getAlgorithm () const |
std::string | getAlgorithmName () const |
unsigned long | getSeed () const |
double | uniform () |
Returns a uniformly distributed random double precision floating point number from the generator. | |
double | uniformPos () |
Returns a uniformly distributed random double precision floating point number from the generator. | |
unsigned long | uniformInt (unsigned long n) |
Returns a uniformly distributed random integer from 0 to n-1 . | |
double | flat (double const a, double const b) |
Returns a random variate from the flat (uniform) distribution on [a , b ). | |
double | gaussian () |
Returns a gaussian random variate with mean 0 and standard deviation 1 | |
double | chisq (double const nu) |
Returns a random variate from the chi-squared distribution with nu degrees of freedom. | |
double | poisson (double const mu) |
Returns a random variate from the poisson distribution with mean mu . | |
Static Public Member Functions | |
static std::vector< std::string > const & | getAlgorithmNames () |
A class that can be used to generate sequences of random numbers according to a number of different algorithms.
Support for generating random variates from the uniform, Gaussian, Poisson, and chi-squared distributions is provided.
This class is a thin wrapper for the random number generation facilities of GSL, which supports many additional distributions that can easily be added to this class as the need arises.
Accessors for the opaque state of the random number generator.
These may be used to save the state and restore it later, possibly after persisting. The state is algorithm-dependent, and possibly platform/architecture dependent; it should only be used for debugging perposes.
We use string here because it's a format Python and afw::table understand; the actual value is a binary blob that is not expected to be human-readable.
Identifiers for the list of supported algorithms.
Definition at line 60 of file Random.h.
Creates a random number generator that uses the given algorithm to produce random numbers, and seeds it with the specified value.
The default value for algorithm
is MT19937, corresponding to the "Mersenne Twister" algorithm by Makoto Matsumoto and Takuji Nishimura.
[in] | algorithm | the algorithm to use for random number generation |
[in] | seed | the seed value to initialize the generator with |
lsst::pex::exceptions::InvalidParameterError | Thrown if the requested algorithm is not supported. |
std::bad_alloc | Thrown if memory allocation for internal generator state fails. |
Definition at line 89 of file Random.cc.
|
explicit |
Creates a random number generator that uses the algorithm with the given name to produce random numbers, and seeds it with the specified value.
[in] | algorithm | the name of the algorithm to use for random number generation |
[in] | seed | the seed value to initialize the generator with |
lsst::pex::exceptions::InvalidParameterError | Thrown if the requested algorithm is not supported. |
std::bad_alloc | Thrown if memory allocation for internal generator state fails. |
Definition at line 96 of file Random.cc.
|
default |
|
default |
|
default |
double lsst::afw::math::Random::chisq | ( | double const | nu | ) |
Returns a random variate from the chi-squared distribution with nu
degrees of freedom.
[in] | nu | the number of degrees of freedom in the chi-squared distribution |
Definition at line 163 of file Random.cc.
Random lsst::afw::math::Random::deepCopy | ( | ) | const |
Creates a deep copy of this random number generator.
Both this random number and its copy will subsequently produce an identical stream of random numbers.
std::bad_alloc | Thrown if memory allocation for internal generator state fails. |
Definition at line 100 of file Random.cc.
double lsst::afw::math::Random::flat | ( | double const | a, |
double const | b ) |
double lsst::afw::math::Random::gaussian | ( | ) |
Returns a gaussian random variate with mean 0
and standard deviation 1
Definition at line 161 of file Random.cc.
Random::Algorithm lsst::afw::math::Random::getAlgorithm | ( | ) | const |
std::string lsst::afw::math::Random::getAlgorithmName | ( | ) | const |
|
static |
Definition at line 132 of file Random.cc.
unsigned long lsst::afw::math::Random::getSeed | ( | ) | const |
Random::State lsst::afw::math::Random::getState | ( | ) | const |
Definition at line 109 of file Random.cc.
std::size_t lsst::afw::math::Random::getStateSize | ( | ) | const |
double lsst::afw::math::Random::poisson | ( | double const | mu | ) |
void lsst::afw::math::Random::setState | ( | State const & | state | ) |
Definition at line 113 of file Random.cc.
double lsst::afw::math::Random::uniform | ( | ) |
Returns a uniformly distributed random double precision floating point number from the generator.
The random number will be in the range [0, 1); the range includes 0.0 but excludes 1.0. Note that some algorithms will not produce randomness across all mantissa bits - choose an algorithm that produces double precisions results (such as Random::RANLXD1, Random::TAUS, or Random::MT19937) if this is important.
Definition at line 146 of file Random.cc.
unsigned long lsst::afw::math::Random::uniformInt | ( | unsigned long | n | ) |
Returns a uniformly distributed random integer from 0
to n-1
.
This function is not intended to generate values across the full range of unsigned integer values [0, 2^32 - 1]. If this is necessary, use a high precision algorithm like Random::RANLXD1, Random::TAUS, or Random::MT19937 with a minimum value of zero and call get() directly.
[in] | n | specifies the range of allowable return values (0 to n-1 ) |
lsst::pex::exceptions::RangeError | Thrown if n is larger than the algorithm specific range of the generator. |
Definition at line 150 of file Random.cc.
double lsst::afw::math::Random::uniformPos | ( | ) |
Returns a uniformly distributed random double precision floating point number from the generator.
The random number will be in the range (0, 1); the range excludes both 0.0 and 1.0. Note that some algorithms will not produce randomness across all mantissa bits - choose an algorithm that produces double precisions results (such as Random::RANLXD1, Random::TAUS, or Random::MT19937) if this is important.
Definition at line 148 of file Random.cc.