Changeset 2483:bf6d7b624d5c in lemon0.x for lemon/random.h
 Timestamp:
 10/01/07 20:57:21 (13 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@3322
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

lemon/random.h
r2391 r2483 749 749 } 750 750 751 double gamma(int k) 752 { 753 double s = 0; 754 for(int i=0;i<k;i++) s=std::log(1.0real<double>()); 755 return s; 756 } 757 758 /// Gamma distribution with given shape and scale parameter 759 760 /// This function generates a gamma distribution random number. 761 /// 762 ///\param k shape parameter (<tt>k>0</tt>) 763 ///\param theta scale parameter 764 /// 765 double gamma(double k,double theta=1.0) 766 { 767 double xi,nu; 768 const double delta = kstd::floor(k); 769 const double v0=M_E/(M_Edelta); 770 do { 771 double V0=1.0real<double>(); 772 double V1=1.0real<double>(); 773 double V2=1.0real<double>(); 774 if(V2<=v0) 775 { 776 xi=std::pow(V1,1.0/delta); 777 nu=V0*std::pow(xi,delta1.0); 778 } 779 else 780 { 781 xi=1.0std::log(V1); 782 nu=V0*std::exp(xi); 783 } 784 } while(nu>std::pow(xi,delta1.0)*std::exp(xi)); 785 return theta*(xigamma(int(std::floor(k)))); 786 } 787 788 751 789 ///@} 752 790
Note: See TracChangeset
for help on using the changeset viewer.