versatile-mcmc  0.1.7
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Attributes | List of all members
vmcmc::RandomPrototype< EngineT > Class Template Reference

A thread-safe interface for STL style pesudo random number generators (PRNG). More...

#include <random.hpp>

Public Types

typedef EngineT engine_type
 
typedef engine_type::result_type result_type
 

Public Member Functions

engine_type & GetEngine ()
 Get a reference to the underlying random number engine (mersenne twister). More...
 
template<typename FloatT >
std::enable_if< std::is_floating_point< FloatT >::value, FloatT >::type Uniform (FloatT min, FloatT max, bool minIncluded, bool maxIncluded)
 Get a random uniform number in the specified range. More...
 
template<typename FloatT = double>
std::enable_if< std::is_floating_point< FloatT >::value, FloatT >::type Uniform (FloatT min=0.0, FloatT max=1.0)
 Get a random uniform number in the specified range [min, max). More...
 
template<typename IntegerT >
std::enable_if< std::is_integral< IntegerT >::value, IntegerT >::type Uniform (IntegerT inclMin, IntegerT inclMax)
 Get a random uniform number from a discrete distribution [inclMin, inclMax]. More...
 
template<typename FloatT = double>
bool Bool (FloatT probability=0.5)
 Return a boolean. More...
 
template<typename FloatT = double>
FloatT Normal (FloatT mean=0.0, FloatT sigma=1.0)
 Draw from a gaussian / normal distribution. More...
 
template<typename FloatT = double>
FloatT StudentT (FloatT n=1.0, FloatT mean=0.0, FloatT sigma=1.0)
 
template<typename FloatT >
FloatT Exponential (FloatT tau)
 Draw from an exponential distribution according to exp(-t/tau). More...
 
template<typename IntegerT = uint32_t>
std::enable_if< std::is_integral< IntegerT >::value, IntegerT >::type Poisson (double mean)
 Draw an integer value from a poisson distribution. More...
 
template<typename FloatT >
std::enable_if< std::is_floating_point< FloatT >::value, FloatT >::type Poisson (FloatT mean)
 Draw a float value (cast from integer) from a poisson distribution. More...
 
template<typename ProbRangeT , typename IndexType = uint32_t>
IndexType Discrete (const ProbRangeT &probabilities)
 Produces integers in the range [0, n) with the probability of producing each value is specified by the parameters of the distribution. More...
 
template<typename DistributionT >
DistributionT::result_type FromDistribution (DistributionT &dist=DistributionT())
 Draw from a custom distribution. More...
 
template<typename DistributionT , typename VectorT , typename MatrixT >
VectorT FromMultiVariateDistribution (DistributionT &dist, const VectorT &mean, const MatrixT &cholesky)
 Draw from a custom multivariate distribution. More...
 
template<typename DistributionT , typename VectorT >
VectorT FromMultiVariateDistribution (DistributionT &dist, const VectorT &mean, const VectorT &sigma)
 Draw from a custom multivariate distribution without correlations. More...
 
result_type operator() ()
 Invokes the underlying random number generator. More...
 

Static Public Member Functions

static void Seed (result_type seed)
 Set the initial value for the global seed variable. More...
 
static RandomPrototypeInstance ()
 Get a reference to a static instance for the current thread. More...
 
static constexpr result_type min ()
 
static constexpr result_type max ()
 

Protected Member Functions

 RandomPrototype (const RandomPrototype &other)=delete
 
 RandomPrototype (RandomPrototype &&other)=delete
 
void operator= (const RandomPrototype &other)=delete
 
void operator= (RandomPrototype &&other)=delete
 

Static Protected Attributes

static std::atomic< result_type > sSeed
 

Detailed Description

template<typename EngineT>
class vmcmc::RandomPrototype< EngineT >

A thread-safe interface for STL style pesudo random number generators (PRNG).

Each thread accesses it's own static instance of a PRNG, which is realized using the thread_local keyword. In order for each new PRNG instance to be constructed with a new seed, a global variable Random::sSeed (initially to be set with Random::Seed), is incremented and used in each PRNG's constructor.

Template Parameters
EngineTUnderlying random number generator (e.g. std::mt19937).

Member Function Documentation

template<typename EngineT >
template<typename FloatT >
bool vmcmc::RandomPrototype< EngineT >::Bool ( FloatT  probability = 0.5)
inline

Return a boolean.

Parameters
probability
Returns
True with the given probability.
template<typename EngineT >
template<typename ProbRangeT , typename IndexType >
IndexType vmcmc::RandomPrototype< EngineT >::Discrete ( const ProbRangeT &  probabilities)
inline

