LSST Applications
21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
double | uniformPos () |
Returns a uniformly distributed random double precision floating point number from the generator. More... | |
unsigned long | uniformInt (unsigned long n) |
Returns a uniformly distributed random integer from 0 to n-1 . More... | |
double | flat (double const a, double const b) |
Returns a random variate from the flat (uniform) distribution on [a , b ). More... | |
double | gaussian () |
Returns a gaussian random variate with mean 0 and standard deviation 1 More... | |
double | chisq (double const nu) |
Returns a random variate from the chi-squared distribution with nu degrees of freedom. More... | |
double | poisson (double const mu) |
Returns a random variate from the poisson distribution with mean mu . More... | |
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. |
|
default |
|
default |
|
default |
double lsst::afw::math::Random::chisq | ( | double const | nu | ) |
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 |
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.