COIN-OR::LEMON - Graph Library

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/random.h

    r280 r463  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2009
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    541541    /// @{
    542542
    543     ///\name Initialization
    544     ///
    545     /// @{
    546 
    547543    /// \brief Default constructor
    548544    ///
     
    693689    }
    694690
    695     /// \brief Returns a random real number the range [0, b)
    696     ///
    697     /// It returns a random real number from the range [0, b).
    698     template <typename Number>
    699     Number real(Number b) {
    700       return real<Number>() * b;
    701     }
    702 
    703     /// \brief Returns a random real number from the range [a, b)
    704     ///
    705     /// It returns a random real number from the range [a, b).
    706     template <typename Number>
    707     Number real(Number a, Number b) {
    708       return real<Number>() * (b - a) + a;
    709     }
    710 
    711     /// @}
    712 
    713     ///\name Uniform distributions
    714     ///
    715     /// @{
    716 
    717691    /// \brief Returns a random real number from the range [0, 1)
    718692    ///
     
    725699    ///
    726700    /// It returns a random real number from the range [0, b).
    727     template <typename Number>
    728     Number operator()(Number b) {
    729       return real<Number>() * b;
     701    double operator()(double b) {
     702      return real<double>() * b;
    730703    }
    731704
     
    733706    ///
    734707    /// It returns a random real number from the range [a, b).
    735     template <typename Number>
    736     Number operator()(Number a, Number b) {
    737       return real<Number>() * (b - a) + a;
     708    double operator()(double a, double b) {
     709      return real<double>() * (b - a) + a;
    738710    }
    739711
     
    771743      return _random_bits::IntConversion<Number, Word>::convert(core);
    772744    }
    773 
    774     /// @}
    775745
    776746    unsigned int uinteger() {
     
    807777    ///\name Non-uniform distributions
    808778    ///
    809 
    810779    ///@{
    811780
    812     /// \brief Returns a random bool
     781    /// \brief Returns a random bool with given probability of true result.
    813782    ///
    814783    /// It returns a random bool with given probability of true result.
     
    817786    }
    818787
    819     /// Standard Gauss distribution
    820 
    821     /// Standard Gauss distribution.
     788    /// Standard normal (Gauss) distribution
     789
     790    /// Standard normal (Gauss) distribution.
    822791    /// \note The Cartesian form of the Box-Muller
    823792    /// transformation is used to generate a random normal distribution.
     
    832801      return std::sqrt(-2*std::log(S)/S)*V1;
    833802    }
    834     /// Gauss distribution with given mean and standard deviation
    835 
    836     /// Gauss distribution with given mean and standard deviation.
     803    /// Normal (Gauss) distribution with given mean and standard deviation
     804
     805    /// Normal (Gauss) distribution with given mean and standard deviation.
    837806    /// \sa gauss()
    838807    double gauss(double mean,double std_dev)
    839808    {
    840809      return gauss()*std_dev+mean;
     810    }
     811
     812    /// Lognormal distribution
     813
     814    /// Lognormal distribution. The parameters are the mean and the standard
     815    /// deviation of <tt>exp(X)</tt>.
     816    ///
     817    double lognormal(double n_mean,double n_std_dev)
     818    {
     819      return std::exp(gauss(n_mean,n_std_dev));
     820    }
     821    /// Lognormal distribution
     822
     823    /// Lognormal distribution. The parameter is an <tt>std::pair</tt> of
     824    /// the mean and the standard deviation of <tt>exp(X)</tt>.
     825    ///
     826    double lognormal(const std::pair<double,double> &params)
     827    {
     828      return std::exp(gauss(params.first,params.second));
     829    }
     830    /// Compute the lognormal parameters from mean and standard deviation
     831
     832    /// This function computes the lognormal parameters from mean and
     833    /// standard deviation. The return value can direcly be passed to
     834    /// lognormal().
     835    std::pair<double,double> lognormalParamsFromMD(double mean,
     836                                                   double std_dev)
     837    {
     838      double fr=std_dev/mean;
     839      fr*=fr;
     840      double lg=std::log(1+fr);
     841      return std::pair<double,double>(std::log(mean)-lg/2.0,std::sqrt(lg));
     842    }
     843    /// Lognormal distribution with given mean and standard deviation
     844
     845    /// Lognormal distribution with given mean and standard deviation.
     846    ///
     847    double lognormalMD(double mean,double std_dev)
     848    {
     849      return lognormal(lognormalParamsFromMD(mean,std_dev));
    841850    }
    842851
     
    944953    ///\name Two dimensional distributions
    945954    ///
    946 
    947955    ///@{
    948956
     
    961969      return dim2::Point<double>(V1,V2);
    962970    }
    963     /// A kind of two dimensional Gauss distribution
     971    /// A kind of two dimensional normal (Gauss) distribution
    964972
    965973    /// This function provides a turning symmetric two-dimensional distribution.
Note: See TracChangeset for help on using the changeset viewer.