Pareto and Weibull random distributions
authorAlpar Juttner <alpar@cs.elte.hu>
Fri, 21 Dec 2007 01:32:24 +0000
changeset 11ea5945b2da9c
parent 10 99e499ca560b
child 12 435bbc8127b3
Pareto and Weibull random distributions
lemon/random.h
     1.1 --- a/lemon/random.h	Fri Dec 21 00:07:03 2007 +0000
     1.2 +++ b/lemon/random.h	Fri Dec 21 01:32:24 2007 +0000
     1.3 @@ -737,7 +737,7 @@
     1.4      ///
     1.5      double exponential(double lambda=1.0)
     1.6      {
     1.7 -      return -std::log(real<double>())/lambda;
     1.8 +      return -std::log(1.0-real<double>())/lambda;
     1.9      }
    1.10  
    1.11      /// Gamma distribution with given integer shape
    1.12 @@ -782,6 +782,33 @@
    1.13        return theta*(xi-gamma(int(std::floor(k))));
    1.14      }
    1.15      
    1.16 +    /// Weibull distribution
    1.17 +
    1.18 +    /// This function generates a Weibull distribution random number.
    1.19 +    /// 
    1.20 +    ///\param k shape parameter (<tt>k>0</tt>)
    1.21 +    ///\param lambda scale parameter (<tt>lambda>0</tt>)
    1.22 +    ///
    1.23 +    double weibull(double k,double lambda)
    1.24 +    {
    1.25 +      return lambda*pow(-std::log(1.0-real<double>()),1.0/k);
    1.26 +    }  
    1.27 +      
    1.28 +    /// Pareto distribution
    1.29 +
    1.30 +    /// This function generates a Pareto distribution random number.
    1.31 +    /// 
    1.32 +    ///\param x_min location parameter (<tt>x_min>0</tt>)
    1.33 +    ///\param k shape parameter (<tt>k>0</tt>)
    1.34 +    ///
    1.35 +    ///\warning This function used inverse transform sampling, therefore may
    1.36 +    ///suffer from numerical unstability.
    1.37 +    ///
    1.38 +    ///\todo Implement a numerically stable method
    1.39 +    double pareto(double x_min,double k)
    1.40 +    {
    1.41 +      return x_min*pow(1.0-real<double>(),1.0/k);
    1.42 +    }  
    1.43        
    1.44      ///@}
    1.45