[Lemon-commits] Alpar Juttner: Lognormal distribution added (#102)
Lemon HG
hg at lemon.cs.elte.hu
Mon Oct 27 19:00:07 CET 2008
details: http://lemon.cs.elte.hu/hg/lemon/rev/2593e163e407
changeset: 351:2593e163e407
user: Alpar Juttner <alpar [at] cs.elte.hu>
date: Thu Jun 19 17:33:06 2008 +0100
description:
Lognormal distribution added (#102)
diffstat:
1 file changed, 40 insertions(+)
lemon/random.h | 40 ++++++++++++++++++++++++++++++++++++++++
diffs (50 lines):
diff -r b77fb8c32707 -r 2593e163e407 lemon/random.h
--- a/lemon/random.h Thu Oct 23 12:39:39 2008 +0200
+++ b/lemon/random.h Thu Jun 19 17:33:06 2008 +0100
@@ -840,6 +840,46 @@
return gauss()*std_dev+mean;
}
+ /// Lognormal distribution
+
+ /// Lognormal distribution. The parameters are the mean and the standard
+ /// deviation of <tt>exp(X)</tt>.
+ ///
+ double lognormal(double n_mean,double n_std_dev)
+ {
+ return std::exp(gauss(n_mean,n_std_dev));
+ }
+ /// Lognormal distribution
+
+ /// Lognormal distribution. The parameter is an <tt>std::pair</tt> of
+ /// the mean and the standard deviation of <tt>exp(X)</tt>.
+ ///
+ double lognormal(const std::pair<double,double> ¶ms)
+ {
+ return std::exp(gauss(params.first,params.second));
+ }
+ /// Compute the lognormal parameters from mean and standard deviation
+
+ /// This function computes the lognormal parameters from mean and
+ /// standard deviation. The return value can direcly be passed to
+ /// lognormal().
+ std::pair<double,double> lognormalParamsFromMD(double mean,
+ double std_dev)
+ {
+ double fr=std_dev/mean;
+ fr*=fr;
+ double lg=std::log(1+fr);
+ return std::pair<double,double>(std::log(mean)-lg/2.0,std::sqrt(lg));
+ }
+ /// Lognormal distribution with given mean and standard deviation
+
+ /// Lognormal distribution with given mean and standard deviation.
+ ///
+ double lognormalMD(double mean,double std_dev)
+ {
+ return lognormal(lognormalParamsFromMD(mean,std_dev));
+ }
+
/// Exponential distribution with given mean
/// This function generates an exponential distribution random number
More information about the Lemon-commits
mailing list