# Changeset 367

Ignore:
Timestamp:
Aug 5, 2005, 1:55:16 PM (17 years ago)
Message:

Location:
trunk
Files:
2 edited

### Legend:

Unmodified
 r366 /// /// @brief continuous random distributions. /// Base for continuous random distributions. /// /// Abstract base class for continuous random distributions. /// class RandomContinuous inline RandomContinuous(void) { rng_=RNG::instance(89); } /// /// @return A random number /// virtual double operator()(void) const = 0; /// @brief Uniform distribution /// /// Class for generating a random number from a flat distribution /// Class for generating a random number from a uniform distribution /// between zero and unity. /// /// Distribution function \f$f(x) = 1 \f$ for \f$0 \le x < 1 \f$ /// Expectation value: 0.5 /// Distribution function \f$f(x) = 1 \f$ for \f$0 \le x < 1 \f$ \n /// Expectation value: 0.5 \n /// Variance: \f$\frac{1}{12} \f$ /// /// /// Class to generate Gaussian random numbers. /// @brief Gaussian distribution /// /// Class for generating a random number from a Gaussian /// distribution between zero and unity. Utilizes the Box-Muller /// algorithm, which needs two calls to random generator. /// /// Distribution function \f$f(x) = /// \frac{1}{\sqrt{2\pi\sigma^2}}\exp(-\frac{(x-\mu)^2}{2\sigma^2}) /// \f$ \n /// Expectation value: \f$\mu \f$ \n /// Variance: \f$\sigma^2 \f$ /// class RandomGaussian : public RandomContinuous { public: /// /// @brief Constructor /// @param s is the standard deviation \f$\sigma \f$ of distribution /// m is the expectation value \f$\mu \f$ of the distribution /// inline RandomGaussian(const double s=1, const double m=0) : m_(m), s_(s) {} /// /// @return A random Gaussian number /// inline double operator()(void) const { return gsl_ran_gaussian(rng_->rng(), s_)+m_; } /// /// @return A random Gaussian number with standard deviation \a s /// and expectation value 0. /// @note this operator ignores parameters given in Constructor /// inline double operator()(const double s) const { return gsl_ran_gaussian(rng_->rng(), s); } /// /// @return A random Gaussian number with standard deviation \a s /// and expectation value \a m. /// @note this operator ignores parameters given in Constructor /// inline double operator()(const double s, const double m) const { return gsl_ran_gaussian(rng_->rng(), s)+m; } /// /// @brief exponential /// @brief Exponential distribution /// /// Class for generating a random number from a Exponential /// distribution. /// /// Distribution function \f$f(x) = \frac{1}{m}\exp(-x/a) \f$ for /// \f$x \f$ \n /// Expectation value: \f$m \f$ \n /// Variance: \f$m^2 \f$ /// class RandomExponential : public RandomContinuous public: /// /// Constructor /// @brief Constructor /// @param m is the expectation value of the distribution. /// inline RandomExponential(const double m=1) /// /// /// @return A random number from exponential distribution /// inline double operator()(void) const /// /// /// /// @return A random number from exponential distribution, with /// expectation value \a m /// @note this operator ignores parameters given in Constructor /// inline double operator()(const double m) const { return gsl_ran_exponential(rng_->rng(), m); } /// /// @brief discrete random distributions. /// Base for discrete random distributions. /// /// Abstract Base Class for discrete random distributions. Given K /// discrete events with different probabilities \f$P[k] \f$, /// produce a random value k consistent with its probability. /// class RandomDiscrete public: /// /// Constructor /// @brief Constructor /// inline RandomDiscrete(void) { rng_=RNG::instance(89); } /// /// Common interface for all Discrete Random Classes /// @return A random number. /// virtual long operator()(void) const = 0; }; /// /// @brief Discrete uniform distribution /// /// Discrete uniform distribution also known as the "equally likely /// outcomes" distribution. Each outcome, in this case an integer /// from \f$[a,b) \f$, have equal probability to occur. /// /// Distribution function \f$p(k) = \frac{1}{b-a} \f$ for \f$a \le /// k < b \f$ \n /// Expectation value: \f$\frac{a+b}{2} \f$ \n /// Variance: \f$\frac{1}{3}((b-a)^2-1) \f$ /// class RandomDiscreteUniform : public RandomDiscrete public: /// /// Constructor. /// @brief Constructor. /// /// @param \a range is number of different integers that can be /// generated \f$(b-a+1) \f$ \a min is the minimal integer that /// can be generated \f$(a) \f$ /// inline RandomDiscreteUniform(const u_long range, const long min=0) /// /// @return A random number between \a min and \a range - \a min /// @note this operator ignores parameters given in Constructor /// inline long operator()(const u_long range, const long min) const /// /// @brief Poisson /// class RandomPoisson : public RandomContinuous { public: /// /// Constructor /// /// @brief Poisson Distribution /// /// Having a Poisson process (no memory), number of occurences /// within a given time window is Poisson distributed. This /// distribution is the limit of a Binomial distribution when number /// of attempts is large, and the probability for one attempt to be /// succesful is small (in such a way that the expected number of /// succesful attempts is \f$m \f$. /// /// Probability function \f$p(k) = e^{-m}\frac{m^k}{k!} \f$ for \f$0 \le /// k \f$ \n /// Expectation value: \f$m \f$ \n /// Variance: \f$m \f$ /// class RandomPoisson : public RandomDiscrete { public: /// /// @brief Constructor /// /// @param m is expectation value inline RandomPoisson(const double m=1) : m_(m){} /// /// /// @return a Poisson distributed number. /// inline double operator()(void) const /// /// /// /// @return a Poisson distributed number with expectation value \a /// m /// @note this operator ignores parameters set in Constructor inline double operator()(const double m) const { return gsl_ran_poisson(rng_->rng(), m); }