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