COIN-OR::LEMON - Graph Library

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/random.h

    r517 r564  
    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).
     
    531531    /// @{
    532532
    533     ///\name Initialization
    534     ///
    535     /// @{
    536 
    537533    /// \brief Default constructor
    538534    ///
     
    681677    }
    682678
    683     /// @}
    684 
    685     ///\name Uniform distributions
    686     ///
    687     /// @{
    688 
    689679    /// \brief Returns a random real number from the range [0, 1)
    690680    ///
     
    741731      return _random_bits::IntConversion<Number, Word>::convert(core);
    742732    }
    743 
    744     /// @}
    745733
    746734    unsigned int uinteger() {
     
    777765    ///\name Non-uniform distributions
    778766    ///
    779 
    780767    ///@{
    781768
    782     /// \brief Returns a random bool
     769    /// \brief Returns a random bool with given probability of true result.
    783770    ///
    784771    /// It returns a random bool with given probability of true result.
     
    787774    }
    788775
    789     /// Standard Gauss distribution
    790 
    791     /// Standard Gauss distribution.
     776    /// Standard normal (Gauss) distribution
     777
     778    /// Standard normal (Gauss) distribution.
    792779    /// \note The Cartesian form of the Box-Muller
    793780    /// transformation is used to generate a random normal distribution.
     
    802789      return std::sqrt(-2*std::log(S)/S)*V1;
    803790    }
    804     /// Gauss distribution with given mean and standard deviation
    805 
    806     /// Gauss distribution with given mean and standard deviation.
     791    /// Normal (Gauss) distribution with given mean and standard deviation
     792
     793    /// Normal (Gauss) distribution with given mean and standard deviation.
    807794    /// \sa gauss()
    808795    double gauss(double mean,double std_dev)
    809796    {
    810797      return gauss()*std_dev+mean;
     798    }
     799
     800    /// Lognormal distribution
     801
     802    /// Lognormal distribution. The parameters are the mean and the standard
     803    /// deviation of <tt>exp(X)</tt>.
     804    ///
     805    double lognormal(double n_mean,double n_std_dev)
     806    {
     807      return std::exp(gauss(n_mean,n_std_dev));
     808    }
     809    /// Lognormal distribution
     810
     811    /// Lognormal distribution. The parameter is an <tt>std::pair</tt> of
     812    /// the mean and the standard deviation of <tt>exp(X)</tt>.
     813    ///
     814    double lognormal(const std::pair<double,double> &params)
     815    {
     816      return std::exp(gauss(params.first,params.second));
     817    }
     818    /// Compute the lognormal parameters from mean and standard deviation
     819
     820    /// This function computes the lognormal parameters from mean and
     821    /// standard deviation. The return value can direcly be passed to
     822    /// lognormal().
     823    std::pair<double,double> lognormalParamsFromMD(double mean,
     824                                                   double std_dev)
     825    {
     826      double fr=std_dev/mean;
     827      fr*=fr;
     828      double lg=std::log(1+fr);
     829      return std::pair<double,double>(std::log(mean)-lg/2.0,std::sqrt(lg));
     830    }
     831    /// Lognormal distribution with given mean and standard deviation
     832
     833    /// Lognormal distribution with given mean and standard deviation.
     834    ///
     835    double lognormalMD(double mean,double std_dev)
     836    {
     837      return lognormal(lognormalParamsFromMD(mean,std_dev));
    811838    }
    812839
     
    914941    ///\name Two dimensional distributions
    915942    ///
    916 
    917943    ///@{
    918944
     
    931957      return dim2::Point<double>(V1,V2);
    932958    }
    933     /// A kind of two dimensional Gauss distribution
     959    /// A kind of two dimensional normal (Gauss) distribution
    934960
    935961    /// This function provides a turning symmetric two-dimensional distribution.
Note: See TracChangeset for help on using the changeset viewer.