vnl_gamma.h
Go to the documentation of this file.
1 // This is core/vnl/vnl_gamma.h
2 #ifndef vnl_gamma_h_
3 #define vnl_gamma_h_
4 //:
5 // \file
6 // \brief Complete and incomplete gamma function approximations
7 // \author Tim Cootes
8 
9 #include <cmath>
10 #ifdef _MSC_VER
11 # include <vcl_msvc_warnings.h>
12 #endif
13 #include "vnl/vnl_export.h"
14 
15 //: Approximate log of gamma function
16 // Uses 6 parameter Lanczos approximation as described by Toth
17 // (http://www.rskey.org/gamma.htm)
18 // Accurate to about one part in 3e-11.
19 VNL_EXPORT double vnl_log_gamma(double x);
20 
21 //: Approximate gamma function
22 // Uses 6 parameter Lanczos approximation as described by Toth
23 // (http://www.rskey.org/gamma.htm)
24 // Accurate to about one part in 3e-11.
25 inline double vnl_gamma(double x) { return std::exp(vnl_log_gamma(x)); }
26 
27 //: Normalised Incomplete gamma function, P(a,x)
28 // $P(a,x)=\frac{1}{\Gamma(a)}\int_0^x e^{-t}t^{a-1}dt$
29 // Note the order of parameters - this is the normal maths order.
30 // MATLAB uses gammainc(x,a), ie the other way around
31 VNL_EXPORT double vnl_gamma_p(double a, double x);
32 
33 //:Normalised Incomplete gamma function, Q(a,x)
34 // $Q(a,x)=\frac{1}{\Gamma(a)}\int_x^{\infty}e^{-t}t^{a-1}dt$
35 VNL_EXPORT double vnl_gamma_q(double a, double x);
36 
37 //: P(chi<chi2)
38 // Calculates the probability that a value generated
39 // at random from a chi-square distribution with given
40 // degrees of freedom is less than the value chi2
41 // \param n_dof Number of degrees of freedom
42 // \param chi2 Value of chi-squared
43 inline double vnl_cum_prob_chi2(int n_dof, double chi2)
44 {
45  return vnl_gamma_p( n_dof*0.5 , chi2*0.5 );
46 }
47 //: approximate digamma function, dLog[gamma[z]]/dz
48 // Analytic derivative of the Lanczos approximation. Error < 10^-11 1<z<20.
49 VNL_EXPORT double vnl_digamma(double x);
50 
51 #endif // vnl_gamma_h_
VNL_EXPORT double vnl_digamma(double x)
approximate digamma function, dLog[gamma[z]]/dz.
Definition: vnl_gamma.cxx:114
VNL_EXPORT double vnl_gamma_p(double a, double x)
Normalised Incomplete gamma function, P(a,x).
Definition: vnl_gamma.cxx:92
double vnl_gamma(double x)
Approximate gamma function.
Definition: vnl_gamma.h:25
VNL_EXPORT double vnl_log_gamma(double x)
Approximate log of gamma function.
Definition: vnl_gamma.cxx:18
double vnl_cum_prob_chi2(int n_dof, double chi2)
P(chi<chi2).
Definition: vnl_gamma.h:43
VNL_EXPORT double vnl_gamma_q(double a, double x)
Normalised Incomplete gamma function, Q(a,x).
Definition: vnl_gamma.cxx:103