Class SpecialFunctions
Added in 2.4.0 as the home of these functions from
util.MathUtils (removed in 3.0). The code was moved, not
rewritten, so every value is bit-identical to 2.3.
- Since:
- 2.4.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic doublelogGamma(double x) Natural log of the gamma function (Lanczos, |relative error| < 2e-10).static doublelogNormPdf(double x) Natural log of the standard normal density, finite for any finite x.static doublenormCdf(double x) Standard normal CDF to full double precision.static doublenormInv(double p) Inverse standard normal CDF: Acklam's rational seed (|error| < 1.15e-9) refined by one Halley step onnormCdf(double), which brings it to double precision apart from the last few bits.static doublenormPdf(double x) Standard normal density.static doubleregularizedIncompleteBeta(double a, double b, double x) Regularized incomplete beta function I_x(a, b) via the continued fraction (modified Lentz), switching to the symmetryI_x(a,b) = 1 − I_{1−x}(b,a)where the fraction converges fastest.static doubletCdf(double t, double df) Student-t CDF withdfdegrees of freedom — exact via the regularized incomplete beta (P(T ≤ t) = 1 − ½·I_{ν/(ν+t²)}(ν/2, ½)for t ≥ 0), no normal approximation: the tails are precisely where a t distribution and its moment-matched normal disagree most.
-
Method Details
-
normInv
public static double normInv(double p) Inverse standard normal CDF: Acklam's rational seed (|error| < 1.15e-9) refined by one Halley step onnormCdf(double), which brings it to double precision apart from the last few bits. -
logNormPdf
public static double logNormPdf(double x) Natural log of the standard normal density, finite for any finite x. -
normPdf
public static double normPdf(double x) Standard normal density. -
normCdf
public static double normCdf(double x) Standard normal CDF to full double precision.W. J. Cody's rational Chebyshev approximations (Cody 1969, "Rational Chebyshev approximations for the error function", Math. Comp. 23, 631-637; coefficients from his SPECFUN routine ANORM, 1993, the set R's
pnormalso uses). Three regions: |x| <= 0.67449, |x| <= sqrt(32) and the asymptotic tail. The Gaussian factor is split as exp(-xs^2/2) exp(-(x-xs)(x+xs)/2) with xs = |x| truncated to a multiple of 1/16, so the exponent carries no rounding error and the lower tail keeps relative accuracy (about 1e-15) down to x = -37.5. Further out the value is subnormal and then 0. NaN in gives NaN out. -
logGamma
public static double logGamma(double x) Natural log of the gamma function (Lanczos, |relative error| < 2e-10). -
regularizedIncompleteBeta
public static double regularizedIncompleteBeta(double a, double b, double x) Regularized incomplete beta function I_x(a, b) via the continued fraction (modified Lentz), switching to the symmetryI_x(a,b) = 1 − I_{1−x}(b,a)where the fraction converges fastest. Accurate to ~1e-13 across (0, 1). -
tCdf
public static double tCdf(double t, double df) Student-t CDF withdfdegrees of freedom — exact via the regularized incomplete beta (P(T ≤ t) = 1 − ½·I_{ν/(ν+t²)}(ν/2, ½)for t ≥ 0), no normal approximation: the tails are precisely where a t distribution and its moment-matched normal disagree most.
-