Changes in lemon/random.h [280:e7f8647ce760:340:0badf3bb38c2] in lemon-1.2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/random.h
r280 r340 541 541 /// @{ 542 542 543 ///\name Initialization544 ///545 /// @{546 547 543 /// \brief Default constructor 548 544 /// … … 709 705 } 710 706 711 /// @}712 713 ///\name Uniform distributions714 ///715 /// @{716 717 707 /// \brief Returns a random real number from the range [0, 1) 718 708 /// … … 771 761 return _random_bits::IntConversion<Number, Word>::convert(core); 772 762 } 773 774 /// @}775 763 776 764 unsigned int uinteger() { … … 807 795 ///\name Non-uniform distributions 808 796 /// 809 810 797 ///@{ 811 798 812 /// \brief Returns a random bool 799 /// \brief Returns a random bool with given probability of true result. 813 800 /// 814 801 /// It returns a random bool with given probability of true result. … … 817 804 } 818 805 819 /// Standard Gaussdistribution820 821 /// Standard Gaussdistribution.806 /// Standard normal (Gauss) distribution 807 808 /// Standard normal (Gauss) distribution. 822 809 /// \note The Cartesian form of the Box-Muller 823 810 /// transformation is used to generate a random normal distribution. … … 832 819 return std::sqrt(-2*std::log(S)/S)*V1; 833 820 } 834 /// Gaussdistribution with given mean and standard deviation835 836 /// Gaussdistribution with given mean and standard deviation.821 /// Normal (Gauss) distribution with given mean and standard deviation 822 823 /// Normal (Gauss) distribution with given mean and standard deviation. 837 824 /// \sa gauss() 838 825 double gauss(double mean,double std_dev) 839 826 { 840 827 return gauss()*std_dev+mean; 828 } 829 830 /// Lognormal distribution 831 832 /// Lognormal distribution. The parameters are the mean and the standard 833 /// deviation of <tt>exp(X)</tt>. 834 /// 835 double lognormal(double n_mean,double n_std_dev) 836 { 837 return std::exp(gauss(n_mean,n_std_dev)); 838 } 839 /// Lognormal distribution 840 841 /// Lognormal distribution. The parameter is an <tt>std::pair</tt> of 842 /// the mean and the standard deviation of <tt>exp(X)</tt>. 843 /// 844 double lognormal(const std::pair<double,double> ¶ms) 845 { 846 return std::exp(gauss(params.first,params.second)); 847 } 848 /// Compute the lognormal parameters from mean and standard deviation 849 850 /// This function computes the lognormal parameters from mean and 851 /// standard deviation. The return value can direcly be passed to 852 /// lognormal(). 853 std::pair<double,double> lognormalParamsFromMD(double mean, 854 double std_dev) 855 { 856 double fr=std_dev/mean; 857 fr*=fr; 858 double lg=std::log(1+fr); 859 return std::pair<double,double>(std::log(mean)-lg/2.0,std::sqrt(lg)); 860 } 861 /// Lognormal distribution with given mean and standard deviation 862 863 /// Lognormal distribution with given mean and standard deviation. 864 /// 865 double lognormalMD(double mean,double std_dev) 866 { 867 return lognormal(lognormalParamsFromMD(mean,std_dev)); 841 868 } 842 869 … … 944 971 ///\name Two dimensional distributions 945 972 /// 946 947 973 ///@{ 948 974 … … 961 987 return dim2::Point<double>(V1,V2); 962 988 } 963 /// A kind of two dimensional Gaussdistribution989 /// A kind of two dimensional normal (Gauss) distribution 964 990 965 991 /// This function provides a turning symmetric two-dimensional distribution.
Note: See TracChangeset
for help on using the changeset viewer.