00001 // This is core/vnl/algo/vnl_chi_squared.h 00002 #ifndef vnl_chi_squared_h_ 00003 #define vnl_chi_squared_h_ 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \brief Name space for various (mostly templated) chi-squared distribution functions. 00010 // \author Rupert Curwen, GE CRD 00011 // \date August 18th, 1998 00012 // 00013 // \verbatim 00014 // Modifications 00015 // 26/03/2001 dac (Manchester) tidied up documentation 00016 // 24 Mar 2010 Peter Vanroose made vnl_chi_squared_cumulative() templated 00017 // \endverbatim 00018 00019 //: Compute cumulative distribution function value for chi-squared distribution. 00020 // This subroutine computes the cumulative distribution function 00021 // value for the chi-squared distribution with integer degrees of 00022 // freedom parameter = dof. This distribution is defined for all 00023 // non-negative chisq. Thus if a random variable x is drawn from a 00024 // chi-squared distribution with d degrees of freedom, then 00025 // $P(x < X) =$ vnl_chi_squared_cumulative(X,d). 00026 // Internally, T=double is used. 00027 template <class T> 00028 double vnl_chi_squared_cumulative(T chisq, long dof); 00029 00030 //------------------------------------------------------------ 00031 00032 //: Name space for various chi-squared distribution functions. 00033 // 00034 // A[] and B[] are (pointers to) arrays containing histograms. 00035 // If the 'normalize' parameter is true, each histogram will 00036 // be implicitly normalized (so as to sum to 1) before the 00037 // statistic is calculated : 00038 // 00039 // $a[i] = A[i] / \sum_j A[j]$ 00040 // 00041 // $b[i] = B[i] / \sum_j B[j]$ 00042 // 00043 // *DO NOT* add scale factors to these functions or you will break 00044 // the code written by those who read the documentation. fsm. 00045 // 00046 // $\displaystyle \sum_i \frac{ (a[i] - b[i])^2 }{ a[i] } $ 00047 // 00048 00049 template <class T> 00050 double vnl_chi_squared_statistic_1 (T const *A, T const *B, 00051 int n, bool normalize); 00052 00053 //: 00054 // $\displaystyle \sum_i \frac{ (a[i] - b[i])^2 }{ b[i] } $ 00055 template <class T> 00056 double vnl_chi_squared_statistic_2 (T const *A, T const *B, 00057 int n, bool normalize); 00058 00059 //: 00060 // $\displaystyle \sum_i \frac{ (a[i] - b[i])^2 }{ a[i] + b[i] } $ 00061 template <class T> 00062 double vnl_chi_squared_statistic_12(T const *A, T const *B, 00063 int n, bool normalize); 00064 00065 #define VNL_CHI_SQUARED_INSTANTIATE(T) \ 00066 extern "please include vnl/algo/vnl_chi_squared.txx first" 00067 00068 #endif // vnl_chi_squared_h_