List of usage examples for org.apache.commons.math.special Gamma regularizedGammaP
public static double regularizedGammaP(double a, double x) throws MathException
From source file:geogebra.util.MyMath.java
final public static double gammaIncomplete(double a, double x, Kernel kernel) { try {//from w w w . j ava 2s . co m // see http://mathworld.wolfram.com/RegularizedGammaFunction.html // http://en.wikipedia.org/wiki/Incomplete_gamma_function#Regularized_Gamma_functions_and_Poisson_random_variables return Gamma.regularizedGammaP(a, x) * gamma(a, kernel); } catch (MathException e) { return Double.NaN; } }
From source file:geogebra.util.MyMath.java
final public static double gammaIncompleteRegularized(double a, double x) { try {/*from www. j a va2s . c o m*/ return Gamma.regularizedGammaP(a, x); } catch (MathException e) { return Double.NaN; } }
From source file:com.opengamma.analytics.math.statistics.distribution.NonCentralChiSquaredDistribution.java
/** * {@inheritDoc}/* w w w . java2s . c om*/ */ @Override public double getCDF(final Double x) { Validate.notNull(x, "x"); if (x < 0) { return 0.0; } if ((_dofOverTwo + _lambdaOverTwo) > 1000) { return getFraserApproxCDF(x); } double regGammaStart = 0; final double halfX = x / 2.0; final double logX = Math.log(halfX); try { regGammaStart = Gamma.regularizedGammaP(_dofOverTwo + _k, halfX); } catch (final org.apache.commons.math.MathException ex) { throw new MathException(ex); } double sum = _pStart * regGammaStart; double oldSum = Double.NEGATIVE_INFINITY; double p = _pStart; double regGamma = regGammaStart; double temp; int i = _k; // first add terms below _k while (i > 0 && Math.abs(sum - oldSum) / sum > _eps) { i--; p *= (i + 1) / _lambdaOverTwo; temp = (_dofOverTwo + i) * logX - halfX - Gamma.logGamma(_dofOverTwo + i + 1); regGamma += Math.exp(temp); oldSum = sum; sum += p * regGamma; } p = _pStart; regGamma = regGammaStart; oldSum = Double.NEGATIVE_INFINITY; i = _k; while (Math.abs(sum - oldSum) / sum > _eps) { i++; p *= _lambdaOverTwo / i; temp = (_dofOverTwo + i - 1) * logX - halfX - Gamma.logGamma(_dofOverTwo + i); regGamma -= Math.exp(temp); oldSum = sum; sum += p * regGamma; } return sum; }