COIN-OR::LEMON - Graph Library

Changeset 2355:ac0d843b8873 in lemon-0.x


Ignore:
Timestamp:
02/06/07 20:16:26 (12 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3155
Message:

Two new distributions added:

  • Gaussian distribution generated using the polar form of the Box-Muller transformation,
  • Exponential distribution generated using inverse cdf.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/random.h

    r2285 r2355  
    2525
    2626#include <ctime>
    27 #include <cmath>
    2827#include <cmath>
    2928
     
    632631      return operator()() < p;
    633632    }
     633
     634    /// Standard Gauss distribution
     635
     636    /// Standard Gauss distribution.
     637    /// \todo Currently it uses the so-calles "polar technique" to generate
     638    /// random distribution.
     639    /// Probably, the "Ziggurat" method should rather be used.
     640    double gauss()
     641    {
     642      double V1,V2,S;
     643      do {
     644        V1=2*real<double>()-1;
     645        V2=2*real<double>()-1;
     646        S=V1*V1+V2*V2;
     647      } while(S>=1);
     648      return std::sqrt(-2*std::log(S)/S)*V1;
     649    }
     650    /// Gauss distribution with given variance and mean 0
     651    double gauss(double var)
     652    {
     653      return gauss()*var;
     654    }
     655    /// Gauss distribution with given variance and mean
     656    double gauss(double var,double mean)
     657    {
     658      return gauss()*var+mean;
     659    }
     660
     661    double exponential(double lambda)
     662    {
     663      return -log(real<double>())/lambda;
     664    }
    634665   
    635666  };
Note: See TracChangeset for help on using the changeset viewer.