LSST Applications g063fba187b+eddd1b24d7,g0f08755f38+4a855ab515,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+062a45aee3,g1dcb35cd9c+45d3fa5522,g20f6ffc8e0+4a855ab515,g217e2c1bcf+f55e51b560,g28da252d5a+7d8e536cc7,g2bbee38e9b+2d92fc7d83,g2bc492864f+2d92fc7d83,g3156d2b45e+6e55a43351,g32e5bea42b+625186cc6b,g347aa1857d+2d92fc7d83,g35bb328faa+a8ce1bb630,g3a166c0a6a+2d92fc7d83,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+1af189bab1,g7af13505b9+7b6a50a2f8,g80478fca09+6174b7f182,g82479be7b0+5b71efbaf0,g858d7b2824+4a855ab515,g9125e01d80+a8ce1bb630,ga5288a1d22+61618a97c4,gb58c049af0+d64f4d3760,gc28159a63d+2d92fc7d83,gc5452a3dca+f4add4ffd5,gcab2d0539d+d9f5af7f69,gcf0d15dbbd+6c7e0a19ec,gda6a2b7d83+6c7e0a19ec,gdaeeff99f8+1711a396fd,ge79ae78c31+2d92fc7d83,gef2f8181fd+55fff6f525,gf0baf85859+c1f95f4921,gfa517265be+4a855ab515,gfa999e8aa5+17cd334064,w.2024.51
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.