Changeset 378:80ec623f529f in lemon1.2
 Timestamp:
 11/11/08 11:25:57 (15 years ago)
 Branch:
 default
 Parents:
 376:4b2382fd80ef (diff), 377:c4aa9f097ef1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.  Phase:
 public
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

lemon/random.h
r340 r378 689 689 } 690 690 691 /// \brief Returns a random real number the range [0, b)692 ///693 /// It returns a random real number from the range [0, b).694 template <typename Number>695 Number real(Number b) {696 return real<Number>() * b;697 }698 699 /// \brief Returns a random real number from the range [a, b)700 ///701 /// It returns a random real number from the range [a, b).702 template <typename Number>703 Number real(Number a, Number b) {704 return real<Number>() * (b  a) + a;705 }706 707 691 /// \brief Returns a random real number from the range [0, 1) 708 692 /// … … 715 699 /// 716 700 /// It returns a random real number from the range [0, b). 717 template <typename Number> 718 Number operator()(Number b) { 719 return real<Number>() * b; 701 double operator()(double b) { 702 return real<double>() * b; 720 703 } 721 704 … … 723 706 /// 724 707 /// It returns a random real number from the range [a, b). 725 template <typename Number> 726 Number operator()(Number a, Number b) { 727 return real<Number>() * (b  a) + a; 708 double operator()(double a, double b) { 709 return real<double>() * (b  a) + a; 728 710 } 729 711 
lemon/random.h
r377 r378 541 541 /// @{ 542 542 543 ///\name Initialization544 ///545 /// @{546 547 543 /// \brief Default constructor 548 544 /// … … 693 689 } 694 690 695 /// @}696 697 ///\name Uniform distributions698 ///699 /// @{700 701 691 /// \brief Returns a random real number from the range [0, 1) 702 692 /// … … 753 743 return _random_bits::IntConversion<Number, Word>::convert(core); 754 744 } 755 756 /// @}757 745 758 746 unsigned int uinteger() { … … 789 777 ///\name Nonuniform distributions 790 778 /// 791 792 779 ///@{ 793 780 794 /// \brief Returns a random bool 781 /// \brief Returns a random bool with given probability of true result. 795 782 /// 796 783 /// It returns a random bool with given probability of true result. … … 799 786 } 800 787 801 /// Standard Gaussdistribution802 803 /// Standard Gaussdistribution.788 /// Standard normal (Gauss) distribution 789 790 /// Standard normal (Gauss) distribution. 804 791 /// \note The Cartesian form of the BoxMuller 805 792 /// transformation is used to generate a random normal distribution. … … 814 801 return std::sqrt(2*std::log(S)/S)*V1; 815 802 } 816 /// Gaussdistribution with given mean and standard deviation817 818 /// Gaussdistribution with given mean and standard deviation.803 /// Normal (Gauss) distribution with given mean and standard deviation 804 805 /// Normal (Gauss) distribution with given mean and standard deviation. 819 806 /// \sa gauss() 820 807 double gauss(double mean,double std_dev) 821 808 { 822 809 return gauss()*std_dev+mean; 810 } 811 812 /// Lognormal distribution 813 814 /// Lognormal distribution. The parameters are the mean and the standard 815 /// deviation of <tt>exp(X)</tt>. 816 /// 817 double lognormal(double n_mean,double n_std_dev) 818 { 819 return std::exp(gauss(n_mean,n_std_dev)); 820 } 821 /// Lognormal distribution 822 823 /// Lognormal distribution. The parameter is an <tt>std::pair</tt> of 824 /// the mean and the standard deviation of <tt>exp(X)</tt>. 825 /// 826 double lognormal(const std::pair<double,double> ¶ms) 827 { 828 return std::exp(gauss(params.first,params.second)); 829 } 830 /// Compute the lognormal parameters from mean and standard deviation 831 832 /// This function computes the lognormal parameters from mean and 833 /// standard deviation. The return value can direcly be passed to 834 /// lognormal(). 835 std::pair<double,double> lognormalParamsFromMD(double mean, 836 double std_dev) 837 { 838 double fr=std_dev/mean; 839 fr*=fr; 840 double lg=std::log(1+fr); 841 return std::pair<double,double>(std::log(mean)lg/2.0,std::sqrt(lg)); 842 } 843 /// Lognormal distribution with given mean and standard deviation 844 845 /// Lognormal distribution with given mean and standard deviation. 846 /// 847 double lognormalMD(double mean,double std_dev) 848 { 849 return lognormal(lognormalParamsFromMD(mean,std_dev)); 823 850 } 824 851 … … 926 953 ///\name Two dimensional distributions 927 954 /// 928 929 955 ///@{ 930 956 … … 943 969 return dim2::Point<double>(V1,V2); 944 970 } 945 /// A kind of two dimensional Gaussdistribution971 /// A kind of two dimensional normal (Gauss) distribution 946 972 947 973 /// This function provides a turning symmetric twodimensional distribution.
Note: See TracChangeset
for help on using the changeset viewer.