# HG changeset patch
# User Peter Kovacs <kpeter@inf.elte.hu>
# Date 1225190621 -3600
# Node ID 0293cb1b9e9cc7d0a1f0dc1ef95a09ee07c732f5
# Parent 2593e163e407403990ba8f4323f684190a625a62
Add normal() as an alias for gauss() + doc improvements
diff --git a/lemon/random.h b/lemon/random.h
a
|
b
|
|
540 | 540 | /// |
541 | 541 | /// @{ |
542 | 542 | |
543 | | ///\name Initialization |
544 | | /// |
545 | | /// @{ |
546 | | |
547 | 543 | /// \brief Default constructor |
548 | 544 | /// |
549 | 545 | /// Constructor with constant seeding. |
… |
… |
|
708 | 704 | return real<Number>() * (b - a) + a; |
709 | 705 | } |
710 | 706 | |
711 | | /// @} |
712 | | |
713 | | ///\name Uniform distributions |
714 | | /// |
715 | | /// @{ |
716 | | |
717 | 707 | /// \brief Returns a random real number from the range [0, 1) |
718 | 708 | /// |
719 | 709 | /// It returns a random double from the range [0, 1). |
… |
… |
|
771 | 761 | return _random_bits::IntConversion<Number, Word>::convert(core); |
772 | 762 | } |
773 | 763 | |
774 | | /// @} |
775 | | |
776 | 764 | unsigned int uinteger() { |
777 | 765 | return uinteger<unsigned int>(); |
778 | 766 | } |
… |
… |
|
806 | 794 | |
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. |
815 | 802 | bool boolean(double p) { |
816 | 803 | return operator()() < p; |
817 | 804 | } |
818 | 805 | |
819 | | /// Standard Gauss distribution |
| 806 | /// Standard normal (Gauss) distribution |
820 | 807 | |
821 | | /// Standard Gauss distribution. |
| 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. |
824 | | double gauss() |
| 811 | double normal() |
825 | 812 | { |
826 | 813 | double V1,V2,S; |
827 | 814 | do { |
… |
… |
|
831 | 818 | } while(S>=1); |
832 | 819 | return std::sqrt(-2*std::log(S)/S)*V1; |
833 | 820 | } |
834 | | /// Gauss distribution with given mean and standard deviation |
| 821 | /// Normal (Gauss) distribution with given mean and standard deviation |
835 | 822 | |
836 | | /// Gauss distribution with given mean and standard deviation. |
837 | | /// \sa gauss() |
| 823 | /// Normal (Gauss) distribution with given mean and standard deviation. |
| 824 | /// \sa normal() |
| 825 | double normal(double mean,double std_dev) |
| 826 | { |
| 827 | return normal()*std_dev+mean; |
| 828 | } |
| 829 | |
| 830 | /// Standard normal (Gauss) distribution |
| 831 | |
| 832 | /// Standard normal (Gauss) distribution. |
| 833 | /// |
| 834 | /// It is an alias for \ref normal(). |
| 835 | double gauss() |
| 836 | { |
| 837 | return normal(); |
| 838 | } |
| 839 | /// Normal (Gauss) distribution with given mean and standard deviation |
| 840 | |
| 841 | /// Normal (Gauss) distribution with given mean and standard deviation. |
| 842 | /// |
| 843 | /// It is an alias for \ref normal(double, double). |
838 | 844 | double gauss(double mean,double std_dev) |
839 | 845 | { |
840 | | return gauss()*std_dev+mean; |
| 846 | return normal(mean,std_dev); |
841 | 847 | } |
842 | 848 | |
843 | 849 | /// Lognormal distribution |
… |
… |
|
864 | 870 | /// standard deviation. The return value can direcly be passed to |
865 | 871 | /// lognormal(). |
866 | 872 | std::pair<double,double> lognormalParamsFromMD(double mean, |
867 | | double std_dev) |
| 873 | double std_dev) |
868 | 874 | { |
869 | 875 | double fr=std_dev/mean; |
870 | 876 | fr*=fr; |
… |
… |
|
872 | 878 | return std::pair<double,double>(std::log(mean)-lg/2.0,std::sqrt(lg)); |
873 | 879 | } |
874 | 880 | /// Lognormal distribution with given mean and standard deviation |
875 | | |
| 881 | |
876 | 882 | /// Lognormal distribution with given mean and standard deviation. |
877 | 883 | /// |
878 | 884 | double lognormalMD(double mean,double std_dev) |
879 | 885 | { |
880 | 886 | return lognormal(lognormalParamsFromMD(mean,std_dev)); |
881 | 887 | } |
882 | | |
| 888 | |
883 | 889 | /// Exponential distribution with given mean |
884 | 890 | |
885 | 891 | /// This function generates an exponential distribution random number |
… |
… |
|
983 | 989 | |
984 | 990 | ///\name Two dimensional distributions |
985 | 991 | /// |
986 | | |
987 | 992 | ///@{ |
988 | 993 | |
989 | 994 | /// Uniform distribution on the full unit circle |
… |
… |
|
1000 | 1005 | } while(V1*V1+V2*V2>=1); |
1001 | 1006 | return dim2::Point<double>(V1,V2); |
1002 | 1007 | } |
1003 | | /// A kind of two dimensional Gauss distribution |
| 1008 | /// A kind of two dimensional normal (Gauss) distribution |
1004 | 1009 | |
1005 | 1010 | /// This function provides a turning symmetric two-dimensional distribution. |
1006 | 1011 | /// Both coordinates are of standard normal distribution, but they are not |
… |
… |
|
1008 | 1013 | /// |
1009 | 1014 | /// \note The coordinates are the two random variables provided by |
1010 | 1015 | /// the Box-Muller method. |
1011 | | dim2::Point<double> gauss2() |
| 1016 | dim2::Point<double> normal2() |
1012 | 1017 | { |
1013 | 1018 | double V1,V2,S; |
1014 | 1019 | do { |
… |
… |
|
1019 | 1024 | double W=std::sqrt(-2*std::log(S)/S); |
1020 | 1025 | return dim2::Point<double>(W*V1,W*V2); |
1021 | 1026 | } |
| 1027 | /// A kind of two dimensional normal (Gauss) distribution |
| 1028 | |
| 1029 | /// A kind of two dimensional normal (Gauss) distribution. |
| 1030 | /// |
| 1031 | /// It is an alias for \ref normal2(). |
| 1032 | dim2::Point<double> gauss2() |
| 1033 | { |
| 1034 | return normal2(); |
| 1035 | } |
| 1036 | |
1022 | 1037 | /// A kind of two dimensional exponential distribution |
1023 | 1038 | |
1024 | 1039 | /// This function provides a turning symmetric two-dimensional distribution. |