Changeset 2374:b59a17034ffa in lemon-0.x for lemon
- Timestamp:
- 02/20/07 14:01:22 (17 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3189
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/random.h
r2372 r2374 70 70 #include <cmath> 71 71 72 #include <lemon/dim2.h> 72 73 ///\ingroup misc 73 74 ///\file … … 743 744 double exponential(double lambda=1.0) 744 745 { 745 return - log(real<double>())/lambda;746 return -std::log(real<double>())/lambda; 746 747 } 747 748 748 749 ///@} 749 750 751 ///\name Two dimensional distributions 752 /// 753 754 ///@{ 755 756 /// Uniform distribution on the full unit circle. 757 dim2::Point<double> ball2() 758 { 759 double V1,V2; 760 do { 761 V1=2*real<double>()-1; 762 V2=2*real<double>()-1; 763 764 } while(V1*V1+V2*V2>=1); 765 return dim2::Point<double>(V1,V2); 766 } 767 /// A kind of two dimensional Gauss distribution 768 769 /// This function provides a turning symmetric two-dimensional distribution. 770 /// Both coordinates are of standard normal distribution, but they are not 771 /// independent. 772 /// 773 /// \note The coordinates are the two random variables provided by 774 /// the Box-Muller method. 775 dim2::Point<double> gauss2() 776 { 777 double V1,V2,S; 778 do { 779 V1=2*real<double>()-1; 780 V2=2*real<double>()-1; 781 S=V1*V1+V2*V2; 782 } while(S>=1); 783 double W=std::sqrt(-2*std::log(S)/S); 784 return dim2::Point<double>(W*V1,W*V2); 785 } 786 /// A kind of two dimensional exponential distribution 787 788 /// This function provides a turning symmetric two-dimensional distribution. 789 /// The x-coordinate is of conditionally exponential distribution 790 /// with the condition that x is positive and y=0. If x is negative and 791 /// y=0 then, -x is of exponential distribution. The same is true for the 792 /// y-coordinate. 793 dim2::Point<double> exponential2() 794 { 795 double V1,V2,S; 796 do { 797 V1=2*real<double>()-1; 798 V2=2*real<double>()-1; 799 S=V1*V1+V2*V2; 800 } while(S>=1); 801 double W=-std::log(S)/S; 802 return dim2::Point<double>(W*V1,W*V2); 803 } 804 805 ///@} 750 806 }; 751 807
Note: See TracChangeset
for help on using the changeset viewer.