template<class State, typename SeqNumType, unsigned int(*)(State*) Generate>
RNGSSE class
RNGSSE-based random number generator used polymorphically with tk::
Contents
Constructors, destructors, conversion operators
-
RNGSSE(SeqNumType n,
InitFn fnShort,
ctr::
RNGSSESeqLenType seqlen = ctr:: RNGSSESeqLenType:: SHORT, InitFn fnLong = nullptr, InitFn fnMed = nullptr) explicit - RNGSSE(const RNGSSE& x)
- Copy constructor: in terms of copy assignment.
- RNGSSE(RNGSSE&& x)
- Move constructor: in terms of move assignment.
Public functions
-
void uniform(int tid,
ncomp_
t num, double* r) const -
void gaussian(int tid,
ncomp_
t num, double* r) const -
void gaussianmv(] int tid,
] ncomp_
t num, ] ncomp_ t d, ] const double*const mean, ] const double*const cov, ] double* r) const - Multi-variate Gaussian RNG: Generate multi-variate Gaussian random numbers.
-
void beta(int tid,
ncomp_
t num, double p, double q, double a, double b, double* r) const -
void gamma(int tid,
ncomp_
t num, double a, double b, double* r) const - auto operator=(const RNGSSE& x) -> RNGSSE&
- Copy assignment.
- auto operator=(RNGSSE&& x) -> RNGSSE&
- Move assignment.
- auto nthreads() const -> SeqNumType noexcept
- Accessor to the number of threads we operate on.
Function documentation
template<class State, typename SeqNumType, unsigned int(*)(State*) Generate>
tk:: RNGSSE<State, SeqNumType, Generate>:: RNGSSE(SeqNumType n,
InitFn fnShort,
ctr:: RNGSSESeqLenType seqlen = ctr:: RNGSSESeqLenType:: SHORT,
InitFn fnLong = nullptr,
InitFn fnMed = nullptr) explicit
Parameters | |
---|---|
n in | Initialize RNG using this many independent streams |
fnShort in | RNG initializer function for short streams |
seqlen in | Sequence length enum: short, medium or long |
fnLong in | RNG initializer function for long streams |
fnMed in | RNG initializer function for medium streams |
Constructor
template<class State, typename SeqNumType, unsigned int(*)(State*) Generate>
void tk:: RNGSSE<State, SeqNumType, Generate>:: uniform(int tid,
ncomp_ t num,
double* r) const
Parameters | |
---|---|
tid in | Thread (or more precisely) stream ID |
num in | Number of RNGs to generate |
r in/out | Pointer to memory to write the random numbers to |
Uniform RNG: Generate uniform random numbers
template<class State, typename SeqNumType, unsigned int(*)(State*) Generate>
void tk:: RNGSSE<State, SeqNumType, Generate>:: gaussian(int tid,
ncomp_ t num,
double* r) const
Parameters | |
---|---|
tid in | Thread (or more precisely stream) ID |
num in | Number of RNGs to generate |
r in/out | Pointer to memory to write the random numbers to |
Gaussian RNG: Generate Gaussian random numbers Generating Gaussian random numbers is implemented via an adaptor, modeling std::UniformRandomNumberGenerator, outsourcing the transformation of uniform random numbers to Gaussian ones, to the standard library. The adaptor is instantiated here because a standard distribution, such as e.g., std::normal_distribution, generates numbers using operator() with no arguments, thus the RNG state and the thread ID (this latter only known here) must be stored in the adaptor functor's state. Even though creating the adaptor seems like a potentially costly operation for every call, using the standard library implementation is still faster than a hand-coded implementation of the Box-Muller algorithm. Note that libc++ uses a cache, as Box-Muller, implemented using the polar algorithm generates 2 Gaussian numbers for each pair of uniform ones, caching every 2nd.
template<class State, typename SeqNumType, unsigned int(*)(State*) Generate>
void tk:: RNGSSE<State, SeqNumType, Generate>:: gaussianmv(] int tid,
] ncomp_ t num,
] ncomp_ t d,
] const double*const mean,
] const double*const cov,
] double* r) const
Multi-variate Gaussian RNG: Generate multi-variate Gaussian random numbers.
Parameters | |
---|---|
tid in | Thread (or more precisely stream) ID |
num in | Number of RNGs to generate |
d in | Dimension d ( d ≥ 1) of output random vectors |
mean in | Mean vector of dimension d |
cov in | Lower triangle of covariance matrix, stored as a vector of length d(d+1)/2 |
r in/out | Pointer to memory to write the random numbers to |
template<class State, typename SeqNumType, unsigned int(*)(State*) Generate>
void tk:: RNGSSE<State, SeqNumType, Generate>:: beta(int tid,
ncomp_ t num,
double p,
double q,
double a,
double b,
double* r) const
Parameters | |
---|---|
tid in | Thread (or more precisely stream) ID |
num in | Number of RNGs to generate |
p in | First beta shape parameter |
q in | Second beta shape parameter |
a in | Beta displacement parameter |
b in | Beta scale factor |
r in/out | Pointer to memory to write the random numbers to |
Beta RNG: Generate beta random numbers Generating beta-distributed random numbers is implemented via an adaptor, modeling boost::UniformRandomNumberGenerator, outsourcing the transformation of uniform random numbers to beta-distributed ones, to boost::random. The adaptor is instantiated here because a boost random number distribution, such as e.g., boost::random::beta_distribution, generates numbers using operator() with no arguments, thus the RNG state and the thread ID (this latter only known here) must be stored in the adaptor functor's state.
template<class State, typename SeqNumType, unsigned int(*)(State*) Generate>
void tk:: RNGSSE<State, SeqNumType, Generate>:: gamma(int tid,
ncomp_ t num,
double a,
double b,
double* r) const
Parameters | |
---|---|
tid in | Thread (or more precisely stream) ID |
num in | Number of RNGs to generate |
a in | Gamma shape parameter |
b in | Gamma scale factor |
r in/out | Pointer to memory to write the random numbers to |
Gamma RNG: Generate gamma random numbers Generating gamma-distributed random numbers is implemented via an adaptor, modeling boost::UniformRandomNumberGenerator, outsourcing the transformation of uniform random numbers to gamma-distributed ones, to boost::random. The adaptor is instantiated here because a boost random number distribution, such as e.g., boost::random::gamma_distribution, generates numbers using operator() with no arguments, thus the RNG state and the thread ID (this latter only known here) must be stored in the adaptor functor's state.