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

#include <RngGsl.h>

Inheritance diagram for QUESO::RngGsl:
QUESO::RngBase

Public Member Functions

Constructor/Destructor methods
 RngGsl (int seed, int worldRank)
 Constructor with seed. More...
 
 ~RngGsl ()
 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

gsl_rng * m_rng
 GSL random number 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...
 
const gsl_rng * rng () const
 GSL random number generator. More...
 
 RngGsl ()
 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 51 of file RngGsl.h.

Constructor & Destructor Documentation

RngGsl::RngGsl ( int  seed,
int  worldRank 
)

Constructor with seed.

Constructor with seed ------------------------—.

Definition at line 32 of file RngGsl.C.

References gsl_rng_default_seed, m_rng, QUESO::RngBase::m_seed, and QUESO::RngBase::m_worldRank.

33  :
34  RngBase(seed,worldRank),
35  m_rng (NULL)
36 {
37  gsl_rng_default_seed = (unsigned long int) m_seed;
38  m_rng = gsl_rng_alloc(gsl_rng_ranlxd2);
39  queso_require_msg(m_rng, "null m_rng");
40 
41 //gsl_rng_set(m_rng, gsl_rng_default_seed);
42 #if 0
43  if (m_worldRank == 0) {
44  std::cout << "In RngGsl::constructor():"
45  << "\n m_seed = " << m_seed
46  << "\n internal seed = " << gsl_rng_default_seed
47  //<< "\n first generated sample from uniform distribution = " << gsl_rng_uniform(m_rng)
48  //<< "\n first generated sample from std normal distribution = " << gsl_ran_gaussian(m_rng,1.)
49  << std::endl;
50  }
51 #endif
52 }
int seed() const
Sets the seed.
Definition: RngBase.C:42
int m_seed
Seed.
Definition: RngBase.h:82
gsl_rng * m_rng
GSL random number generator.
Definition: RngGsl.h:113
int m_worldRank
Rank of processor.
Definition: RngBase.h:85
RngBase()
Default Constructor: it should not be used.
unsigned long int gsl_rng_default_seed
RngGsl::~RngGsl ( )

Destructor.

Definition at line 55 of file RngGsl.C.

References m_rng.

56 {
57  if (m_rng) gsl_rng_free(m_rng);
58 }
gsl_rng * m_rng
GSL random number generator.
Definition: RngGsl.h:113
QUESO::RngGsl::RngGsl ( )
protected

Default Constructor: it should not be used.

Member Function Documentation

double RngGsl::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). Uses gsl_ran_beta(). Support (domain): [0,1].

Implements QUESO::RngBase.

Definition at line 89 of file RngGsl.C.

References m_rng.

90 {
91  return gsl_ran_beta(m_rng,alpha,beta);
92 }
gsl_rng * m_rng
GSL random number generator.
Definition: RngGsl.h:113
double RngGsl::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. Uses gsl_ran_gamma(). Support (domain): [0,infinity).

Implements QUESO::RngBase.

Definition at line 96 of file RngGsl.C.

References m_rng.

97 {
98  return gsl_ran_gamma(m_rng,a,b);
99 }
gsl_rng * m_rng
GSL random number generator.
Definition: RngGsl.h:113
double RngGsl::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. Uses gsl_ran_gaussian(). Support: (-infinity, infinity).

Implements QUESO::RngBase.

Definition at line 82 of file RngGsl.C.

References m_rng.

83 {
84  return gsl_ran_gaussian(m_rng,stdDev);
85 }
gsl_rng * m_rng
GSL random number generator.
Definition: RngGsl.h:113
void RngGsl::resetSeed ( int  newSeed)
virtual

Resets the seed with value newSeed.

Reimplemented from QUESO::RngBase.

Definition at line 62 of file RngGsl.C.

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

63 {
64  RngBase::resetSeed(newSeed);
65  gsl_rng_free(m_rng);
66 
67  gsl_rng_default_seed = (unsigned long int) m_seed;
68  m_rng = gsl_rng_alloc(gsl_rng_ranlxd2);
69  queso_require_msg(m_rng, "null m_rng");
70  return;
71 }
virtual void resetSeed(int newSeed)
Resets the seed with value newSeed.
Definition: RngBase.C:48
int m_seed
Seed.
Definition: RngBase.h:82
gsl_rng * m_rng
GSL random number generator.
Definition: RngGsl.h:113
unsigned long int gsl_rng_default_seed
const gsl_rng * RngGsl::rng ( ) const

GSL random number generator.

Definition at line 102 of file RngGsl.C.

References m_rng.

103 {
104  return m_rng;
105 }
gsl_rng * m_rng
GSL random number generator.
Definition: RngGsl.h:113
double RngGsl::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. Uses gsl_rng_uniform(m_rng).

Implements QUESO::RngBase.

Definition at line 75 of file RngGsl.C.

References m_rng.

76 {
77  return gsl_rng_uniform(m_rng);
78 }
gsl_rng * m_rng
GSL random number generator.
Definition: RngGsl.h:113

Member Data Documentation

gsl_rng* QUESO::RngGsl::m_rng
protected

GSL random number generator.

It is chosen, in the constructor, to be of type gsl_rng_ranlxd2.

Definition at line 113 of file RngGsl.h.

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


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