00001 #pragma ident "$Id: Chi2Distribution.cpp 1389 2008-09-04 17:06:43Z ckiesch $"
00002
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "Chi2Distribution.hpp"
00033
00034
00035 using namespace std;
00036
00037 namespace gpstk
00038 {
00039
00040
00041
00042
00043
00044
00045 double Chi2Distribution::pdf(double x)
00046 {
00047
00048 if( x <= 0.0 )
00049 {
00050 return (0.0);
00051 }
00052
00053
00054 double khalf( static_cast<double>(ndf) / 2.0 );
00055
00056
00057 double t1( -0.69314718055994529 * khalf );
00058 double t2( -lngamma( khalf ) );
00059 double t3( ( khalf - 1.0 ) * log(x) );
00060 double t4( - x / 2.0 );
00061
00062 return ( exp( t1 + t2 + t3 + t4 ) );
00063
00064 }
00065
00066
00067
00068
00069
00070
00071
00072 double Chi2Distribution::cdf(double x)
00073 {
00074
00075
00076 if( x <= 0.0 )
00077 {
00078 return (0.0);
00079 }
00080
00081
00082 double khalf( static_cast<double>(ndf) / 2.0 );
00083
00084 return ( gammaP( khalf, (x/2.0) ) );
00085
00086 }
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 Chi2Distribution& Chi2Distribution::setNDF(int n)
00097 throw(InvalidParameter)
00098 {
00099
00100 if( n == 0 )
00101 {
00102 InvalidParameter e( "Invalid value for NDF." );
00103 GPSTK_THROW(e);
00104 }
00105
00106 if( n < 0 )
00107 {
00108 ndf = -n;
00109 }
00110 else
00111 {
00112 ndf = n;
00113 }
00114
00115 return (*this);
00116
00117 }
00118
00119
00120
00121 }