20 #include "itkNumericTraits.h"
21 #include "vnl/vnl_math.h"
22 #include "vnl/vnl_erf.h"
24 extern "C" double dgami_(
double *a,
double *x);
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 dofon2 = 0.5*dof;
97 pdf = vcl_exp(-0.5*x) * vcl_pow(x, dofon2 - 1.0)
98 / (vcl_pow(2.0, dofon2) *
dgamma_(&dofon2));
116 ::itk::OStringStream message;
117 message <<
"itk::ERROR: "
118 <<
"ChiSquareDistribution: "
119 <<
"Invalid number of parameters to describe distribution.";
130 ::CDF(
double x,
long degreesOfFreedom)
140 double dofon2 = 0.5*degreesOfFreedom;
158 ::itk::OStringStream message;
159 message <<
"itk::ERROR: "
160 <<
"ChiSquareDistribution: "
161 <<
"Invalid number of parameters to describe distribution.";
176 return itk::NumericTraits<double>::Zero;
180 return itk::NumericTraits<double>::max();
188 dof =
static_cast<double>(degreesOfFreedom);
191 double f = 2.0 / (9.0*dof);
192 x = dof*vcl_pow(1.0 - f + nx*vcl_sqrt(f), 3.0);
226 for (
unsigned int newt = 0; newt < 10; ++newt)
248 ::itk::OStringStream message;
249 message <<
"itk::ERROR: "
250 <<
"ChiSquareDistribution: "
251 <<
"Invalid number of parameters to describe distribution.";
264 if (m_Parameters.GetSize() == 1)
271 ::itk::OStringStream message;
272 message <<
"itk::ERROR: " << this->GetNameOfClass()
273 <<
"(" <<
this <<
"): "
274 <<
"Invalid number of parameters to describe distribution.";
293 ::itk::OStringStream message;
294 message <<
"itk::ERROR: " << this->GetNameOfClass()
295 <<
"(" <<
this <<
"): "
296 <<
"Invalid number of parameters to describe distribution.";
316 if (m_Parameters.GetSize() == 1)
323 ::itk::OStringStream message;
324 message <<
"itk::ERROR: " << this->GetNameOfClass()
325 <<
"(" <<
this <<
"): "
326 <<
"Invalid number of parameters to describe distribution.";
345 ::itk::OStringStream message;
346 message <<
"itk::ERROR: " << this->GetNameOfClass()
347 <<
"(" <<
this <<
"): "
348 <<
"Invalid number of parameters to describe distribution.";
368 if (m_Parameters.GetSize() == 1)
371 static_cast<long>(m_Parameters[0]));
376 ::itk::OStringStream message;
377 message <<
"itk::ERROR: " << this->GetNameOfClass()
378 <<
"(" <<
this <<
"): "
379 <<
"Invalid number of parameters to describe distribution.";
398 ::itk::OStringStream message;
399 message <<
"itk::ERROR: " << this->GetNameOfClass()
400 <<
"(" <<
this <<
"): "
401 <<
"Invalid number of parameters to describe distribution.";
421 if (m_Parameters.GetSize() == 1)
423 return m_Parameters[0];
428 ::itk::OStringStream message;
429 message <<
"itk::ERROR: " << this->GetNameOfClass()
430 <<
"(" <<
this <<
"): "
431 <<
"Invalid number of parameters to describe distribution.";
437 return NumericTraits<double>::quiet_NaN();
444 if (m_Parameters.GetSize() == 1)
446 return 2.0*m_Parameters[0];
451 ::itk::OStringStream message;
452 message <<
"itk::ERROR: " << this->GetNameOfClass()
453 <<
"(" <<
this <<
"): "
454 <<
"Invalid number of parameters to describe distribution.";
460 return NumericTraits<double>::quiet_NaN();
467 Superclass::PrintSelf(os,indent);
469 if (m_Parameters.GetSize() > 0)
471 os << indent <<
"Degrees of freedom: "
472 <<
static_cast<long>(m_Parameters[0]) << std::endl;
476 os << indent <<
"Degrees of freedom: (unknown)"