LSSTApplications
10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
|
#include <Random.h>
Public Types | |
enum | Algorithm { MT19937 = 0, RANLXS0, RANLXS1, RANLXS2, RANLXD1, RANLXD2, RANLUX, RANLUX389, CMRG, MRG, TAUS, TAUS2, GFSR4, NUM_ALGORITHMS } |
Public Member Functions | |
Random (Algorithm algorithm=MT19937, unsigned long seed=1) | |
Random (std::string const &algorithm, unsigned long seed=1) | |
Random (lsst::pex::policy::Policy::Ptr const policy) | |
Random | deepCopy () const |
Algorithm | getAlgorithm () const |
std::string | getAlgorithmName () const |
unsigned long | getSeed () const |
double | uniform () |
double | uniformPos () |
unsigned long | uniformInt (unsigned long n) |
double | flat (double const a, double const b) |
double | gaussian () |
double | chisq (double const nu) |
double | poisson (double const nu) |
Static Public Member Functions | |
static std::vector < std::string > const & | getAlgorithmNames () |
Private Member Functions | |
void | initialize () |
void | initialize (std::string const &) |
Private Attributes | |
boost::shared_ptr< ::gsl_rng > | _rng |
unsigned long | _seed |
Algorithm | _algorithm |
Static Private Attributes | |
::gsl_rng_type const *const | _gslRngTypes [NUM_ALGORITHMS] |
static char const *const | _algorithmNames [NUM_ALGORITHMS] |
static char const *const | _algorithmEnvVarName = "LSST_RNG_ALGORITHM" |
static char const *const | _seedEnvVarName = "LSST_RNG_SEED" |
typedef std::string | State |
State | getState () const |
void | setState (State const &state) |
std::size_t | getStateSize () const |
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.
To enable reproducibility, factory functions which determine the algorithm type and seed value to used based on the the LSST_RNG_ALGORITHM
and LSST_RNG_SEED
environment variables (or the "rngAlgorithm" and "rngSeed" keys in a policy) are provided.
typedef std::string lsst.afw.math::Random::State |
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 66 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. Passing a seed-value of zero will cause the generator to be seeded with an algorithm specific default 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 or a seed value of zero (corresponding to an algorithm specific seed) is chosen. |
lsst::pex::exceptions::MemoryError | Thrown if memory allocation for internal generator state fails. |
Definition at line 151 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. Passing a seed-value of zero will cause the generator to be seeded with an algorithm specific default 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 or a seed value of zero (corresponding to an algorithm specific seed) is chosen. |
lsst::pex::exceptions::MemoryError | Thrown if memory allocation for internal generator state fails. |
Definition at line 175 of file Random.cc.
|
explicit |
Creates a random number generator using the algorithm and seed specified in the given policy. The algorithm name and seed are expected to be specified in string-valued keys named "rngAlgorithm" and "rngSeed" respectively. The "rngSeed" value is expected to be convertible to an unsigned long integer and must not be positive.
[in] | policy | policy which contains the algorithm and seed to to use for random number generation |
lsst::pex::exceptions::InvalidParameterError | Thrown if the requested algorithm is not supported. |
lsst::pex::exceptions::MemoryError | Thrown if memory allocation for internal generator state fails. |
lsst::pex::exceptions::RuntimeError | Thrown if the "rngSeed" policy value cannot be converted to an unsigned long int. |
Definition at line 200 of file Random.cc.
double lsst.afw.math::Random::chisq | ( | double const | nu | ) |
math::Random lsst.afw.math::Random::deepCopy | ( | void | ) | 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.
lsst::pex::exceptions::MemoryError | Thrown if memory allocation for internal generator state fails. |
Definition at line 223 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 370 of file Random.cc.
math::Random::Algorithm lsst.afw.math::Random::getAlgorithm | ( | ) | const |
std::string lsst.afw.math::Random::getAlgorithmName | ( | ) | const |
Definition at line 263 of file Random.cc.
|
static |
Definition at line 270 of file Random.cc.
unsigned long lsst.afw.math::Random::getSeed | ( | ) | const |
math::Random::State lsst.afw.math::Random::getState | ( | ) | const |
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.
Definition at line 232 of file Random.cc.
std::size_t lsst.afw.math::Random::getStateSize | ( | ) | const |
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.
Definition at line 247 of file Random.cc.
|
private |
Definition at line 96 of file Random.cc.
|
private |
Definition at line 119 of file Random.cc.
double lsst.afw.math::Random::poisson | ( | double const | nu | ) |
void lsst.afw.math::Random::setState | ( | State const & | state | ) |
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.
Definition at line 236 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 304 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 341 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 319 of file Random.cc.
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
private |
|
staticprivate |