queso-0.51.1
List of all members
QUESO::RngGsl Class Reference

#include <RngGsl.h>

Inheritance diagram for QUESO::RngGsl:
Inheritance graph
[legend]
Collaboration diagram for QUESO::RngGsl:
Collaboration graph
[legend]

Public Member Functions

Constructor/Destructor methods
 RngGsl ()
 Default Constructor: it should not be used. More...
 
 RngGsl (int seed, int worldRank)
 Constructor with seed. More...
 
 ~RngGsl ()
 Destructor. More...
 
- Public Member Functions inherited from QUESO::RngBase
 RngBase ()
 Default Constructor: it should not be used. More...
 
 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...
 

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 49 of file RngGsl.h.

Constructor & Destructor Documentation

RngGsl::RngGsl ( )

Default Constructor: it should not be used.

Definition at line 32 of file RngGsl.C.

References QUESO::RngBase::m_worldRank, and UQ_FATAL_TEST_MACRO.

33  :
34  RngBase()
35 {
38  "RngGsl::constructor(), default",
39  "should not be used by user");
40 }
int m_worldRank
Rank of processor.
Definition: RngBase.h:88
RngBase()
Default Constructor: it should not be used.
Definition: RngBase.C:30
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
RngGsl::RngGsl ( int  seed,
int  worldRank 
)

Constructor with seed.

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

Definition at line 43 of file RngGsl.C.

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

44  :
45  RngBase(seed,worldRank),
46  m_rng (NULL)
47 {
48  gsl_rng_default_seed = (unsigned long int) m_seed;
49  m_rng = gsl_rng_alloc(gsl_rng_ranlxd2);
50  UQ_FATAL_TEST_MACRO((m_rng == NULL),
52  "RngGsl::constructor()",
53  "null m_rng");
54 
55 //gsl_rng_set(m_rng, gsl_rng_default_seed);
56 #if 0
57  if (m_worldRank == 0) {
58  std::cout << "In RngGsl::constructor():"
59  << "\n m_seed = " << m_seed
60  << "\n internal seed = " << gsl_rng_default_seed
61  //<< "\n first generated sample from uniform distribution = " << gsl_rng_uniform(m_rng)
62  //<< "\n first generated sample from std normal distribution = " << gsl_ran_gaussian(m_rng,1.)
63  << std::endl;
64  }
65 #endif
66 }
int seed() const
Sets the seed.
Definition: RngBase.C:54
int m_worldRank
Rank of processor.
Definition: RngBase.h:88
unsigned long int gsl_rng_default_seed
gsl_rng * m_rng
GSL random number generator.
Definition: RngGsl.h:111
RngBase()
Default Constructor: it should not be used.
Definition: RngBase.C:30
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
int m_seed
Seed.
Definition: RngBase.h:85
RngGsl::~RngGsl ( )

Destructor.

Definition at line 69 of file RngGsl.C.

References m_rng.

70 {
71  if (m_rng) gsl_rng_free(m_rng);
72 }
gsl_rng * m_rng
GSL random number generator.
Definition: RngGsl.h:111

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 106 of file RngGsl.C.

References m_rng.

107 {
108  return gsl_ran_beta(m_rng,alpha,beta);
109 }
gsl_rng * m_rng
GSL random number generator.
Definition: RngGsl.h:111
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 113 of file RngGsl.C.

References m_rng.

114 {
115  return gsl_ran_gamma(m_rng,a,b);
116 }
gsl_rng * m_rng
GSL random number generator.
Definition: RngGsl.h:111
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 99 of file RngGsl.C.

References m_rng.

100 {
101  return gsl_ran_gaussian(m_rng,stdDev);
102 }
gsl_rng * m_rng
GSL random number generator.
Definition: RngGsl.h:111
void RngGsl::resetSeed ( int  newSeed)
virtual

Resets the seed with value newSeed.

Reimplemented from QUESO::RngBase.

Definition at line 76 of file RngGsl.C.

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

77 {
78  RngBase::resetSeed(newSeed);
79  gsl_rng_free(m_rng);
80 
81  gsl_rng_default_seed = (unsigned long int) m_seed;
82  m_rng = gsl_rng_alloc(gsl_rng_ranlxd2);
83  UQ_FATAL_TEST_MACRO((m_rng == NULL),
85  "RngGsl::resetSeed()",
86  "null m_rng");
87  return;
88 }
virtual void resetSeed(int newSeed)
Resets the seed with value newSeed.
Definition: RngBase.C:60
int m_worldRank
Rank of processor.
Definition: RngBase.h:88
unsigned long int gsl_rng_default_seed
gsl_rng * m_rng
GSL random number generator.
Definition: RngGsl.h:111
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
int m_seed
Seed.
Definition: RngBase.h:85
const gsl_rng * RngGsl::rng ( ) const

GSL random number generator.

Definition at line 119 of file RngGsl.C.

References m_rng.

120 {
121  return m_rng;
122 }
gsl_rng * m_rng
GSL random number generator.
Definition: RngGsl.h:111
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 92 of file RngGsl.C.

References m_rng.

93 {
94  return gsl_rng_uniform(m_rng);
95 }
gsl_rng * m_rng
GSL random number generator.
Definition: RngGsl.h:111

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 111 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 Thu Apr 23 2015 19:26:17 for queso-0.51.1 by  doxygen 1.8.5