gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
A better way of generating pareto distr, and swap its parameters. - Pareto distribution is now generated as a composition of a Gamma and an exponential one - Similarly to gamma() and weibull(), the shape parameter became the first one.
0 1 0
default
1 file changed with 3 insertions and 7 deletions:
↑ Collapse diff ↑
Show white space 48 line context
... ...
@@ -777,58 +777,54 @@
777 777
	  {
778 778
	    xi=1.0-std::log(V1);
779 779
	    nu=V0*std::exp(-xi);
780 780
	  }
781 781
      } while(nu>std::pow(xi,delta-1.0)*std::exp(-xi));
782 782
      return theta*(xi-gamma(int(std::floor(k))));
783 783
    }
784 784
    
785 785
    /// Weibull distribution
786 786

	
787 787
    /// This function generates a Weibull distribution random number.
788 788
    /// 
789 789
    ///\param k shape parameter (<tt>k>0</tt>)
790 790
    ///\param lambda scale parameter (<tt>lambda>0</tt>)
791 791
    ///
792 792
    double weibull(double k,double lambda)
793 793
    {
794 794
      return lambda*pow(-std::log(1.0-real<double>()),1.0/k);
795 795
    }  
796 796
      
797 797
    /// Pareto distribution
798 798

	
799 799
    /// This function generates a Pareto distribution random number.
800 800
    /// 
801
    ///\param k shape parameter (<tt>k>0</tt>)
801 802
    ///\param x_min location parameter (<tt>x_min>0</tt>)
802
    ///\param k shape parameter (<tt>k>0</tt>)
803 803
    ///
804
    ///\warning This function used inverse transform sampling, therefore may
805
    ///suffer from numerical unstability.
806
    ///
807
    ///\todo Implement a numerically stable method
808
    double pareto(double x_min,double k)
804
    double pareto(double k,double x_min)
809 805
    {
810
      return x_min*pow(1.0-real<double>(),1.0/k);
806
      return exponential(gamma(k,1.0/x_min));
811 807
    }  
812 808
      
813 809
    ///@}
814 810
    
815 811
    ///\name Two dimensional distributions
816 812
    ///
817 813

	
818 814
    ///@{
819 815
    
820 816
    /// Uniform distribution on the full unit circle.
821 817
    dim2::Point<double> disc() 
822 818
    {
823 819
      double V1,V2;
824 820
      do {
825 821
	V1=2*real<double>()-1;
826 822
	V2=2*real<double>()-1;
827 823
	
828 824
      } while(V1*V1+V2*V2>=1);
829 825
      return dim2::Point<double>(V1,V2);
830 826
    }
831 827
    /// A kind of two dimensional Gauss distribution
832 828

	
833 829
    /// This function provides a turning symmetric two-dimensional distribution.
834 830
    /// Both coordinates are of standard normal distribution, but they are not
0 comments (0 inline)