Changeset 364


Ignore:
Timestamp:
Aug 5, 2005, 10:25:21 AM (18 years ago)
Author:
Peter
Message:

added classes to random, now has all functionality that former random_singleton had except general distributions

Location:
trunk/lib/utility
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/utility/Random.h

    r362 r364  
    5757  public:
    5858
    59     inline double operator()(void) const { return gsl_rng_uniform(rng_->rng()); }
    60 
    61   };
    62 
    63 
    64 
     59    inline double operator()(void) const { return gsl_rng_uniform(rng_->rng());}
     60
     61  };
     62
     63  ///
     64  /// Class to generate Gaussian random numbers.
     65  ///
    6566  class RandomGaussian : public RandomContinuous
    6667  {
     
    8384  };
    8485
    85 
    86   class RandomDiscrete {
    87   };
    88 
    89 
    90   class RandomDiscreteUniform : public RandomDiscrete {
     86  ///
     87  /// @brief exponential
     88  ///
     89  class RandomExponential : public RandomContinuous
     90  {
     91  public:
     92    ///
     93    /// Constructor
     94    ///
     95    inline RandomExponential(const double m=1)
     96      : m_(m){}
     97
     98    ///
     99    ///
     100    ///
     101    inline double operator()(void) const
     102    { return gsl_ran_exponential(rng_->rng(), m_); }
     103
     104    ///
     105    ///
     106    ///
     107    inline double operator()(const double m) const
     108    { return gsl_ran_exponential(rng_->rng(), m); }
     109
     110  private:
     111    double m_;
     112  };
     113
     114
     115  ///
     116  /// Base class for discrete random distributions.
     117  ///
     118  class RandomDiscrete
     119  {
     120  public:
     121    ///
     122    /// Constructor
     123    ///
     124    inline RandomDiscrete(void) { rng_=RNG::instance(89); }
     125
     126    ///
     127    /// Common interface for all Discrete Random Classes
     128    ///
     129    virtual long operator()(void) const = 0;
     130   
     131  protected:
     132    RNG* rng_;
     133  };
     134
     135
     136  class RandomDiscreteUniform : public RandomDiscrete
     137  {
     138  public:
     139    ///
     140    /// Constructor.
     141    ///
     142    inline RandomDiscreteUniform(const u_long range, const long min=0)
     143      : min_(min), range_(range) {}
     144
     145    ///
     146    /// @return A random number between \a min_ and \a range_ - \a min_
     147    ///
     148    inline long operator()(void) const
     149    { return gsl_rng_uniform_int(rng_->rng(), range_)+min_; }
     150
     151    ///
     152    /// @return A random number between 0 and \a range.
     153    ///
     154    inline long operator()(const u_long range) const
     155    { return gsl_rng_uniform_int(rng_->rng(), range); }
     156
     157    ///
     158    /// @return A random number between \a min and \a range - \a min
     159    ///
     160    inline long operator()(const u_long range, const long min) const
     161    { return gsl_rng_uniform_int(rng_->rng(), range)+min; }
     162
     163
     164  private:
     165    long min_;
     166    u_long range_;
     167  };
     168
     169
     170  ///
     171  /// @brief Poisson
     172  ///
     173  class RandomPoisson : public RandomContinuous
     174  {
     175  public:
     176    ///
     177    /// Constructor
     178    ///
     179    inline RandomPoisson(const double m=1)
     180      : m_(m){}
     181
     182    ///
     183    ///
     184    ///
     185    inline double operator()(void) const
     186    { return gsl_ran_poisson(rng_->rng(), m_); }
     187
     188    ///
     189    ///
     190    ///
     191    inline double operator()(const double m) const
     192    { return gsl_ran_poisson(rng_->rng(), m); }
     193
     194  private:
     195    double m_;
    91196  };
    92197
  • trunk/lib/utility/random_singleton.cc

    r358 r364  
    22
    33#include <c++_tools/utility/random_singleton.h>
     4
     5#include <c++_tools/gslapi/vector.h>
    46
    57namespace theplu {
     
    5557}
    5658
    57 /**
    58 double random_singleton::get_poisson(const double m) const
     59void random_singleton::general_distribution_prob(const gslapi::vector& p)
    5960{
    60  
     61
    6162}
    62 */
    6363
    6464}} // of namespace utility and namespace theplu
  • trunk/lib/utility/random_singleton.h

    r359 r364  
    1313
    1414namespace theplu {
     15namespace gslapi {
     16  class vector;
     17}
     18
    1519namespace utility { 
    1620
    17   ///
     21  ///
    1822  /// Class defining interface for different random stuff.
    1923  ///
     
    111115    /// @see rnd_discrete
    112116    ///
    113     inline void general_distribution_prob( const size_t& k,
    114                                            const double* p )
    115     { gen_ = gsl_ran_discrete_preproc( k, p ); }
     117    void general_distribution_prob( const gslapi::vector& p);
    116118
    117119    ///
Note: See TracChangeset for help on using the changeset viewer.