Changes in lemon/random.h [517:afd134142111:564:2b6d5d22bb23] in lemon
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/random.h
r517 r564 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). … … 531 531 /// @{ 532 532 533 ///\name Initialization534 ///535 /// @{536 537 533 /// \brief Default constructor 538 534 /// … … 681 677 } 682 678 683 /// @}684 685 ///\name Uniform distributions686 ///687 /// @{688 689 679 /// \brief Returns a random real number from the range [0, 1) 690 680 /// … … 741 731 return _random_bits::IntConversion<Number, Word>::convert(core); 742 732 } 743 744 /// @}745 733 746 734 unsigned int uinteger() { … … 777 765 ///\name Non-uniform distributions 778 766 /// 779 780 767 ///@{ 781 768 782 /// \brief Returns a random bool 769 /// \brief Returns a random bool with given probability of true result. 783 770 /// 784 771 /// It returns a random bool with given probability of true result. … … 787 774 } 788 775 789 /// Standard Gaussdistribution790 791 /// Standard Gaussdistribution.776 /// Standard normal (Gauss) distribution 777 778 /// Standard normal (Gauss) distribution. 792 779 /// \note The Cartesian form of the Box-Muller 793 780 /// transformation is used to generate a random normal distribution. … … 802 789 return std::sqrt(-2*std::log(S)/S)*V1; 803 790 } 804 /// Gaussdistribution with given mean and standard deviation805 806 /// Gaussdistribution with given mean and standard deviation.791 /// Normal (Gauss) distribution with given mean and standard deviation 792 793 /// Normal (Gauss) distribution with given mean and standard deviation. 807 794 /// \sa gauss() 808 795 double gauss(double mean,double std_dev) 809 796 { 810 797 return gauss()*std_dev+mean; 798 } 799 800 /// Lognormal distribution 801 802 /// Lognormal distribution. The parameters are the mean and the standard 803 /// deviation of <tt>exp(X)</tt>. 804 /// 805 double lognormal(double n_mean,double n_std_dev) 806 { 807 return std::exp(gauss(n_mean,n_std_dev)); 808 } 809 /// Lognormal distribution 810 811 /// Lognormal distribution. The parameter is an <tt>std::pair</tt> of 812 /// the mean and the standard deviation of <tt>exp(X)</tt>. 813 /// 814 double lognormal(const std::pair<double,double> ¶ms) 815 { 816 return std::exp(gauss(params.first,params.second)); 817 } 818 /// Compute the lognormal parameters from mean and standard deviation 819 820 /// This function computes the lognormal parameters from mean and 821 /// standard deviation. The return value can direcly be passed to 822 /// lognormal(). 823 std::pair<double,double> lognormalParamsFromMD(double mean, 824 double std_dev) 825 { 826 double fr=std_dev/mean; 827 fr*=fr; 828 double lg=std::log(1+fr); 829 return std::pair<double,double>(std::log(mean)-lg/2.0,std::sqrt(lg)); 830 } 831 /// Lognormal distribution with given mean and standard deviation 832 833 /// Lognormal distribution with given mean and standard deviation. 834 /// 835 double lognormalMD(double mean,double std_dev) 836 { 837 return lognormal(lognormalParamsFromMD(mean,std_dev)); 811 838 } 812 839 … … 914 941 ///\name Two dimensional distributions 915 942 /// 916 917 943 ///@{ 918 944 … … 931 957 return dim2::Point<double>(V1,V2); 932 958 } 933 /// A kind of two dimensional Gaussdistribution959 /// A kind of two dimensional normal (Gauss) distribution 934 960 935 961 /// This function provides a turning symmetric two-dimensional distribution.
Note: See TracChangeset
for help on using the changeset viewer.