queso-0.52.0
RngBoost.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2015 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include <queso/RngBoost.h>
26 #include <mpi.h>
27 
28 namespace QUESO {
29 
30 // Default constructor ------------------------------
32  :
33  RngBase()
34 {
37  "RngBoost::constructor(), default",
38  "should not be used by user");
39 }
40 
42 RngBoost::RngBoost(int seed, int worldRank)
43  :
44  RngBase(seed,worldRank)
45  //m_rng(seed)
46 {
47  resetSeed(seed);
48 //TODO Find a suitable test for here; Kemelli todo
49 // UQ_FATAL_TEST_MACRO(true,
50 // m_worldRank,
51 // "RngBoos::constructor()",
52 // "Kemelli todo: boost rng");
53 }
54 
55 // Destructor ---------------------------------------
57 {
58  //this function does nothing
59 }
60 
61 // Sampling methods ---------------------------------
62 void
63 RngBoost::resetSeed(int newSeed)
64 {
65  m_rng.seed(newSeed);
66 
67  return;
68 }
69 
70 // --------------------------------------------------
71 double
73 {
74  static boost::uniform_01<boost::mt19937> zeroone(m_rng);
75  return zeroone();
76 }
77 
78 // --------------------------------------------------
79 double
80 RngBoost::gaussianSample(double stdDev) const
81 {
82  double mean = 0.; //it will be added conveniently later
83  static boost::uniform_01<boost::mt19937> zeroone(m_rng);
84  boost::math::normal_distribution<double> gaussian_dist(mean, stdDev);
85  return quantile(gaussian_dist, zeroone());
86 }
87 
88 // --------------------------------------------------
89 double
90 RngBoost::betaSample(double alpha, double beta) const
91 {
92  static boost::uniform_01<boost::mt19937> zeroone(m_rng);
93  boost::math::beta_distribution<double> beta_dist(alpha, beta);
94  return quantile(beta_dist, zeroone());
95 }
96 
97 // --------------------------------------------------
98 double
99 RngBoost::gammaSample(double a, double b) const
100 {
101  static boost::uniform_01<boost::mt19937> zeroone(m_rng);
102  boost::math::gamma_distribution<double> gamma_dist(a,b);
103  return quantile(gamma_dist, zeroone());
104 }
105 
106 } // End namespace QUESO
Class for random number generation (base class for either GSL or Boost RNG).
Definition: RngBase.h:45
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
RngBoost()
Default Constructor: it should not be used.
Definition: RngBoost.C:31
double uniformSample() const
Samples a value from a uniform distribution. Support: [0,1] or [a,b].
Definition: RngBoost.C:72
~RngBoost()
Destructor.
Definition: RngBoost.C:56
double betaSample(double alpha, double beta) const
Samples a value from a Beta distribution. Support: [0,1].
Definition: RngBoost.C:90
double gammaSample(double a, double b) const
Samples a value from a Gamma distribution. Support: [0,infinity).
Definition: RngBoost.C:99
int m_worldRank
Rank of processor.
Definition: RngBase.h:88
void resetSeed(int newSeed)
Resets the seed with value newSeed.
Definition: RngBoost.C:63
double gaussianSample(double stdDev) const
Definition: RngBoost.C:80
boost::mt19937 m_rng
Random number generator from class boost::mt19937.
Definition: RngBoost.h:110

Generated on Thu Apr 23 2015 19:30:54 for queso-0.52.0 by  doxygen 1.8.5