COIN-OR::LEMON - Graph Library

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/random.h

    r463 r280  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2008
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    541541    /// @{
    542542
     543    ///\name Initialization
     544    ///
     545    /// @{
     546
    543547    /// \brief Default constructor
    544548    ///
     
    689693    }
    690694
     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
    691717    /// \brief Returns a random real number from the range [0, 1)
    692718    ///
     
    699725    ///
    700726    /// It returns a random real number from the range [0, b).
    701     double operator()(double b) {
    702       return real<double>() * b;
     727    template <typename Number>
     728    Number operator()(Number b) {
     729      return real<Number>() * b;
    703730    }
    704731
     
    706733    ///
    707734    /// It returns a random real number from the range [a, b).
    708     double operator()(double a, double b) {
    709       return real<double>() * (b - a) + a;
     735    template <typename Number>
     736    Number operator()(Number a, Number b) {
     737      return real<Number>() * (b - a) + a;
    710738    }
    711739
     
    743771      return _random_bits::IntConversion<Number, Word>::convert(core);
    744772    }
     773
     774    /// @}
    745775
    746776    unsigned int uinteger() {
     
    777807    ///\name Non-uniform distributions
    778808    ///
     809
    779810    ///@{
    780811
    781     /// \brief Returns a random bool with given probability of true result.
     812    /// \brief Returns a random bool
    782813    ///
    783814    /// It returns a random bool with given probability of true result.
     
    786817    }
    787818
    788     /// Standard normal (Gauss) distribution
    789 
    790     /// Standard normal (Gauss) distribution.
     819    /// Standard Gauss distribution
     820
     821    /// Standard Gauss distribution.
    791822    /// \note The Cartesian form of the Box-Muller
    792823    /// transformation is used to generate a random normal distribution.
     
    801832      return std::sqrt(-2*std::log(S)/S)*V1;
    802833    }
    803     /// Normal (Gauss) distribution with given mean and standard deviation
    804 
    805     /// Normal (Gauss) distribution with given mean and standard deviation.
     834    /// Gauss distribution with given mean and standard deviation
     835
     836    /// Gauss distribution with given mean and standard deviation.
    806837    /// \sa gauss()
    807838    double gauss(double mean,double std_dev)
    808839    {
    809840      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));
    850841    }
    851842
     
    953944    ///\name Two dimensional distributions
    954945    ///
     946
    955947    ///@{
    956948
     
    969961      return dim2::Point<double>(V1,V2);
    970962    }
    971     /// A kind of two dimensional normal (Gauss) distribution
     963    /// A kind of two dimensional Gauss distribution
    972964
    973965    /// This function provides a turning symmetric two-dimensional distribution.
Note: See TracChangeset for help on using the changeset viewer.