00001 #pragma ident "$Id: StudentDistribution.cpp 1409 2008-09-24 16:56:22Z architest $"
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 "StudentDistribution.hpp"
00033
00034
00035 using namespace std;
00036
00037 namespace gpstk
00038 {
00039
00040
00041
00042
00043
00044
00045 double StudentDistribution::pdf(double x)
00046 {
00047
00048
00049 if( ndf == 1 )
00050 {
00051 return ( 1.0 / ( PI * ( 1.0 + x*x ) ) );
00052 }
00053
00054
00055
00056 if( ndf == 2 )
00057 {
00058 double temp( 2.0 + x*x );
00059 return ( 1.0 / ( std::sqrt( temp * temp * temp ) ) );
00060 }
00061
00062 double nu( static_cast<double>(ndf) );
00063
00064
00065 double t1( 0.5*nu );
00066 double t2( t1 + 0.5 );
00067 double t3( std::log( std::sqrt(nu*PI) ) );
00068
00069 return ( std::exp( lngamma(t2) - t2 * std::log(1.0 + x*x/nu)
00070 - t3 - lngamma(t1) ) );
00071
00072 }
00073
00074
00075
00076
00077
00078
00079
00080 double StudentDistribution::cdf(double x)
00081 {
00082
00083
00084 if( ndf == 1 )
00085 {
00086 return ( 0.5 + ( std::atan(x) / PI ) );
00087 }
00088
00089
00090 if( ndf == 2 )
00091 {
00092 return ( 0.5 * ( 1.0 + x / std::sqrt( 2.0 + x*x ) ) );
00093 }
00094
00095
00096 double nu( static_cast<double>(ndf) );
00097
00098
00099 double t1( 0.5*nu );
00100 double t2( std::sqrt(x*x+nu) );
00101 double t3( 0.5 * ( 1.0 + ( x / t2 ) ) );
00102
00103 return ( regIncompleteBeta(t3, t1, t1) );
00104
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 StudentDistribution& StudentDistribution::setNDF(int n)
00116 throw(InvalidParameter)
00117 {
00118
00119 if( n == 0 )
00120 {
00121 InvalidParameter e( "Invalid value for NDF." );
00122 GPSTK_THROW(e);
00123 }
00124
00125 if( n < 0 )
00126 {
00127 ndf = -n;
00128 }
00129 else
00130 {
00131 ndf = n;
00132 }
00133
00134 return (*this);
00135
00136 }
00137
00138
00139
00140 }