191 |
191 |
192 |
192 |
193 /** |
193 /** |
194 * \brief The uniform distribution RNG for NS-3. |
194 * \brief The uniform distribution RNG for NS-3. |
195 * \ingroup randomvariable |
195 * \ingroup randomvariable |
|
196 * |
196 * This class supports the creation of objects that return random numbers |
197 * This class supports the creation of objects that return random numbers |
197 * from a fixed uniform distribution. It also supports the generation of |
198 * from a fixed uniform distribution. It also supports the generation of |
198 * single random numbers from various uniform distributions. |
199 * single random numbers from various uniform distributions. |
|
200 * |
|
201 * The low end of the range is always included and the high end |
|
202 * of the range is always excluded. |
199 * \code |
203 * \code |
200 * UniformVariable x(0,10); |
204 * UniformVariable x(0,10); |
201 * x.GetValue(); //will always return numbers [0,10] |
205 * x.GetValue(); //will always return numbers [0,10) |
202 * UniformVariable::GetSingleValue(100,1000); //returns a value [100,1000] |
206 * UniformVariable::GetSingleValue(100,1000); //returns a value [100,1000) |
203 * \endcode |
207 * \endcode |
204 */ |
208 */ |
205 class UniformVariable : public RandomVariable { |
209 class UniformVariable : public RandomVariable { |
206 public: |
210 public: |
207 /** |
211 /** |
208 * Creates a uniform random number generator in the |
212 * Creates a uniform random number generator in the |
209 * range [0.0 .. 1.0) |
213 * range [0.0 .. 1.0). |
210 */ |
214 */ |
211 UniformVariable(); |
215 UniformVariable(); |
212 |
216 |
213 /** |
217 /** |
214 * Creates a uniform random number generator with the specified range |
218 * Creates a uniform random number generator with the specified range |
332 }; |
336 }; |
333 |
337 |
334 /** |
338 /** |
335 * \brief Exponentially Distributed random var |
339 * \brief Exponentially Distributed random var |
336 * \ingroup randomvariable |
340 * \ingroup randomvariable |
|
341 * |
337 * This class supports the creation of objects that return random numbers |
342 * This class supports the creation of objects that return random numbers |
338 * from a fixed exponential distribution. It also supports the generation of |
343 * from a fixed exponential distribution. It also supports the generation of |
339 * single random numbers from various exponential distributions. |
344 * single random numbers from various exponential distributions. |
|
345 * |
|
346 * The probability density function of an exponential variable |
|
347 * is defined over the interval [0, +inf) as: |
|
348 * \f$ \alpha e^{-\alpha x} \f$ |
|
349 * where \f$ \alpha = \frac{1}{mean} \f$ |
|
350 * |
|
351 * The bounded version is defined over the internal [0,+inf) as: |
|
352 * \f$ \left\{ \begin{array}{cl} \alpha e^{-\alpha x} & x < bound \\ bound & x > bound \end{array}\right. \f$ |
|
353 * |
340 * \code |
354 * \code |
341 * ExponentialVariable x(3.14); |
355 * ExponentialVariable x(3.14); |
342 * x.GetValue(); //will always return with mean 3.14 |
356 * x.GetValue(); //will always return with mean 3.14 |
343 * ExponentialVariable::GetSingleValue(20.1); //returns with mean 20.1 |
357 * ExponentialVariable::GetSingleValue(20.1); //returns with mean 20.1 |
344 * ExponentialVariable::GetSingleValue(108); //returns with mean 108 |
358 * ExponentialVariable::GetSingleValue(108); //returns with mean 108 |
392 }; |
406 }; |
393 |
407 |
394 /** |
408 /** |
395 * \brief ParetoVariable distributed random var |
409 * \brief ParetoVariable distributed random var |
396 * \ingroup randomvariable |
410 * \ingroup randomvariable |
|
411 * |
397 * This class supports the creation of objects that return random numbers |
412 * This class supports the creation of objects that return random numbers |
398 * from a fixed pareto distribution. It also supports the generation of |
413 * from a fixed pareto distribution. It also supports the generation of |
399 * single random numbers from various pareto distributions. |
414 * single random numbers from various pareto distributions. |
|
415 * |
|
416 * The probability density function is defined over the range [\f$x_m\f$,+inf) as: |
|
417 * \f$ k \frac{x_m^k}{x^{k+1}}\f$ where \f$x_m > 0\f$ is called the location |
|
418 * parameter and \f$ k > 0\f$ is called the pareto index or shape. |
|
419 * |
|
420 * The parameter \f$ x_m \f$ can be infered from the mean and the parameter \f$ k \f$ |
|
421 * with the equation \f$ x_m = mean \frac{k-1}{k}, k > 1\f$. |
|
422 * |
400 * \code |
423 * \code |
401 * ParetoVariable x(3.14); |
424 * ParetoVariable x(3.14); |
402 * x.GetValue(); //will always return with mean 3.14 |
425 * x.GetValue(); //will always return with mean 3.14 |
403 * ParetoVariable::GetSingleValue(20.1); //returns with mean 20.1 |
426 * ParetoVariable::GetSingleValue(20.1); //returns with mean 20.1 |
404 * ParetoVariable::GetSingleValue(108); //returns with mean 108 |
427 * ParetoVariable::GetSingleValue(108); //returns with mean 108 |
466 }; |
489 }; |
467 |
490 |
468 /** |
491 /** |
469 * \brief WeibullVariable distributed random var |
492 * \brief WeibullVariable distributed random var |
470 * \ingroup randomvariable |
493 * \ingroup randomvariable |
|
494 * |
471 * This class supports the creation of objects that return random numbers |
495 * This class supports the creation of objects that return random numbers |
472 * from a fixed weibull distribution. It also supports the generation of |
496 * from a fixed weibull distribution. It also supports the generation of |
473 * single random numbers from various weibull distributions. |
497 * single random numbers from various weibull distributions. |
|
498 * |
|
499 * The probability density function is defined over the interval [0, +inf] |
|
500 * as: \f$ \frac{k}{\lambda}\left(\frac{x}{\lambda}\right)^{k-1}e^{-\left(\frac{x}{\lambda}\right)^k} \f$ |
|
501 * where \f$ k > 0\f$ is the shape parameter and \f$ \lambda > 0\f$ is the scale parameter. The |
|
502 * specified mean is related to the scale and shape parameters by the following relation: |
|
503 * \f$ mean = \lambda\Gamma\left(1+\frac{1}{k}\right) \f$ where \f$ \Gamma \f$ is the Gamma function. |
474 */ |
504 */ |
475 class WeibullVariable : public RandomVariable { |
505 class WeibullVariable : public RandomVariable { |
476 public: |
506 public: |
477 /** |
507 /** |
478 * Constructs a weibull random variable with a mean |
508 * Constructs a weibull random variable with a mean |
531 }; |
561 }; |
532 |
562 |
533 /** |
563 /** |
534 * \brief Class NormalVariable defines a random variable with a |
564 * \brief Class NormalVariable defines a random variable with a |
535 * normal (Gaussian) distribution. |
565 * normal (Gaussian) distribution. |
|
566 * \ingroup randomvariable |
536 * |
567 * |
537 * This class supports the creation of objects that return random numbers |
568 * This class supports the creation of objects that return random numbers |
538 * from a fixed normal distribution. It also supports the generation of |
569 * from a fixed normal distribution. It also supports the generation of |
539 * single random numbers from various normal distributions. |
570 * single random numbers from various normal distributions. |
540 * \ingroup randomvariable |
571 * |
|
572 * The density probability function is defined over the interval (-inf,+inf) |
|
573 * as: \f$ \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{s\sigma^2}}\f$ |
|
574 * where \f$ mean = \mu \f$ and \f$ variance = \sigma^2 \f$ |
|
575 * |
541 */ |
576 */ |
542 class NormalVariable : public RandomVariable { // Normally Distributed random var |
577 class NormalVariable : public RandomVariable { // Normally Distributed random var |
543 |
578 |
544 public: |
579 public: |
545 static const double INFINITE_VALUE; |
580 static const double INFINITE_VALUE; |
586 * \brief EmpiricalVariable distribution random var |
621 * \brief EmpiricalVariable distribution random var |
587 * \ingroup randomvariable |
622 * \ingroup randomvariable |
588 * |
623 * |
589 * Defines a random variable that has a specified, empirical |
624 * Defines a random variable that has a specified, empirical |
590 * distribution. The distribution is specified by a |
625 * distribution. The distribution is specified by a |
591 * series of calls the the CDF member function, specifying a |
626 * series of calls to the CDF member function, specifying a |
592 * value and the probability that the function value is less than |
627 * value and the probability that the function value is less than |
593 * the specified value. When values are requested, |
628 * the specified value. When values are requested, |
594 * a uniform random variable is used to select a probabililty, |
629 * a uniform random variable is used to select a probabililty, |
595 * and the return value is interpreted linerarly between the |
630 * and the return value is interpreted linerarly between the |
596 * two appropriate points in the CDF |
631 * two appropriate points in the CDF |
691 |
726 |
692 |
727 |
693 /** |
728 /** |
694 * \brief Log-normal Distributed random var |
729 * \brief Log-normal Distributed random var |
695 * \ingroup randomvariable |
730 * \ingroup randomvariable |
|
731 * |
696 * LogNormalVariable defines a random variable with log-normal |
732 * LogNormalVariable defines a random variable with log-normal |
697 * distribution. If one takes the natural logarithm of random |
733 * distribution. If one takes the natural logarithm of random |
698 * variable following the log-normal distribution, the obtained values |
734 * variable following the log-normal distribution, the obtained values |
699 * follow a normal distribution. |
735 * follow a normal distribution. |
700 * This class supports the creation of objects that return random numbers |
736 * This class supports the creation of objects that return random numbers |
701 * from a fixed lognormal distribution. It also supports the generation of |
737 * from a fixed lognormal distribution. It also supports the generation of |
702 * single random numbers from various lognormal distributions. |
738 * single random numbers from various lognormal distributions. |
|
739 * |
|
740 * The probability density function is defined over the interval [0,+inf) as: |
|
741 * \f$ \frac{1}{x\sigma\sqrt{2\pi}} e^{-\frac{(ln(x) - \mu)^2}{2\sigma^2}}\f$ |
|
742 * where \f$ mean = e^{\mu+\frac{\sigma^2}{2}} \f$ and |
|
743 * \f$ variance = (e^{\sigma^2}-1)e^{2\mu+\sigma^2}\f$ |
|
744 * |
|
745 * The \f$ \mu \f$ and \f$ \sigma \f$ parameters can be calculated from the mean |
|
746 * and standard deviation with the following equations: |
|
747 * \f$ \mu = ln(mean) - \frac{1}{2}ln\left(1+\frac{stddev}{mean^2}\right)\f$, and, |
|
748 * \f$ \sigma = \sqrt{ln\left(1+\frac{stddev}{mean^2}\right)}\f$ |
703 */ |
749 */ |
704 class LogNormalVariable : public RandomVariable { |
750 class LogNormalVariable : public RandomVariable { |
705 public: |
751 public: |
706 /** |
752 /** |
707 * \param mu Mean value of the underlying normal distribution. |
753 * \param mu mu parameter of the lognormal distribution |
708 * \param sigma Standard deviation of the underlying normal distribution. |
754 * \param sigma sigma parameter of the lognormal distribution |
709 * |
|
710 * Notice: the parameters mu and sigma are _not_ the mean and standard |
|
711 * deviation of the log-normal distribution. To obtain the |
|
712 * parameters mu and sigma for a given mean and standard deviation |
|
713 * of the log-normal distribution the following convertion can be |
|
714 * used: |
|
715 * \code |
|
716 * double tmp = log (1 + pow (stddev/mean, 2)); |
|
717 * double sigma = sqrt (tmp); |
|
718 * double mu = log (mean) - 0.5*tmp; |
|
719 * \endcode |
|
720 */ |
755 */ |
721 LogNormalVariable (double mu, double sigma); |
756 LogNormalVariable (double mu, double sigma); |
722 |
757 |
723 /** |
758 /** |
724 * \return A random value from this distribution |
759 * \return A random value from this distribution |
725 */ |
760 */ |
726 virtual double GetValue (); |
761 virtual double GetValue (); |
727 virtual RandomVariable* Copy() const; |
762 virtual RandomVariable* Copy() const; |
728 public: |
763 public: |
729 /** |
764 /** |
730 * \param mu Mean value of the underlying normal distribution. |
765 * \param mu mu parameter of the underlying normal distribution |
731 * \param sigma Standard deviation of the underlying normal distribution. |
766 * \param sigma sigma parameter of the underlying normal distribution |
732 * \return A random number from the distribution specified by mu and sigma |
767 * \return A random number from the distribution specified by mu and sigma |
733 */ |
768 */ |
734 static double GetSingleValue(double mu, double sigma); |
769 static double GetSingleValue(double mu, double sigma); |
735 private: |
770 private: |
736 double m_mu; |
771 double m_mu; |