2 #include <boost/math/quadrature/gauss.hpp> 14 for (
unsigned int i = 0;i < n;++i)
22 const unsigned int maxIter,
const double tol)
26 bool stopLoop =
false;
27 unsigned int counter = 2;
29 std::vector <double> aVals(2);
31 aVals[1] = 1.0 + x * a / b;
33 while (counter < maxIter && !stopLoop)
35 double r = (a + counter - 1.0) / (counter * (b + counter - 1.0));
36 double newVal = aVals[1] + (aVals[1] - aVals[0]) * r * x;
38 if ((counter != 2) && (std::abs(newVal - resVal) < tol * std::abs(resVal)))
55 const unsigned int maxIter,
const double tol)
59 bool stopLoop =
false;
60 unsigned int counter = 0;
61 double factorial_counter = 1;
63 while (counter < maxIter && !stopLoop)
66 factorial_counter *= counter;
68 double tmpVal = resVal;
70 double poch_a, poch_b;
83 resVal += poch_a * poch_b * std::pow(std::abs(x),-1.0 * counter) / factorial_counter;
85 if ((counter != 1) && (std::abs(resVal - tmpVal) < tol * std::abs(tmpVal)))
90 resVal *= std::exp(x) * std::pow(x,(
double)(a-b)) / std::tgamma(a);
92 resVal *= std::pow(-x,-1.0 * a) / std::tgamma(b-a);
94 resVal *= std::tgamma(b);
105 double resVal = boost::math::quadrature::gauss<double, 15>::integrate(integrand, 0.0, 1.0);
106 resVal *= std::tgamma(b) / std::tgamma(a) / std::tgamma(b - a);
113 const unsigned int maxIter,
const double tol)
115 if ((a == 0) || (x == 0))
126 resVal = std::exp(x + std::log(resVal));
131 double rFactor = std::abs(x * a / b);
141 throw itk::ExceptionObject(__FILE__, __LINE__,
"Invalid inputs for Kummer function using method 2",ITK_LOCATION);
144 double logResVal = x + std::log(std::abs(tmpVal));
145 double factor = (0.0 < tmpVal) - (0.0 > tmpVal);
146 return factor * std::exp(logResVal);
155 const unsigned int maxIter,
const double tol)
157 if ((a == 0) || (x == 0))
168 resVal = std::exp(- x + std::log(resVal));
173 double rFactor = std::abs(x * a / b);
175 return std::exp(-x + std::log(
KummerMethod1(x, a, b, maxIter, tol)));
183 throw itk::ExceptionObject(__FILE__, __LINE__,
"Invalid inputs for Kummer function using method 2",ITK_LOCATION);
188 return std::exp(-x + std::log(
KummerMethod2(x, a, b, maxIter, tol)));
void SetBValue(double val)
double GetScaledKummerFunctionValue(const double &x, const double &a, const double &b, const unsigned int maxIter, const double tol)
Computes the confluent hypergeometric function 1F1 also known as the Kummer function M...
double KummerIntegrandMethod(const double &x, const double &a, const double &b)
According to Muller, K. E. (2001) ‘Computing the confluent hypergeometric function, M (a, b, x)’, Numerische Mathematik, pp. 179–196. Method with integral if b > a > 0.
double PochHammer(const double &x, const unsigned int n)
double KummerMethod1(const double &x, const double &a, const double &b, const unsigned int maxIter, const double tol)
According to Muller, K. E. (2001) ‘Computing the confluent hypergeometric function, M (a, b, x)’, Numerische Mathematik, pp. 179–196. Method 1.C, p.5.
void SetAValue(double val)
double KummerMethod2(const double &x, const double &a, const double &b, const unsigned int maxIter, const double tol)
According to Muller, K. E. (2001) ‘Computing the confluent hypergeometric function, M (a, b, x)’, Numerische Mathematik, pp. 179–196. Method 2, p.6.
double GetKummerFunctionValue(const double &x, const double &a, const double &b, const unsigned int maxIter, const double tol)
Computes the confluent hypergeometric function 1F1 also known as the Kummer function M...
void SetXValue(double val)