00001 // This is core/vnl/vnl_gamma.h 00002 #ifndef vnl_gamma_h_ 00003 #define vnl_gamma_h_ 00004 //: 00005 // \file 00006 // \brief Complete and incomplete gamma function approximations 00007 // \author Tim Cootes 00008 00009 #include <vcl_cmath.h> 00010 00011 //: Approximate log of gamma function 00012 // Uses 6 parameter Lanczos approximation as described by Toth 00013 // (http://www.rskey.org/gamma.htm) 00014 // Accurate to about one part in 3e-11. 00015 double vnl_log_gamma(double x); 00016 00017 //: Approximate gamma function 00018 // Uses 6 parameter Lanczos approximation as described by Toth 00019 // (http://www.rskey.org/gamma.htm) 00020 // Accurate to about one part in 3e-11. 00021 inline double vnl_gamma(double x) { return vcl_exp(vnl_log_gamma(x)); } 00022 00023 //: Normalised Incomplete gamma function, P(a,x) 00024 // $P(a,x)=\frac{1}{\Gamma(a)}\int_0^x e^{-t}t^{a-1}dt$ 00025 // Note the order of parameters - this is the normal maths order. 00026 // MATLAB uses gammainc(x,a), ie the other way around 00027 double vnl_gamma_p(double a, double x); 00028 00029 //:Normalised Incomplete gamma function, Q(a,x) 00030 // $Q(a,x)=\frac{1}{\Gamma(a)}\int_x^{\infty}e^{-t}t^{a-1}dt$ 00031 double vnl_gamma_q(double a, double x); 00032 00033 //: P(chi<chi2) 00034 // Calculates the probability that a value generated 00035 // at random from a chi-square distribution with given 00036 // degrees of freedom is less than the value chi2 00037 // \param n_dof Number of degrees of freedom 00038 // \param chi2 Value of chi-squared 00039 inline double vnl_cum_prob_chi2(int n_dof, double chi2) 00040 { 00041 return vnl_gamma_p( n_dof*0.5 , chi2*0.5 ); 00042 } 00043 //: approximate digamma function, dLog[gamma[z]]/dz 00044 // Analytic derivative of the Lanczos approximation. Error < 10^-11 1<z<20. 00045 double vnl_digamma(double x); 00046 00047 #endif // vnl_gamma_h_