rng.cpp
Go to the documentation of this file.
00001 // Copyright (C) 2002-2006 Klaas Gadeyne <first dot last at gmail dot com>
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU Lesser General Public License as published by
00005 // the Free Software Foundation; either version 2.1 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 //
00017 #include "rng.h"
00018 
00019 #include <../config.h>
00020 #ifdef __RNGWRAPPER_BOOST__  // BOOST RANDOM LIBRARY
00021 // THE BOOST RANDOM NUMBER GENERATION LIBRARY
00022 
00023 #include <boost/random/mersenne_twister.hpp>
00024 #include <boost/random/variate_generator.hpp>
00025 #include <boost/random/normal_distribution.hpp>
00026 #include <boost/random/uniform_01.hpp>
00027 #include <boost/random/uniform_real.hpp>
00028 
00029 static boost::mt19937 Boost_Rng; // Source of randomness
00030 
00031 static boost::uniform_real<double> Uniform_Distribution; // Uniform distribution
00032 static boost::variate_generator<boost::mt19937&,boost::uniform_real<double> > roll(Boost_Rng,Uniform_Distribution);
00033 
00034 double BFL::rnorm(const double& mu,const double& sigma)
00035 {
00036   boost::normal_distribution<double> TestDist(mu,sigma);
00037   boost::variate_generator <boost::mt19937 &,boost::normal_distribution<double> > TestGen(Boost_Rng,TestDist);
00038   return TestGen();
00039 }
00040 
00041 double BFL::runif()
00042 {
00043   return roll();
00044 }
00045 
00046 double BFL::runif(const double &min, const double& max)
00047 {
00048   boost::uniform_real<double> Uniform_DistributionMinMax(min,max); // Uniform distribution
00049   boost::variate_generator<boost::mt19937&,boost::uniform_real<double> > roll(Boost_Rng,Uniform_DistributionMinMax);
00050   return roll();
00051 }
00052 
00053 #endif // __RNGWRAPPER_BOOST__
00054 
00055 
00056 
00057 
00058 
00059 #ifdef __RNGWRAPPER_SCYTHE__  // SCYTHE RANDOM LIBRARY
00060 
00061 #include <scythestat/rng.h>
00062 #include <scythestat/rng/mersenne.h>
00063 #include <scythestat/distributions.h>
00064 
00065 
00066 static scythe::mersenne bfl_mersenne;
00067 
00068 // Sample from univariate normal distribution with mu and sigma
00069 double BFL::rnorm(const double & mu, const double & sigma)
00070 {
00071   return (bfl_mersenne.rnorm(mu,sigma));
00072 }
00073 
00074 // Sample from uniform distribution
00075 double BFL::runif()
00076 {
00077   return (bfl_mersenne.runif());
00078 }
00079 
00080 double BFL::runif(const double &min, const double& max)
00081 {
00082   return (bfl_mersenne.runif()*(max-min)+min);
00083 }
00084 #endif // __RNGWRAPPER_SCYTHE__
00085 
00086 
00087 
00088 
00089 
00090 #ifdef __RNGWRAPPER_LTI__  // LTILIB
00091 
00092 #include <ltilib/ltiUniformDist.h>
00093 #include <ltilib/ltiGaussDist.h>
00094 
00095 // Sample from univariate normal distribution with mu and sigma
00096 double BFL::rnorm(const double & mu, const double & sigma)
00097 {
00098   lti::gaussianDistribution g(mu,sigma);
00099   return g.draw();
00100 }
00101 
00102 // FIXME: Check quality of RNG!!
00103 // Create uniform distribution between 0 and 1
00104 static lti::uniformDistribution unif;
00105 
00106 // Sample from uniform distribution
00107 double BFL::runif()
00108 {
00109   return unif.draw();
00110 }
00111 
00112 // Sample from uniform distribution
00113 double BFL::runif(const double &min, const double& max)
00114 {
00115   lti::uniformDistribution u(min,max);
00116   return u.draw();
00117 }
00118 #endif // __RNGWRAPPER_LTI__
00119 


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 Sun Oct 5 2014 22:29:53