COIN-OR::LEMON - Graph Library

Ticket #164: 0293cb1b9e9c.patch

File 0293cb1b9e9c.patch, 4.9 KB (added by Peter Kovacs, 16 years ago)
  • lemon/random.h

    # HG changeset patch
    # User Peter Kovacs <kpeter@inf.elte.hu>
    # Date 1225190621 -3600
    # Node ID 0293cb1b9e9cc7d0a1f0dc1ef95a09ee07c732f5
    # Parent  2593e163e407403990ba8f4323f684190a625a62
    Add normal() as an alias for gauss() + doc improvements
    
    diff --git a/lemon/random.h b/lemon/random.h
    a b  
    540540    ///
    541541    /// @{
    542542
    543     ///\name Initialization
    544     ///
    545     /// @{
    546 
    547543    /// \brief Default constructor
    548544    ///
    549545    /// Constructor with constant seeding.
     
    708704      return real<Number>() * (b - a) + a;
    709705    }
    710706
    711     /// @}
    712 
    713     ///\name Uniform distributions
    714     ///
    715     /// @{
    716 
    717707    /// \brief Returns a random real number from the range [0, 1)
    718708    ///
    719709    /// It returns a random double from the range [0, 1).
     
    771761      return _random_bits::IntConversion<Number, Word>::convert(core);
    772762    }
    773763
    774     /// @}
    775 
    776764    unsigned int uinteger() {
    777765      return uinteger<unsigned int>();
    778766    }
     
    806794
    807795    ///\name Non-uniform distributions
    808796    ///
    809 
    810797    ///@{
    811798
    812     /// \brief Returns a random bool
     799    /// \brief Returns a random bool with given probability of true result.
    813800    ///
    814801    /// It returns a random bool with given probability of true result.
    815802    bool boolean(double p) {
    816803      return operator()() < p;
    817804    }
    818805
    819     /// Standard Gauss distribution
     806    /// Standard normal (Gauss) distribution
    820807
    821     /// Standard Gauss distribution.
     808    /// Standard normal (Gauss) distribution.
    822809    /// \note The Cartesian form of the Box-Muller
    823810    /// transformation is used to generate a random normal distribution.
    824     double gauss()
     811    double normal()
    825812    {
    826813      double V1,V2,S;
    827814      do {
     
    831818      } while(S>=1);
    832819      return std::sqrt(-2*std::log(S)/S)*V1;
    833820    }
    834     /// Gauss distribution with given mean and standard deviation
     821    /// Normal (Gauss) distribution with given mean and standard deviation
    835822
    836     /// Gauss distribution with given mean and standard deviation.
    837     /// \sa gauss()
     823    /// Normal (Gauss) distribution with given mean and standard deviation.
     824    /// \sa normal()
     825    double normal(double mean,double std_dev)
     826    {
     827      return normal()*std_dev+mean;
     828    }
     829
     830    /// Standard normal (Gauss) distribution
     831
     832    /// Standard normal (Gauss) distribution.
     833    ///
     834    /// It is an alias for \ref normal().
     835    double gauss()
     836    {
     837      return normal();
     838    }
     839    /// Normal (Gauss) distribution with given mean and standard deviation
     840
     841    /// Normal (Gauss) distribution with given mean and standard deviation.
     842    ///
     843    /// It is an alias for \ref normal(double, double).
    838844    double gauss(double mean,double std_dev)
    839845    {
    840       return gauss()*std_dev+mean;
     846      return normal(mean,std_dev);
    841847    }
    842848
    843849    /// Lognormal distribution
     
    864870    /// standard deviation. The return value can direcly be passed to
    865871    /// lognormal().
    866872    std::pair<double,double> lognormalParamsFromMD(double mean,
    867                                                    double std_dev)
     873                                                   double std_dev)
    868874    {
    869875      double fr=std_dev/mean;
    870876      fr*=fr;
     
    872878      return std::pair<double,double>(std::log(mean)-lg/2.0,std::sqrt(lg));
    873879    }
    874880    /// Lognormal distribution with given mean and standard deviation
    875    
     881
    876882    /// Lognormal distribution with given mean and standard deviation.
    877883    ///
    878884    double lognormalMD(double mean,double std_dev)
    879885    {
    880886      return lognormal(lognormalParamsFromMD(mean,std_dev));
    881887    }
    882    
     888
    883889    /// Exponential distribution with given mean
    884890
    885891    /// This function generates an exponential distribution random number
     
    983989
    984990    ///\name Two dimensional distributions
    985991    ///
    986 
    987992    ///@{
    988993
    989994    /// Uniform distribution on the full unit circle
     
    10001005      } while(V1*V1+V2*V2>=1);
    10011006      return dim2::Point<double>(V1,V2);
    10021007    }
    1003     /// A kind of two dimensional Gauss distribution
     1008    /// A kind of two dimensional normal (Gauss) distribution
    10041009
    10051010    /// This function provides a turning symmetric two-dimensional distribution.
    10061011    /// Both coordinates are of standard normal distribution, but they are not
     
    10081013    ///
    10091014    /// \note The coordinates are the two random variables provided by
    10101015    /// the Box-Muller method.
    1011     dim2::Point<double> gauss2()
     1016    dim2::Point<double> normal2()
    10121017    {
    10131018      double V1,V2,S;
    10141019      do {
     
    10191024      double W=std::sqrt(-2*std::log(S)/S);
    10201025      return dim2::Point<double>(W*V1,W*V2);
    10211026    }
     1027    /// A kind of two dimensional normal (Gauss) distribution
     1028
     1029    /// A kind of two dimensional normal (Gauss) distribution.
     1030    ///
     1031    /// It is an alias for \ref normal2().
     1032    dim2::Point<double> gauss2()
     1033    {
     1034      return normal2();
     1035    }
     1036
    10221037    /// A kind of two dimensional exponential distribution
    10231038
    10241039    /// This function provides a turning symmetric two-dimensional distribution.