Produces integers in the range [0, n) with the probability of producing each value is specified by the parameters of the distribution.

Returns
template<typename EngineT >
template<typename FloatT >
FloatT vmcmc::RandomPrototype< EngineT >::Exponential ( FloatT  tau)
inline

Draw from an exponential distribution according to exp(-t/tau).

Parameters
tau
Returns
template<typename EngineT >
template<typename DistributionT >
DistributionT::result_type vmcmc::RandomPrototype< EngineT >::FromDistribution ( DistributionT &  dist = DistributionT())
inline

Draw from a custom distribution.

Template Parameters
Typenameof the distribution.
See also
http://www.cplusplus.com/reference/random/
Parameters
dist
Returns
template<typename EngineT >
template<typename DistributionT , typename VectorT , typename MatrixT >
VectorT vmcmc::RandomPrototype< EngineT >::FromMultiVariateDistribution ( DistributionT &  dist,
const VectorT &  mean,
const MatrixT &  cholesky 
)
inline

Draw from a custom multivariate distribution.

Parameters
dist
meanA vector of mean values.
choleskyThe lower triangular matrix cholesky decomposition of the covariance matrix. The diagonal elements correspond to the individual parameter std. deviations.
Returns
See also
boost::multivariate_normal_distribution
template<typename EngineT >
template<typename DistributionT , typename VectorT >
VectorT vmcmc::RandomPrototype< EngineT >::FromMultiVariateDistribution ( DistributionT &  dist,
const VectorT &  mean,
const VectorT &  sigma 
)
inline

Draw from a custom multivariate distribution without correlations.

Parameters
dist
meanA vector of mean values.
sigmaA vector of standard deviations.
Returns
template<typename EngineT >
engine_type& vmcmc::RandomPrototype< EngineT >::GetEngine ( )
inline

Get a reference to the underlying random number engine (mersenne twister).

Returns
template<typename EngineT >
RandomPrototype< EngineT > & vmcmc::RandomPrototype< EngineT >::Instance ( )
inlinestatic

Get a reference to a static instance for the current thread.

Returns
template<typename EngineT >
template<typename FloatT >
FloatT vmcmc::RandomPrototype< EngineT >::Normal ( FloatT  mean = 0.0,
FloatT  sigma = 1.0 
)
inline

Draw from a gaussian / normal distribution.

Parameters
mean
sigma
Returns
template<typename EngineT >
auto vmcmc::RandomPrototype< EngineT >::operator() ( )
inline

Invokes the underlying random number generator.

Returns
template<typename EngineT >
template<typename IntegerT >
std::enable_if< std::is_integral< IntegerT >::value, IntegerT >::type vmcmc::RandomPrototype< EngineT >::Poisson ( double  mean)
inline

Draw an integer value from a poisson distribution.

Parameters
mean
Returns
template<typename EngineT >
template<typename FloatT >
std::enable_if< std::is_floating_point< FloatT >::value, FloatT >::type vmcmc::RandomPrototype< EngineT >::Poisson ( FloatT  mean)
inline

Draw a float value (cast from integer) from a poisson distribution.

Parameters
mean
Returns
template<typename EngineT >
void vmcmc::RandomPrototype< EngineT >::Seed ( result_type  seed)
static

Set the initial value for the global seed variable.

For seed = 0, a non-deterministic value is generated.

Parameters
seed
template<typename EngineT >
template<typename FloatT >
std::enable_if< std::is_floating_point< FloatT >::value, FloatT >::type vmcmc::RandomPrototype< EngineT >::Uniform ( FloatT  min,
FloatT  max,
bool  minIncluded,
bool  maxIncluded 
)
inline

Get a random uniform number in the specified range.

Parameters
minlower interval bound
maxupper interval bound
minIncludedInclude the lower bound.
maxIncludedInclude the upper bound.
Returns
template<typename EngineT >
template<typename FloatT >
std::enable_if< std::is_floating_point< FloatT >::value, FloatT >::type vmcmc::RandomPrototype< EngineT >::Uniform ( FloatT  min = 0.0,
FloatT  max = 1.0 
)
inline

Get a random uniform number in the specified range [min, max).

Parameters
minlower interval bound
maxupper interval bound
Returns
template<typename EngineT >
template<typename IntegerT >
std::enable_if< std::is_integral< IntegerT >::value, IntegerT >::type vmcmc::RandomPrototype< EngineT >::Uniform ( IntegerT  inclMin,
IntegerT  inclMax 
)
inline

Get a random uniform number from a discrete distribution [inclMin, inclMax].

Parameters
inclMin
inclMax
Returns

The documentation for this class was generated from the following file: