rng.cpp
Go to the documentation of this file.
1 // Copyright (C) 2002-2006 Klaas Gadeyne <first dot last at gmail dot com>
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU Lesser General Public License as published by
5 // the Free Software Foundation; either version 2.1 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 #include "rng.h"
18 
19 #include <../config.h>
20 #ifdef __RNGWRAPPER_BOOST__ // BOOST RANDOM LIBRARY
21 // THE BOOST RANDOM NUMBER GENERATION LIBRARY
22 
23 #include <boost/random/mersenne_twister.hpp>
24 #include <boost/random/variate_generator.hpp>
25 #include <boost/random/normal_distribution.hpp>
26 #include <boost/random/uniform_01.hpp>
27 #include <boost/random/uniform_real.hpp>
28 
29 static boost::mt19937 Boost_Rng; // Source of randomness
30 
31 static boost::uniform_real<double> Uniform_Distribution; // Uniform distribution
32 static boost::variate_generator<boost::mt19937&,boost::uniform_real<double> > roll(Boost_Rng,Uniform_Distribution);
33 
34 double BFL::rnorm(const double& mu,const double& sigma)
35 {
36  boost::normal_distribution<double> TestDist(mu,sigma);
37  boost::variate_generator <boost::mt19937 &,boost::normal_distribution<double> > TestGen(Boost_Rng,TestDist);
38  return TestGen();
39 }
40 
41 double BFL::runif()
42 {
43  return roll();
44 }
45 
46 double BFL::runif(const double &min, const double& max)
47 {
48  boost::uniform_real<double> Uniform_DistributionMinMax(min,max); // Uniform distribution
49  boost::variate_generator<boost::mt19937&,boost::uniform_real<double> > roll(Boost_Rng,Uniform_DistributionMinMax);
50  return roll();
51 }
52 
53 #endif // __RNGWRAPPER_BOOST__
54 
55 
56 
57 
58 
59 #ifdef __RNGWRAPPER_SCYTHE__ // SCYTHE RANDOM LIBRARY
60 
61 #include <scythestat/rng.h>
62 #include <scythestat/rng/mersenne.h>
63 #include <scythestat/distributions.h>
64 
65 
66 static scythe::mersenne bfl_mersenne;
67 
68 // Sample from univariate normal distribution with mu and sigma
69 double BFL::rnorm(const double & mu, const double & sigma)
70 {
71  return (bfl_mersenne.rnorm(mu,sigma));
72 }
73 
74 // Sample from uniform distribution
75 double BFL::runif()
76 {
77  return (bfl_mersenne.runif());
78 }
79 
80 double BFL::runif(const double &min, const double& max)
81 {
82  return (bfl_mersenne.runif()*(max-min)+min);
83 }
84 #endif // __RNGWRAPPER_SCYTHE__
85 
86 
87 
88 
89 
90 #ifdef __RNGWRAPPER_LTI__ // LTILIB
91 
92 #include <ltilib/ltiUniformDist.h>
93 #include <ltilib/ltiGaussDist.h>
94 
95 // Sample from univariate normal distribution with mu and sigma
96 double BFL::rnorm(const double & mu, const double & sigma)
97 {
98  lti::gaussianDistribution g(mu,sigma);
99  return g.draw();
100 }
101 
102 // FIXME: Check quality of RNG!!
103 // Create uniform distribution between 0 and 1
104 static lti::uniformDistribution unif;
105 
106 // Sample from uniform distribution
107 double BFL::runif()
108 {
109  return unif.draw();
110 }
111 
112 // Sample from uniform distribution
113 double BFL::runif(const double &min, const double& max)
114 {
115  lti::uniformDistribution u(min,max);
116  return u.draw();
117 }
118 #endif // __RNGWRAPPER_LTI__
119 
double rnorm(const double &mu, const double &sigma)
double runif()


bfl
Author(s): Klaas Gadeyne, Wim Meeussen, Tinne Delaet and many others. See web page for a full contributor list. ROS package maintained by Wim Meeussen.
autogenerated on Mon Feb 28 2022 21:56:33