| ... | ... |
@@ -831,24 +831,64 @@ |
| 831 | 831 |
} while(S>=1); |
| 832 | 832 |
return std::sqrt(-2*std::log(S)/S)*V1; |
| 833 | 833 |
} |
| 834 | 834 |
/// Gauss distribution with given mean and standard deviation |
| 835 | 835 |
|
| 836 | 836 |
/// Gauss distribution with given mean and standard deviation. |
| 837 | 837 |
/// \sa gauss() |
| 838 | 838 |
double gauss(double mean,double std_dev) |
| 839 | 839 |
{
|
| 840 | 840 |
return gauss()*std_dev+mean; |
| 841 | 841 |
} |
| 842 | 842 |
|
| 843 |
/// Lognormal distribution |
|
| 844 |
|
|
| 845 |
/// Lognormal distribution. The parameters are the mean and the standard |
|
| 846 |
/// deviation of <tt>exp(X)</tt>. |
|
| 847 |
/// |
|
| 848 |
double lognormal(double n_mean,double n_std_dev) |
|
| 849 |
{
|
|
| 850 |
return std::exp(gauss(n_mean,n_std_dev)); |
|
| 851 |
} |
|
| 852 |
/// Lognormal distribution |
|
| 853 |
|
|
| 854 |
/// Lognormal distribution. The parameter is an <tt>std::pair</tt> of |
|
| 855 |
/// the mean and the standard deviation of <tt>exp(X)</tt>. |
|
| 856 |
/// |
|
| 857 |
double lognormal(const std::pair<double,double> ¶ms) |
|
| 858 |
{
|
|
| 859 |
return std::exp(gauss(params.first,params.second)); |
|
| 860 |
} |
|
| 861 |
/// Compute the lognormal parameters from mean and standard deviation |
|
| 862 |
|
|
| 863 |
/// This function computes the lognormal parameters from mean and |
|
| 864 |
/// standard deviation. The return value can direcly be passed to |
|
| 865 |
/// lognormal(). |
|
| 866 |
std::pair<double,double> lognormalParamsFromMD(double mean, |
|
| 867 |
double std_dev) |
|
| 868 |
{
|
|
| 869 |
double fr=std_dev/mean; |
|
| 870 |
fr*=fr; |
|
| 871 |
double lg=std::log(1+fr); |
|
| 872 |
return std::pair<double,double>(std::log(mean)-lg/2.0,std::sqrt(lg)); |
|
| 873 |
} |
|
| 874 |
/// Lognormal distribution with given mean and standard deviation |
|
| 875 |
|
|
| 876 |
/// Lognormal distribution with given mean and standard deviation. |
|
| 877 |
/// |
|
| 878 |
double lognormalMD(double mean,double std_dev) |
|
| 879 |
{
|
|
| 880 |
return lognormal(lognormalParamsFromMD(mean,std_dev)); |
|
| 881 |
} |
|
| 882 |
|
|
| 843 | 883 |
/// Exponential distribution with given mean |
| 844 | 884 |
|
| 845 | 885 |
/// This function generates an exponential distribution random number |
| 846 | 886 |
/// with mean <tt>1/lambda</tt>. |
| 847 | 887 |
/// |
| 848 | 888 |
double exponential(double lambda=1.0) |
| 849 | 889 |
{
|
| 850 | 890 |
return -std::log(1.0-real<double>())/lambda; |
| 851 | 891 |
} |
| 852 | 892 |
|
| 853 | 893 |
/// Gamma distribution with given integer shape |
| 854 | 894 |
|
0 comments (0 inline)