00001 #ifndef RANDOMDISTRIBUTION_H_
00002 #define RANDOMDISTRIBUTION_H_
00003
00011 #include <boost/shared_ptr.hpp>
00012 using boost::shared_ptr;
00013
00014 #include <boost/random.hpp>
00015
00016 #include <vector>
00017
00018 #include "RandomEngine.h"
00019
00021 class RandomDistribution
00022 {
00023 public:
00024 virtual ~RandomDistribution() {};
00026
00027 double operator()(RandomEngine &eng ) { return get( eng ); };
00028 shared_ptr< std::vector<double> > operator()(RandomEngine &eng, size_t n );
00029 virtual RandomDistribution *clone(void) const = 0;
00030 protected:
00031 virtual double get( RandomEngine &eng ) { return 0; };
00032 };
00033
00035 template< typename boost_dist >
00036 class RandomDistributionBoostImplementation : public RandomDistribution
00037 {
00038 protected:
00039 typedef boost_dist boost_dist_t;
00040
00041 public:
00042 RandomDistributionBoostImplementation( boost_dist const& d ) : m_dist( d ) {};
00043 virtual ~RandomDistributionBoostImplementation() {};
00044
00045 virtual double get( RandomEngine &eng )
00046 {
00047 return m_dist( eng );
00048 };
00049
00050 virtual RandomDistribution *clone(void) const
00051 {
00052 return new RandomDistributionBoostImplementation( m_dist );
00053 };
00054
00055 private:
00056 boost_dist m_dist;
00057
00058 };
00059
00061 class BernoulliDistribution : public RandomDistributionBoostImplementation< boost::bernoulli_distribution<double> >
00062 {
00063 public:
00064 BernoulliDistribution( double p=0 ) : RandomDistributionBoostImplementation<boost_dist_t>( boost_dist_t( p ) ) {};
00065 };
00066
00068 class BinomialDistribution : public RandomDistributionBoostImplementation< boost::binomial_distribution<int,double> >
00069 {
00070 public:
00071 BinomialDistribution( int n=1, double p=0.5 ) : RandomDistributionBoostImplementation<boost_dist_t>( boost_dist_t(n, p) ) {};
00072 };
00073
00075 class CauchyDistribution : public RandomDistributionBoostImplementation< boost::cauchy_distribution<double> >
00076 {
00077 public:
00078 CauchyDistribution( double median=0, double sigma=1 ) : RandomDistributionBoostImplementation<boost_dist_t>( boost_dist_t(median, sigma) ) {};
00079 };
00080
00082 class ConstantNumber : public RandomDistribution
00083 {
00084 public:
00085
00086 ConstantNumber( double c=1 ) : c(c) {};
00087 virtual ~ConstantNumber() {};
00088
00089 virtual double get( RandomEngine &eng )
00090 {
00091 return c;
00092 };
00093
00094 virtual RandomDistribution *clone(void) const
00095 {
00096 return new ConstantNumber( c );
00097 };
00098
00099 private:
00100 double c;
00101 };
00102
00104 class ExponentialDistribution : public RandomDistributionBoostImplementation< boost::exponential_distribution<double> >
00105 {
00106 public:
00107 ExponentialDistribution( double lambda=1 ) : RandomDistributionBoostImplementation<boost_dist_t>( boost_dist_t(lambda) ) {};
00108 };
00109
00111 class GammaDistribution : public RandomDistributionBoostImplementation< boost::gamma_distribution<double> >
00112 {
00113 public:
00114 GammaDistribution( double alpha=1 ) : RandomDistributionBoostImplementation<boost_dist_t>( boost_dist_t(alpha) ) {};
00115 };
00116
00118 class GeometricDistribution : public RandomDistributionBoostImplementation< boost::geometric_distribution<int,double> >
00119 {
00120 public:
00121 GeometricDistribution( double p=0.5 ) : RandomDistributionBoostImplementation<boost_dist_t>( boost_dist_t(p) ) {};
00122 };
00123
00125 class LogNormalDistribution : public RandomDistributionBoostImplementation< boost::lognormal_distribution<double> >
00126 {
00127 public:
00128 LogNormalDistribution( double mean=0, double sigma=1 ) : RandomDistributionBoostImplementation<boost_dist_t>( boost_dist_t( mean, sigma ) ) {};
00129 };
00130
00132 class NormalDistribution : public RandomDistributionBoostImplementation< boost::normal_distribution<double> >
00133 {
00134 public:
00135 NormalDistribution( double mean=0, double sigma=1 ) : RandomDistributionBoostImplementation<boost_dist_t>( boost_dist_t( mean, sigma ) ) {};
00136 };
00137
00139 class PoissonDistribution : public RandomDistributionBoostImplementation< boost::poisson_distribution<int,double> >
00140 {
00141 public:
00142 PoissonDistribution( double mean=0 ) : RandomDistributionBoostImplementation<boost_dist_t>( boost_dist_t( mean ) ) {};
00143 };
00144
00146
00149 class TriangleDistribution : public RandomDistributionBoostImplementation< boost::triangle_distribution<double> >
00150 {
00151 public:
00152 TriangleDistribution( double a=0, double b=0.5, double c=1 ) : RandomDistributionBoostImplementation<boost_dist_t>( boost_dist_t( a, b, c ) ) {};
00153 };
00154
00156 class UniformDistribution : public RandomDistributionBoostImplementation< boost::uniform_real<double> >
00157 {
00158 public:
00159 UniformDistribution( double a=0, double b=0.5 ) : RandomDistributionBoostImplementation<boost_dist_t>( boost_dist_t( a, b ) ) {};
00160 };
00161
00163 class UniformIntegerDistribution : public RandomDistribution
00164 {
00165 public:
00166 UniformIntegerDistribution( int a=0, int b=1 ) : a(a), b(b), range(b-a+1) {};
00167 virtual ~UniformIntegerDistribution() {};
00168 virtual double get( RandomEngine &eng );
00169 virtual RandomDistribution *clone(void) const
00170 {
00171 return new UniformIntegerDistribution(a,b);
00172 };
00173 private:
00174 int a, b, range;
00175 };
00176
00178 class ClippedDistribution : public RandomDistribution
00179 {
00180 public:
00181 ClippedDistribution( RandomDistribution const& dist, double a, double b, size_t n=1 );
00182 virtual ~ClippedDistribution();
00183 virtual double get( RandomEngine &eng );
00184 virtual RandomDistribution *clone(void) const
00185 {
00186 return new ClippedDistribution(*dist,a,b,n);
00187 };
00188 private:
00189 RandomDistribution *dist;
00190 double a,b,range;
00191 size_t n;
00192 };
00193
00194
00196 class Gamma2Distribution : public GammaDistribution
00197 {
00198 public:
00199 Gamma2Distribution(double a, double b);
00200 virtual ~Gamma2Distribution()
00201 {
00202 }
00203
00204 virtual double get(RandomEngine &eng);
00205
00206 virtual RandomDistribution *clone(void) const
00207 {
00208 return new Gamma2Distribution(a,b);
00209 };
00210
00211 protected:
00212 double a, b;
00213 };
00214
00215
00217 class BndGammaDistribution : public Gamma2Distribution
00218 {
00219 public:
00220 BndGammaDistribution(double mu, double cv, double upperBound);
00221 virtual ~BndGammaDistribution()
00222 {
00223 }
00224
00225 virtual double get(RandomEngine &eng);
00226
00227 virtual RandomDistribution *clone(void) const
00228 {
00229 return new BndGammaDistribution(mu, cv, ub);
00230 };
00231
00232 protected:
00233 UniformDistribution uniform;
00234 double mu, cv, ub;
00235 };
00236
00237
00239 class BndNormalDistribution : public NormalDistribution
00240 {
00241 public:
00242 BndNormalDistribution(double mu, double cv, double lowerBound, double upperBound);
00243 virtual ~BndNormalDistribution()
00244 {
00245 }
00246
00247 virtual double get(RandomEngine &eng);
00248
00249 virtual RandomDistribution *clone(void) const
00250 {
00251 return new BndNormalDistribution(mu, cv, lb, ub);
00252 };
00253
00254 protected:
00255 UniformDistribution uniform;
00256 double mu, cv, lb, ub;
00257 };
00258
00259
00261 class QuadDistribution : public UniformDistribution
00262 {
00263 public:
00264 QuadDistribution(double a, double b);
00265 virtual ~QuadDistribution()
00266 {
00267 }
00268
00269 virtual double get(RandomEngine &eng);
00270
00271 virtual RandomDistribution *clone(void) const
00272 {
00273 return new QuadDistribution(a, b);
00274 };
00275
00276 protected:
00277 double a,b;
00278 };
00279
00280 #endif