Changes in lemon/random.h [280:e7f8647ce760:440:88ed40ad0d4f] in lemon-1.2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/random.h
r280 r440 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-200 85 * Copyright (C) 2003-2009 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 541 541 /// @{ 542 542 543 ///\name Initialization544 ///545 /// @{546 547 543 /// \brief Default constructor 548 544 /// … … 693 689 } 694 690 695 /// \brief Returns a random real number the range [0, b)696 ///697 /// It returns a random real number from the range [0, b).698 template <typename Number>699 Number real(Number b) {700 return real<Number>() * b;701 }702 703 /// \brief Returns a random real number from the range [a, b)704 ///705 /// It returns a random real number from the range [a, b).706 template <typename Number>707 Number real(Number a, Number b) {708 return real<Number>() * (b - a) + a;709 }710 711 /// @}712 713 ///\name Uniform distributions714 ///715 /// @{716 717 691 /// \brief Returns a random real number from the range [0, 1) 718 692 /// … … 725 699 /// 726 700 /// It returns a random real number from the range [0, b). 727 template <typename Number> 728 Number operator()(Number b) { 729 return real<Number>() * b; 701 double operator()(double b) { 702 return real<double>() * b; 730 703 } 731 704 … … 733 706 /// 734 707 /// It returns a random real number from the range [a, b). 735 template <typename Number> 736 Number operator()(Number a, Number b) { 737 return real<Number>() * (b - a) + a; 708 double operator()(double a, double b) { 709 return real<double>() * (b - a) + a; 738 710 } 739 711 … … 771 743 return _random_bits::IntConversion<Number, Word>::convert(core); 772 744 } 773 774 /// @}775 745 776 746 unsigned int uinteger() { … … 807 777 ///\name Non-uniform distributions 808 778 /// 809 810 779 ///@{ 811 780 812 /// \brief Returns a random bool 781 /// \brief Returns a random bool with given probability of true result. 813 782 /// 814 783 /// It returns a random bool with given probability of true result. … … 817 786 } 818 787 819 /// Standard Gaussdistribution820 821 /// Standard Gaussdistribution.788 /// Standard normal (Gauss) distribution 789 790 /// Standard normal (Gauss) distribution. 822 791 /// \note The Cartesian form of the Box-Muller 823 792 /// transformation is used to generate a random normal distribution. … … 832 801 return std::sqrt(-2*std::log(S)/S)*V1; 833 802 } 834 /// Gaussdistribution with given mean and standard deviation835 836 /// 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. 837 806 /// \sa gauss() 838 807 double gauss(double mean,double std_dev) 839 808 { 840 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)); 841 850 } 842 851 … … 944 953 ///\name Two dimensional distributions 945 954 /// 946 947 955 ///@{ 948 956 … … 961 969 return dim2::Point<double>(V1,V2); 962 970 } 963 /// A kind of two dimensional Gaussdistribution971 /// A kind of two dimensional normal (Gauss) distribution 964 972 965 973 /// This function provides a turning symmetric two-dimensional distribution.
Note: See TracChangeset
for help on using the changeset viewer.