20 #include "itkNumericTraits.h"
21 #include "vnl/vnl_math.h"
22 #include "vnl/vnl_erf.h"
24 extern "C" double dbetai_(
double *x,
double *pin,
double *qin);
25 extern "C" double dgamma_(
double *x);
28 namespace Statistics {
34 m_Parameters[0] = 1.0;
41 bool modified =
false;
43 if (m_Parameters.GetSize() > 0)
45 if (m_Parameters[0] != static_cast<double>(dof) )
51 if (m_Parameters.GetSize() != 1)
56 m_Parameters[0] =
static_cast<double>(dof);
68 if (m_Parameters.GetSize() == 1)
70 return static_cast<long>(m_Parameters[0]);
75 ::itk::OStringStream message;
76 message <<
"itk::ERROR: " << this->GetNameOfClass()
77 <<
"(" <<
this <<
"): "
78 <<
"Invalid number of parameters to describe distribution.";
89 ::PDF(
double x,
long degreesOfFreedom)
91 double dof =
static_cast<double>(degreesOfFreedom);
92 double dofplusoneon2 = 0.5*(dof+1.0);
93 double dofon2 = 0.5*dof;
97 / (vcl_sqrt(dof*vnl_math::pi) * vcl_pow(1.0 + ((x*x)/dof), dofplusoneon2));
113 ::itk::OStringStream message;
114 message <<
"itk::ERROR: "
116 <<
"Invalid number of parameters to describe distribution.";
127 ::CDF(
double x,
long degreesOfFreedom)
158 dof =
static_cast<double>(degreesOfFreedom);
159 bx = dof / (dof + (x*x));
165 return 1.0 - 0.5 *
dbetai_(&bx, &pin, &qin);
169 return 0.5 *
dbetai_(&bx, &pin, &qin);
184 ::itk::OStringStream message;
185 message <<
"itk::ERROR: "
187 <<
"Invalid number of parameters to describe distribution.";
203 return itk::NumericTraits<double>::NonpositiveMin();
207 return itk::NumericTraits<double>::max();
211 double dof, dof2, dof3, dof4;
212 double gaussX, gaussX3, gaussX5, gaussX7, gaussX9;
215 dof =
static_cast<double>(degreesOfFreedom);
221 gaussX3 = vcl_pow(gaussX, 3.0);
222 gaussX5 = vcl_pow(gaussX, 5.0);
223 gaussX7 = vcl_pow(gaussX, 7.0);
224 gaussX9 = vcl_pow(gaussX, 9.0);
227 + (gaussX3 + gaussX) / (4.0 * dof)
228 + (5.0*gaussX5 + 16.0*gaussX3 + 3*gaussX) / (96.0 * dof2)
229 + (3.0*gaussX7 + 19.0*gaussX5 + 17.0*gaussX3 - 15.0*gaussX) / (384.0*dof3)
234 - 945.0*gaussX) / (92160.0 * dof4);
261 for (
unsigned int newt = 0; newt < 3; ++newt)
283 ::itk::OStringStream message;
284 message <<
"itk::ERROR: "
286 <<
"Invalid number of parameters to describe distribution.";
300 if (m_Parameters.GetSize() == 1)
307 ::itk::OStringStream message;
308 message <<
"itk::ERROR: " << this->GetNameOfClass()
309 <<
"(" <<
this <<
"): "
310 <<
"Invalid number of parameters to describe distribution.";
329 ::itk::OStringStream message;
330 message <<
"itk::ERROR: " << this->GetNameOfClass()
331 <<
"(" <<
this <<
"): "
332 <<
"Invalid number of parameters to describe distribution.";
352 if (m_Parameters.GetSize() == 1)
359 ::itk::OStringStream message;
360 message <<
"itk::ERROR: " << this->GetNameOfClass()
361 <<
"(" <<
this <<
"): "
362 <<
"Invalid number of parameters to describe distribution.";
381 ::itk::OStringStream message;
382 message <<
"itk::ERROR: " << this->GetNameOfClass()
383 <<
"(" <<
this <<
"): "
384 <<
"Invalid number of parameters to describe distribution.";
404 if (m_Parameters.GetSize() == 1)
411 ::itk::OStringStream message;
412 message <<
"itk::ERROR: " << this->GetNameOfClass()
413 <<
"(" <<
this <<
"): "
414 <<
"Invalid number of parameters to describe distribution.";
433 ::itk::OStringStream message;
434 message <<
"itk::ERROR: " << this->GetNameOfClass()
435 <<
"(" <<
this <<
"): "
436 <<
"Invalid number of parameters to describe distribution.";
455 if (m_Parameters.GetSize() == 1)
457 if (m_Parameters[0] > 2)
465 ::itk::OStringStream message;
466 message <<
"itk::ERROR: " << this->GetNameOfClass()
467 <<
"(" <<
this <<
"): "
468 <<
"Invalid number of parameters to describe distribution.";
488 if (m_Parameters.GetSize() == 1)
490 if (m_Parameters[0] > 2)
492 double dof =
static_cast<double>(m_Parameters[0]);
494 return dof / (dof - 2.0);
498 return NumericTraits<double>::quiet_NaN();
504 ::itk::OStringStream message;
505 message <<
"itk::ERROR: " << this->GetNameOfClass()
506 <<
"(" <<
this <<
"): "
507 <<
"Invalid number of parameters to describe distribution.";
514 return NumericTraits<double>::quiet_NaN();
521 Superclass::PrintSelf(os,indent);
523 if (m_Parameters.GetSize() > 0)
525 os << indent <<
"Degrees of freedom: "
526 <<
static_cast<long>(m_Parameters[0]) << std::endl;
530 os << indent <<
"Degrees of freedom: (unknown)"