[3f9eba] | 1 | /*
|
---|
| 2 | * RandomNumberDistribution_Encapsulation.hpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Jan 01, 2011
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #ifndef RANDOMNUMBERDISTRIBUTION_ENCAPSULATION_HPP_
|
---|
| 9 | #define RANDOMNUMBERDISTRIBUTION_ENCAPSULATION_HPP_
|
---|
| 10 |
|
---|
| 11 | // include config.h
|
---|
| 12 | #ifdef HAVE_CONFIG_H
|
---|
| 13 | #include <config.h>
|
---|
| 14 | #endif
|
---|
| 15 |
|
---|
[081e5d] | 16 | #include "CodePatterns/Assert.hpp"
|
---|
| 17 |
|
---|
[3f9eba] | 18 | #include <typeinfo>
|
---|
| 19 |
|
---|
| 20 | #include <boost/nondet_random.hpp>
|
---|
| 21 | #include <boost/random.hpp>
|
---|
| 22 | #include <boost/random/bernoulli_distribution.hpp>
|
---|
| 23 | #include <boost/random/binomial_distribution.hpp>
|
---|
| 24 | #include <boost/random/cauchy_distribution.hpp>
|
---|
| 25 | #include <boost/random/exponential_distribution.hpp>
|
---|
| 26 | #include <boost/random/gamma_distribution.hpp>
|
---|
| 27 | #include <boost/random/geometric_distribution.hpp>
|
---|
| 28 | #include <boost/random/linear_congruential.hpp>
|
---|
| 29 | #include <boost/random/lognormal_distribution.hpp>
|
---|
| 30 | #include <boost/random/normal_distribution.hpp>
|
---|
| 31 | #include <boost/random/poisson_distribution.hpp>
|
---|
| 32 | #include <boost/random/triangle_distribution.hpp>
|
---|
| 33 | #include <boost/random/uniform_01.hpp>
|
---|
| 34 | #include <boost/random/uniform_int.hpp>
|
---|
| 35 | #include <boost/random/uniform_on_sphere.hpp>
|
---|
| 36 | #include <boost/random/uniform_real.hpp>
|
---|
| 37 | #include <boost/random/uniform_smallint.hpp>
|
---|
| 38 |
|
---|
[0275ad] | 39 | #include "CodePatterns/ManipulableClone.hpp"
|
---|
[c9bc2b7] | 40 | #include "RandomNumberDistribution.hpp"
|
---|
| 41 |
|
---|
[0275ad] | 42 | #include "RandomNumberDistribution_Parameters.hpp"
|
---|
| 43 |
|
---|
[9b3476] | 44 | class RandomNumberDistributionFactory;
|
---|
| 45 |
|
---|
[3f9eba] | 46 | /** Template class that encapsulates the random number distributions from
|
---|
| 47 | * random::boost.
|
---|
| 48 | *
|
---|
| 49 | *
|
---|
| 50 | * We need one template parameters:
|
---|
| 51 | * -# the distribution - generates uniform random numbers
|
---|
| 52 | */
|
---|
| 53 | template <class distribution>
|
---|
[1d5a871] | 54 | class RandomNumberDistribution_Encapsulation :
|
---|
| 55 | public RandomNumberDistribution,
|
---|
[0275ad] | 56 | public ManipulableClone<RandomNumberDistribution, RandomNumberDistribution_Parameters>
|
---|
[3f9eba] | 57 | {
|
---|
[9b3476] | 58 | /**
|
---|
| 59 | * Factory is friend such that it can access private cstor when filling its
|
---|
| 60 | * table
|
---|
| 61 | */
|
---|
| 62 | friend class RandomNumberDistributionFactory;
|
---|
| 63 |
|
---|
[3f9eba] | 64 | public:
|
---|
[0275ad] | 65 | /** Getter for the whole set of possible parameters.
|
---|
| 66 | *
|
---|
| 67 | * @return filled instance of RandomNumberDistribution_Parameters
|
---|
| 68 | */
|
---|
| 69 | RandomNumberDistribution_Parameters* getParameterSet() const
|
---|
| 70 | {
|
---|
| 71 | RandomNumberDistribution_Parameters *params = new RandomNumberDistribution_Parameters();
|
---|
| 72 | params->getParameters(this);
|
---|
| 73 | return params;
|
---|
| 74 | }
|
---|
[3f9eba] | 75 |
|
---|
[0275ad] | 76 | /** Getter for smallest value the uniform_... engines produces.
|
---|
[081e5d] | 77 | *
|
---|
| 78 | * @return smallest value
|
---|
| 79 | */
|
---|
| 80 | double min() const {
|
---|
[0275ad] | 81 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
[081e5d] | 82 | }
|
---|
| 83 |
|
---|
[0275ad] | 84 | /** Getter for largest value the uniform_... engines produces.
|
---|
[081e5d] | 85 | *
|
---|
| 86 | * @return largest value
|
---|
| 87 | */
|
---|
| 88 | double max() const {
|
---|
[0275ad] | 89 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
[081e5d] | 90 | }
|
---|
| 91 |
|
---|
| 92 | /** Getter for bernoulli_distribution's probability p.
|
---|
| 93 | *
|
---|
| 94 | * @return p
|
---|
| 95 | */
|
---|
| 96 | double p() const {
|
---|
[0275ad] | 97 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
[081e5d] | 98 | }
|
---|
| 99 |
|
---|
| 100 | /** Getter for binomial_distribution's parameter t.
|
---|
| 101 | *
|
---|
| 102 | * @return t
|
---|
| 103 | */
|
---|
| 104 | double t() const {
|
---|
[0275ad] | 105 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
[081e5d] | 106 | }
|
---|
| 107 |
|
---|
| 108 | /** Getter for cauchy_distribution parameter median.
|
---|
| 109 | *
|
---|
| 110 | * @return median
|
---|
| 111 | */
|
---|
| 112 | double median() const {
|
---|
[0275ad] | 113 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
[081e5d] | 114 | }
|
---|
| 115 |
|
---|
| 116 | /** Getter for cauchy_distribution parameter sigma.
|
---|
| 117 | *
|
---|
| 118 | * @return sigma
|
---|
| 119 | */
|
---|
| 120 | double sigma() const {
|
---|
[0275ad] | 121 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
[081e5d] | 122 | }
|
---|
| 123 |
|
---|
| 124 | /** Getter for gamma_distribution parameter alpha.
|
---|
| 125 | *
|
---|
| 126 | * @return alpha
|
---|
| 127 | */
|
---|
| 128 | double alpha() const {
|
---|
[0275ad] | 129 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
[081e5d] | 130 | }
|
---|
| 131 |
|
---|
| 132 | /** Getter for poisson_distribution's parameter mean.
|
---|
| 133 | *
|
---|
| 134 | * @return mean
|
---|
| 135 | */
|
---|
| 136 | double mean() const {
|
---|
[0275ad] | 137 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
[081e5d] | 138 | }
|
---|
| 139 |
|
---|
| 140 | /** Getter for triangle_distribution parameter a.
|
---|
| 141 | *
|
---|
| 142 | * @return a
|
---|
| 143 | */
|
---|
| 144 | double a() const {
|
---|
[0275ad] | 145 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
[081e5d] | 146 | }
|
---|
| 147 |
|
---|
| 148 | /** Getter for triangle_distribution parameter b.
|
---|
| 149 | *
|
---|
| 150 | * @return b
|
---|
| 151 | */
|
---|
| 152 | double b() const {
|
---|
[0275ad] | 153 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
[081e5d] | 154 | }
|
---|
| 155 |
|
---|
| 156 | /** Getter for triangle_distribution parameter c.
|
---|
| 157 | *
|
---|
| 158 | * @return c
|
---|
| 159 | */
|
---|
| 160 | double c() const {
|
---|
[0275ad] | 161 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
[081e5d] | 162 | }
|
---|
| 163 |
|
---|
| 164 | /** Getter for exponential_distribution parameter lambda.
|
---|
| 165 | *
|
---|
| 166 | * @return lambda
|
---|
| 167 | */
|
---|
| 168 | double lambda() const {
|
---|
[0275ad] | 169 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
[081e5d] | 170 | }
|
---|
| 171 |
|
---|
[3f9eba] | 172 | /** Getter for the type name of the internal distribution.
|
---|
| 173 | *
|
---|
| 174 | */
|
---|
| 175 | std::string name() {
|
---|
| 176 | return typeid(distribution_type).name();
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | /** Getter for the distribution instance.
|
---|
| 180 | *
|
---|
| 181 | * @return reference to instance
|
---|
| 182 | */
|
---|
| 183 | distribution& getDistribution() {
|
---|
| 184 | return distribution_type;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
[9b3476] | 187 | /** Clones the current instance.
|
---|
| 188 | *
|
---|
| 189 | * Implementation of Clone pattern.
|
---|
| 190 | *
|
---|
| 191 | * @return interface reference to cloned instance
|
---|
| 192 | */
|
---|
| 193 | RandomNumberDistribution* clone() const {
|
---|
| 194 | RandomNumberDistribution* MyClone = NULL;
|
---|
[0275ad] | 195 | RandomNumberDistribution_Parameters *params = getParameterSet();
|
---|
| 196 | MyClone = new RandomNumberDistribution_Encapsulation<distribution>(*params);
|
---|
| 197 | delete params;
|
---|
[9b3476] | 198 | return MyClone;
|
---|
| 199 | }
|
---|
| 200 |
|
---|
[0275ad] | 201 | /** Clones and manipulates the current instance.
|
---|
| 202 | *
|
---|
| 203 | * Implementation of ManipulableClone pattern.
|
---|
| 204 | *
|
---|
| 205 | * @param _params set of parameters to instantiate manipulated clone with
|
---|
| 206 | * @return interface reference to cloned&manipulated instance
|
---|
| 207 | */
|
---|
| 208 | ManipulableClone<RandomNumberDistribution, RandomNumberDistribution_Parameters>*
|
---|
| 209 | manipulatedclone(const RandomNumberDistribution_Parameters&_params) const
|
---|
| 210 | {
|
---|
| 211 | RandomNumberDistribution_Encapsulation<distribution>* newproto =
|
---|
| 212 | new RandomNumberDistribution_Encapsulation<distribution>(_params);
|
---|
| 213 | return newproto;
|
---|
| 214 | }
|
---|
| 215 |
|
---|
[9b3476] | 216 | protected:
|
---|
[3f9eba] | 217 | /** Constructor that instantiates a specific random number generator and
|
---|
| 218 | * distribution.
|
---|
| 219 | * @param _distribution_type instance of the desired distribution
|
---|
| 220 | */
|
---|
| 221 | RandomNumberDistribution_Encapsulation()
|
---|
| 222 | {}
|
---|
| 223 |
|
---|
[0275ad] | 224 | /** Constructor that instantiates a specific random number generator and
|
---|
| 225 | * distribution.
|
---|
| 226 | *
|
---|
| 227 | * @param _params set of parameters to instantiate manipulated clone with
|
---|
| 228 | * @param _distribution_type instance of the desired distribution
|
---|
| 229 | */
|
---|
| 230 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params)
|
---|
| 231 | {}
|
---|
| 232 |
|
---|
[3f9eba] | 233 | /** Destructor of the class.
|
---|
| 234 | *
|
---|
| 235 | */
|
---|
[c9bc2b7] | 236 | virtual ~RandomNumberDistribution_Encapsulation() {}
|
---|
[3f9eba] | 237 | private:
|
---|
| 238 | distribution distribution_type;
|
---|
| 239 | };
|
---|
| 240 |
|
---|
[081e5d] | 241 | // the following definitions prevents the compiler from instantiating the above
|
---|
| 242 | // template member functions for the desired cases.
|
---|
| 243 |
|
---|
[0275ad] | 244 | /* ========= manipulatedclone() ================ */
|
---|
| 245 |
|
---|
| 246 | template <>
|
---|
| 247 | RandomNumberDistribution_Encapsulation< boost::uniform_smallint<> >::
|
---|
| 248 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
| 249 |
|
---|
| 250 | template <>
|
---|
| 251 | RandomNumberDistribution_Encapsulation< boost::uniform_int<> >::
|
---|
| 252 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
| 253 |
|
---|
| 254 | template <>
|
---|
| 255 | RandomNumberDistribution_Encapsulation< boost::uniform_real<> >::
|
---|
| 256 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
| 257 |
|
---|
| 258 | template <>
|
---|
| 259 | RandomNumberDistribution_Encapsulation< boost::bernoulli_distribution<> >::
|
---|
| 260 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
| 261 |
|
---|
| 262 | template <>
|
---|
| 263 | RandomNumberDistribution_Encapsulation< boost::binomial_distribution<> >::
|
---|
| 264 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
| 265 |
|
---|
| 266 | template <>
|
---|
| 267 | RandomNumberDistribution_Encapsulation< boost::cauchy_distribution<> >::
|
---|
| 268 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
| 269 |
|
---|
| 270 | template <>
|
---|
| 271 | RandomNumberDistribution_Encapsulation< boost::gamma_distribution<> >::
|
---|
| 272 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
| 273 |
|
---|
| 274 | template <>
|
---|
| 275 | RandomNumberDistribution_Encapsulation< boost::poisson_distribution<> >::
|
---|
| 276 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
| 277 |
|
---|
| 278 | template <>
|
---|
| 279 | RandomNumberDistribution_Encapsulation< boost::geometric_distribution<> >::
|
---|
| 280 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
| 281 |
|
---|
| 282 | template <>
|
---|
| 283 | RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::
|
---|
| 284 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
| 285 |
|
---|
| 286 | template <>
|
---|
| 287 | RandomNumberDistribution_Encapsulation< boost::exponential_distribution<> >::
|
---|
| 288 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
| 289 |
|
---|
| 290 | template <>
|
---|
| 291 | RandomNumberDistribution_Encapsulation< boost::normal_distribution<> >::
|
---|
| 292 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
| 293 |
|
---|
| 294 | template <>
|
---|
| 295 | RandomNumberDistribution_Encapsulation< boost::lognormal_distribution<> >::
|
---|
| 296 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
| 297 |
|
---|
[081e5d] | 298 | /* =============== min() ======================= */
|
---|
| 299 |
|
---|
| 300 | template <>
|
---|
| 301 | double RandomNumberDistribution_Encapsulation< boost::uniform_smallint<> >::min() const;
|
---|
| 302 | template <>
|
---|
| 303 | double RandomNumberDistribution_Encapsulation< boost::uniform_int<> >::min() const;
|
---|
| 304 | template <>
|
---|
| 305 | double RandomNumberDistribution_Encapsulation< boost::uniform_01<> >::min() const;
|
---|
| 306 | template <>
|
---|
| 307 | double RandomNumberDistribution_Encapsulation< boost::uniform_real<> >::min() const;
|
---|
| 308 |
|
---|
| 309 |
|
---|
| 310 | /* =============== max() ======================= */
|
---|
| 311 |
|
---|
| 312 | template <>
|
---|
| 313 | double RandomNumberDistribution_Encapsulation< boost::uniform_smallint<> >::max() const;
|
---|
| 314 | template <>
|
---|
| 315 | double RandomNumberDistribution_Encapsulation< boost::uniform_int<> >::max() const;
|
---|
| 316 | template <>
|
---|
| 317 | double RandomNumberDistribution_Encapsulation< boost::uniform_01<> >::max() const;
|
---|
| 318 | template <>
|
---|
| 319 | double RandomNumberDistribution_Encapsulation< boost::uniform_real<> >::max() const;
|
---|
| 320 |
|
---|
| 321 |
|
---|
| 322 | /* =============== p() ======================= */
|
---|
| 323 |
|
---|
| 324 | template <>
|
---|
| 325 | double RandomNumberDistribution_Encapsulation< boost::bernoulli_distribution<> >::p() const;
|
---|
| 326 | template <>
|
---|
| 327 | double RandomNumberDistribution_Encapsulation< boost::binomial_distribution<> >::p() const;
|
---|
| 328 | template <>
|
---|
| 329 | double RandomNumberDistribution_Encapsulation< boost::geometric_distribution<> >::p() const;
|
---|
| 330 |
|
---|
| 331 |
|
---|
| 332 | /* =============== t() ======================= */
|
---|
| 333 |
|
---|
| 334 | template <>
|
---|
| 335 | double RandomNumberDistribution_Encapsulation< boost::binomial_distribution<> >::t() const;
|
---|
| 336 |
|
---|
| 337 |
|
---|
| 338 | /* =============== median() ======================= */
|
---|
| 339 |
|
---|
| 340 | template <>
|
---|
| 341 | double RandomNumberDistribution_Encapsulation< boost::cauchy_distribution<> >::median() const;
|
---|
| 342 |
|
---|
| 343 |
|
---|
| 344 | /* =============== sigma() ======================= */
|
---|
| 345 |
|
---|
| 346 | template <>
|
---|
| 347 | double RandomNumberDistribution_Encapsulation< boost::cauchy_distribution<> >::sigma() const;
|
---|
| 348 | template <>
|
---|
| 349 | double RandomNumberDistribution_Encapsulation< boost::normal_distribution<> >::sigma() const;
|
---|
| 350 | template <>
|
---|
| 351 | double RandomNumberDistribution_Encapsulation< boost::lognormal_distribution<> >::sigma() const;
|
---|
| 352 |
|
---|
| 353 |
|
---|
| 354 | /* =============== alpha() ======================= */
|
---|
| 355 |
|
---|
| 356 | template <>
|
---|
| 357 | double RandomNumberDistribution_Encapsulation< boost::gamma_distribution<> >::alpha() const;
|
---|
| 358 |
|
---|
| 359 |
|
---|
| 360 | /* =============== mean() ======================= */
|
---|
| 361 |
|
---|
| 362 | template <>
|
---|
| 363 | double RandomNumberDistribution_Encapsulation< boost::poisson_distribution<> >::mean() const;
|
---|
| 364 | template <>
|
---|
| 365 | double RandomNumberDistribution_Encapsulation< boost::normal_distribution<> >::mean() const;
|
---|
| 366 | template <>
|
---|
| 367 | double RandomNumberDistribution_Encapsulation< boost::lognormal_distribution<> >::mean() const;
|
---|
| 368 |
|
---|
| 369 |
|
---|
| 370 | /* =============== a() ======================= */
|
---|
| 371 |
|
---|
| 372 | template <>
|
---|
| 373 | double RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::a() const;
|
---|
| 374 |
|
---|
| 375 |
|
---|
| 376 | /* =============== b() ======================= */
|
---|
| 377 |
|
---|
| 378 | template <>
|
---|
| 379 | double RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::b() const;
|
---|
| 380 |
|
---|
| 381 |
|
---|
| 382 | /* =============== c() ======================= */
|
---|
| 383 |
|
---|
| 384 | template <>
|
---|
| 385 | double RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::c() const;
|
---|
| 386 |
|
---|
| 387 |
|
---|
| 388 | /* =============== lambda() ======================= */
|
---|
| 389 |
|
---|
| 390 | template <>
|
---|
| 391 | double RandomNumberDistribution_Encapsulation< boost::exponential_distribution<> >::lambda() const;
|
---|
| 392 |
|
---|
| 393 |
|
---|
| 394 |
|
---|
[3f9eba] | 395 | #endif /* RANDOMNUMBERDISTRIBUTION_ENCAPSULATION_HPP_ */
|
---|