queso-0.55.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 
27 namespace QUESO {
28 
30 RngBoost::RngBoost(int seed, int worldRank)
31  :
32  RngBase(seed,worldRank)
33  //m_rng(seed)
34 {
35  resetSeed(seed);
36 //TODO Find a suitable test for here; Kemelli todo
37 
38 // m_worldRank,
39 // "RngBoos::constructor()",
40 // "Kemelli todo: boost rng");
41 }
42 
43 // Destructor ---------------------------------------
45 {
46  //this function does nothing
47 }
48 
49 // Sampling methods ---------------------------------
50 void
51 RngBoost::resetSeed(int newSeed)
52 {
53  m_rng.seed(newSeed);
54 
55  return;
56 }
57 
58 // --------------------------------------------------
59 double
61 {
62  static boost::uniform_01<boost::mt19937> zeroone(m_rng);
63  return zeroone();
64 }
65 
66 // --------------------------------------------------
67 double
68 RngBoost::gaussianSample(double stdDev) const
69 {
70  double mean = 0.; //it will be added conveniently later
71  static boost::uniform_01<boost::mt19937> zeroone(m_rng);
72  boost::math::normal_distribution<double> gaussian_dist(mean, stdDev);
73  return quantile(gaussian_dist, zeroone());
74 }
75 
76 // --------------------------------------------------
77 double
78 RngBoost::betaSample(double alpha, double beta) const
79 {
80  static boost::uniform_01<boost::mt19937> zeroone(m_rng);
81  boost::math::beta_distribution<double> beta_dist(alpha, beta);
82  return quantile(beta_dist, zeroone());
83 }
84 
85 // --------------------------------------------------
86 double
87 RngBoost::gammaSample(double a, double b) const
88 {
89  static boost::uniform_01<boost::mt19937> zeroone(m_rng);
90  boost::math::gamma_distribution<double> gamma_dist(a,b);
91  return quantile(gamma_dist, zeroone());
92 }
93 
94 } // End namespace QUESO
~RngBoost()
Destructor.
Definition: RngBoost.C:44
double gaussianSample(double stdDev) const
Definition: RngBoost.C:68
boost::mt19937 m_rng
Random number generator from class boost::mt19937.
Definition: RngBoost.h:110
RngBoost()
Default Constructor: it should not be used.
double betaSample(double alpha, double beta) const
Samples a value from a Beta distribution. Support: [0,1].
Definition: RngBoost.C:78
double gammaSample(double a, double b) const
Samples a value from a Gamma distribution. Support: [0,infinity).
Definition: RngBoost.C:87
void resetSeed(int newSeed)
Resets the seed with value newSeed.
Definition: RngBoost.C:51
double uniformSample() const
Samples a value from a uniform distribution. Support: [0,1] or [a,b].
Definition: RngBoost.C:60
Class for random number generation (base class for either GSL or Boost RNG).
Definition: RngBase.h:45

Generated on Fri Jun 17 2016 14:17:40 for queso-0.55.0 by  doxygen 1.8.5