queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
QUESO::RngCXX11 Class Reference

#include <RngCXX11.h>

Inheritance diagram for QUESO::RngCXX11:
QUESO::RngBase

Public Member Functions

Constructor/Destructor methods
 RngCXX11 (int seed, int worldRank)
 Constructor with seed. More...
 
 ~RngCXX11 ()
 Destructor. More...
 
- Public Member Functions inherited from QUESO::RngBase
 RngBase (int seed, int worldRank)
 Constructor with seed. More...
 
virtual ~RngBase ()
 Virtual destructor. More...
 
int seed () const
 Sets the seed. More...
 

Sampling methods

std::mt19937 m_rng
 The internal random number generator. Mersenne Twister generator. More...
 
void resetSeed (int newSeed)
 Resets the seed with value newSeed. More...
 
double uniformSample () const
 Samples a value from a uniform distribution. Support: [0,1) or [a,b). More...
 
double gaussianSample (double stdDev) const
 
double betaSample (double alpha, double beta) const
 Samples a value from a Beta distribution. Support: [0,1]. More...
 
double gammaSample (double a, double b) const
 Samples a value from a Gamma distribution. Support: [0,infinity). More...
 
 RngCXX11 ()
 Default Constructor: it should not be used. More...
 

Additional Inherited Members

- Protected Attributes inherited from QUESO::RngBase
int m_seed
 Seed. More...
 
int m_worldRank
 Rank of processor. More...
 

Detailed Description

Definition at line 48 of file RngCXX11.h.

Constructor & Destructor Documentation

RngCXX11::RngCXX11 ( int  seed,
int  worldRank 
)

Constructor with seed.

Definition at line 31 of file RngCXX11.C.

32  :
33  RngBase(seed,worldRank),
34  m_rng((unsigned int)m_seed) // m_seed set in the base class. It is always
35  // positive
36 {
37 }
int seed() const
Sets the seed.
Definition: RngBase.C:42
int m_seed
Seed.
Definition: RngBase.h:82
RngBase()
Default Constructor: it should not be used.
std::mt19937 m_rng
The internal random number generator. Mersenne Twister generator.
Definition: RngCXX11.h:117
RngCXX11::~RngCXX11 ( )

Destructor.

Definition at line 39 of file RngCXX11.C.

40 {
41 }
QUESO::RngCXX11::RngCXX11 ( )
private

Default Constructor: it should not be used.

Member Function Documentation

double RngCXX11::betaSample ( double  alpha,
double  beta 
) const
virtual

Samples a value from a Beta distribution. Support: [0,1].

The Beta Distribution is a continuous probability distribution; it has two free parameters, which are labeled alpha and beta. The beta distribution is used as a prior distribution for binomial proportions in Bayesian analysis (Evans et al. 2000, p. 34). Support (domain): [0,1].

Since std::random doesn't have a beta distribution implementation, we leverage a novel transformation involving two Gamma distributed variates instead. For details, see https://en.wikipedia.org/wiki/Beta_distribution#Generating_beta-distributed_random_variates

Implements QUESO::RngBase.

Definition at line 65 of file RngCXX11.C.

References m_rng.

66 {
67  std::gamma_distribution<double> d1(alpha, 1.0);
68  std::gamma_distribution<double> d2(beta, 1.0);
69 
70  double x = d1(m_rng); // x ~ \Gamma(alpha, 1)
71  double y = d2(m_rng); // y ~ \Gamma(beta, 1)
72 
73  // x / (x + y) ~ Beta(alpha, beta)
74  // See https://en.wikipedia.org/wiki/Beta_distribution#Generating_beta-distributed_random_variates
75  return x / (x + y);
76 }
std::mt19937 m_rng
The internal random number generator. Mersenne Twister generator.
Definition: RngCXX11.h:117
double RngCXX11::gammaSample ( double  a,
double  b 
) const
virtual

Samples a value from a Gamma distribution. Support: [0,infinity).

The Gamma Distribution is a continuous probability distribution; it has two free parameters, which may be labeled: a shape parameter a and an inverse scale parameter b, called a rate parameter. Support (domain): [0, infinity).

Implements QUESO::RngBase.

Definition at line 79 of file RngCXX11.C.

References m_rng.

80 {
81  std::gamma_distribution<double> d(a, b);
82  return d(m_rng);
83 }
std::mt19937 m_rng
The internal random number generator. Mersenne Twister generator.
Definition: RngCXX11.h:117
double RngCXX11::gaussianSample ( double  stdDev) const
virtual

Samples a value from a Gaussian distribution with standard deviation given by stdDev. Support: (-infinity, infinity).

The parameter mu (mean or expectation of the distribution) in this Gaussian sample is set to zero, and thus, needs to be provided in an alternative way (e.g., in the form of a sum. The parameter stdDev is its standard deviation; its variance is therefore stdDev^2. A random variable with a Gaussian distribution is said to be normally distributed and is called a normal deviate. Support: (-infinity, infinity).

Implements QUESO::RngBase.

Definition at line 58 of file RngCXX11.C.

References m_rng.

59 {
60  std::normal_distribution<double> d(0.0, stdDev);
61  return d(m_rng);
62 }
std::mt19937 m_rng
The internal random number generator. Mersenne Twister generator.
Definition: RngCXX11.h:117
void RngCXX11::resetSeed ( int  newSeed)
virtual

Resets the seed with value newSeed.

Reimplemented from QUESO::RngBase.

Definition at line 44 of file RngCXX11.C.

References m_rng, QUESO::RngBase::m_seed, and QUESO::RngBase::resetSeed().

45 {
46  RngBase::resetSeed(newSeed);
47  m_rng.seed(m_seed); // m_seed was set by the previous line
48 }
virtual void resetSeed(int newSeed)
Resets the seed with value newSeed.
Definition: RngBase.C:48
int m_seed
Seed.
Definition: RngBase.h:82
std::mt19937 m_rng
The internal random number generator. Mersenne Twister generator.
Definition: RngCXX11.h:117
double RngCXX11::uniformSample ( ) const
virtual

Samples a value from a uniform distribution. Support: [0,1) or [a,b).

This function samples from continuous uniform distribution on the range [0,1). It is possible to scale this distribution so the support is defined by the two parameters, a and b, which are its minimum and maximum values. Support: -infinity < a < x< b< infinity.

Implements QUESO::RngBase.

Definition at line 51 of file RngCXX11.C.

References m_rng.

52 {
53  std::uniform_real_distribution<double> d(0.0, 1.0);
54  return d(m_rng);
55 }
std::mt19937 m_rng
The internal random number generator. Mersenne Twister generator.
Definition: RngCXX11.h:117

Member Data Documentation

std::mt19937 QUESO::RngCXX11::m_rng
mutableprivate

The internal random number generator. Mersenne Twister generator.

Definition at line 117 of file RngCXX11.h.

Referenced by betaSample(), gammaSample(), gaussianSample(), resetSeed(), and uniformSample().


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

Generated on Tue Jun 5 2018 19:49:12 for queso-0.57.1 by  doxygen 1.8.5