Package jdistlib.math
Class MathFunctions
java.lang.Object
jdistlib.math.MathFunctions
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final doubleprotected static final double -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final double_expm1(double x) Alternative expm1 -- no difference from Java'sstatic final double_log1p(double x) Alternative log1p.static final doublealgdiv(double a, double b) ----------------------------------------------------------------------- COMPUTATION OF LN(GAMMA(B)/GAMMA(A+B)) WHEN B >= 8.static final doublealnrel(double a) ----------------------------------------------------------------------- Evaluation of the function ln(1 + a) -----------------------------------------------------------------------static final doubleapser(double a, double b, double x, double eps) static final doublebasym(double a, double b, double lambda, double eps, boolean log_p) static final doublebcorr(double a0, double b0) ----------------------------------------------------------------------- EVALUATION OF DEL(A0) + DEL(B0) - DEL(A0 + B0) WHERE LN(GAMMA(A)) = (A - 0.5)*LN(A) - A + 0.5*LN(2*PI) + DEL(A).static final doublebd0(double x, double np) static final doublebeta(double a, double b) This function returns the value of the beta function evaluated with arguments a and b.static final doublebetaln(double a0, double b0) ----------------------------------------------------------------------- Evaluation of the logarithm of the beta function ln(beta(a0,b0)) -----------------------------------------------------------------------static final doublebfrac(double a, double b, double x, double y, double lambda, double eps, boolean log_p) static final doublebgrat(double a, double b, double x, double y, double w, double eps, int[] ierr, boolean log_w) static final doublebpser(double a, double b, double x, double eps, boolean log_p) static final double[]bratio(double a, double b, double x, double y, boolean log_p) ----------------------------------------------------------------------- Evaluation of the Incomplete Beta function I_x(a,b) -------------------- It is assumed that a and b are nonnegative, and that x <= 1 and y = 1 - x.static final doublebrcmp1(int mu, double a, double b, double x, double y, boolean give_log) static final doublebrcomp(double a, double b, double x, double y, boolean log_p) static final doublebup(double a, double b, double x, double y, int n, double eps, boolean give_log) static final doublechebyshev_eval(double x, double[] a, int n) evaluate the n-term Chebyshev series "a" at "x".static final doublechoose(double n, double k) static final doublecospi(double x) static final voidebd0(double x, double mean, double[] result) Computes the deviance partx * log(x / mean) + mean - xas a high and low component.static final doubleerf__(double x) ----------------------------------------------------------------------- EVALUATION OF THE REAL ERROR FUNCTION -----------------------------------------------------------------------static final doubleerfc1(int ind, double x) ----------------------------------------------------------------------- EVALUATION OF THE COMPLEMENTARY ERROR FUNCTION ERFC1(IND,X) = ERFC(X) IF IND = 0 ERFC1(IND,X) = EXP(X*X)*ERFC(X) OTHERWISE -----------------------------------------------------------------------static final doubleesum(int mu, double x, boolean give_log) ----------------------------------------------------------------------- EVALUATION OF EXP(MU + X) -----------------------------------------------------------------------static final doubleexparg(int l) --------------------------------------------------------------------static final doublefpser(double a, double b, double x, double eps, boolean log_p) static final doublefrexp(double x, int[] i) Implementation of frexpstatic final doublegam1(double a) ------------------------------------------------------------------ COMPUTATION OF 1/GAMMA(A+1) - 1 FOR -0.5 <= A <= 1.5 ------------------------------------------------------------------static final doublegamln(double a) ----------------------------------------------------------------------- Evaluation of ln(gamma(a)) for positive a ----------------------------------------------------------------------- Written by Alfred H.static final doublegamln1(double a) ----------------------------------------------------------------------- EVALUATION OF LN(GAMMA(1 + A)) FOR -0.2 <= A <= 1.25 -----------------------------------------------------------------------static final doublegamma_cody(double x) ---------------------------------------------------------------------- This routine calculates the GAMMA function for a float argument X.static final doublegammafn(double x) static final double[]gammafn(double[] x) Batch call gamma functionstatic final intgcd(int m, int n) Find greatest common divisor of m and nstatic final doublegharmonic(int n) Calculate harmonic numberstatic final doublegharmonic(int n, double s) static final doublegharmonic(int n, double s, double logexponent) Calculate generalized harmonic numberstatic final doublegrat_r(double a, double x, double log_r, double eps) static final doublegsumln(double a, double b) ----------------------------------------------------------------------- EVALUATION OF THE FUNCTION LN(GAMMA(A + B)) FOR 1 <= A <= 2 AND 1 <= B <= 2 -----------------------------------------------------------------------static final booleanisFinite(double x) static final booleanisInfinite(double x) static final booleanisNonInt(double x) static final doublelbeta(double a, double b) static final doublelchoose(double n, double k) static final doubleldexp(double x, double ex) static final doubleldexp(double x, int p) Implementation of ldexpstatic final doublelgamma1p(double a) static final doublelgammacor(double x) static final doublelgammafn(double x) static final double[]lgammafn(double[] x) Batch call log gamma functionstatic final doublelgammafn_sign(double x, int[] sgn) static final doublelgharmonic(int n) static final doublelgharmonic(int n, double s) static final doublelgharmonic(int n, double s, double logexponent) Calculate the log of generalized harmonic numberstatic final doublelmvgammafn(double a, int p) Log of multivariate gamma function By: Roby Joehanesstatic final doublelog1pexp(double x) static final doublelog1pmx(double x) static final doublelog1px(double x) log1px takes a double and returns a double.static final doublelogspace_add(double logx, double logy) Compute the log of a sum from logs of terms, i.e., log (exp (logx) + exp (logy)) without causing overflows and without throwing away large handfuls of accuracy.static final doublelogspace_sub(double logx, double logy) Compute the log of a difference from logs of terms, i.e., log (exp (logx) - exp (logy)) without causing overflows and without throwing away large handfuls of accuracy.static final doublelogspace_sum(double[] logx) static final doublepd_lower_cf(double y, double d) static final doublepd_lower_series(double lambda, double y) static final doublepd_upper_series(double x, double y, boolean log_p) static final doublepow1p(double x, double y) Computes(1 + x)^ywithout discarding a smallx.static final doublepsi(double x) --------------------------------------------------------------------- Evaluation of the Digamma function psi(x) ----------- Psi(xx) is assigned the value 0 when the digamma function cannot be computed.static final doublerexpm1(double x) ----------------------------------------------------------------------- EVALUATION OF THE FUNCTION EXP(X) - 1 -----------------------------------------------------------------------static final doublerlog1(double x) ----------------------------------------------------------------------- Evaluation of the function x - ln(1 + x) -----------------------------------------------------------------------static final doubleround(double val, int places) Rounding to desired num placesstatic final floatround(float val, int places) static final doublesignif(double val, int places) Mimicking R's signifstatic final doublesinc(double x) Compute sinc(x) = sin(x)/x for x != 0.static final doublesinpi(double x) static final doublestirlerr(double n) static final doubletanpi(double x) static final doubletrunc(double x)
-
Field Details
-
bigx
protected static final double bigx- See Also:
-
scalefactor
protected static final double scalefactor- See Also:
-
-
Constructor Details
-
MathFunctions
public MathFunctions()
-
-
Method Details
-
lmvgammafn
public static final double lmvgammafn(double a, int p) Log of multivariate gamma function By: Roby Joehanes- Parameters:
a-p- the order (or dimension)- Returns:
- log multivariate gamma
-
trunc
public static final double trunc(double x) -
round
public static final double round(double val, int places) Rounding to desired num places- Parameters:
val-places-- Returns:
- rounded number
-
round
public static final float round(float val, int places) -
signif
public static final double signif(double val, int places) Mimicking R's signif- Parameters:
val-places-- Returns:
- rounded values
-
gcd
public static final int gcd(int m, int n) Find greatest common divisor of m and n- Parameters:
m-n-- Returns:
- GCD(m, n)
-
sinc
public static final double sinc(double x) Compute sinc(x) = sin(x)/x for x != 0. Return 1 when x == 0.- Parameters:
x-- Returns:
- sinc value
-
isFinite
public static final boolean isFinite(double x) -
isInfinite
public static final boolean isInfinite(double x) -
ldexp
public static final double ldexp(double x, double ex) -
chebyshev_eval
public static final double chebyshev_eval(double x, double[] a, int n) evaluate the n-term Chebyshev series "a" at "x".- Parameters:
x-a-n-- Returns:
- Chebyshev function result
-
lgammacor
public static final double lgammacor(double x) -
lgammafn_sign
public static final double lgammafn_sign(double x, int[] sgn) -
lgammafn
public static final double lgammafn(double x) -
lgammafn
public static final double[] lgammafn(double[] x) Batch call log gamma function- Parameters:
x-- Returns:
- an array of results
-
stirlerr
public static final double stirlerr(double n) -
gammafn
public static final double gammafn(double x) -
gammafn
public static final double[] gammafn(double[] x) Batch call gamma function- Parameters:
x-- Returns:
- an array of results
-
bd0
public static final double bd0(double x, double np) -
ebd0
public static final void ebd0(double x, double mean, double[] result) Computes the deviance partx * log(x / mean) + mean - xas a high and low component. Keeping the two components separate avoids losing the small remainder whenxandmeanare large.- Parameters:
x- non-negative observationmean- non-negative meanresult- receives the high component at index 0 and low component at index 1
-
pow1p
public static final double pow1p(double x, double y) Computes(1 + x)^ywithout discarding a smallx. -
lbeta
public static final double lbeta(double a, double b) -
log1pmx
public static final double log1pmx(double x) -
log1px
public static final double log1px(double x) log1px takes a double and returns a double. It is a Taylor series expansion of log(1+x). x is presumed to be < 1. As I have called it, x < .1, and so I know the algorithm will terminate quickly. The closer x is to 1, the slower this will be. (From AS 885) -
lgamma1p
public static final double lgamma1p(double a) -
logspace_add
public static final double logspace_add(double logx, double logy) Compute the log of a sum from logs of terms, i.e., log (exp (logx) + exp (logy)) without causing overflows and without throwing away large handfuls of accuracy. -
logspace_sub
public static final double logspace_sub(double logx, double logy) Compute the log of a difference from logs of terms, i.e., log (exp (logx) - exp (logy)) without causing overflows and without throwing away large handfuls of accuracy. -
logspace_sum
public static final double logspace_sum(double[] logx) -
bratio
public static final double[] bratio(double a, double b, double x, double y, boolean log_p) ----------------------------------------------------------------------- Evaluation of the Incomplete Beta function I_x(a,b) -------------------- It is assumed that a and b are nonnegative, and that x <= 1 and y = 1 - x. Bratio assigns w and w1 the values w = I_x(a,b) w1 = 1 - I_x(a,b) ierr is a variable that reports the status of the results. If no input errors are detected then ierr is set to 0 and w and w1 are computed. otherwise, if an error is detected, then w and w1 are assigned the value 0 and ierr is set to one of the following values ... ierr = 1 if a or b is negative ierr = 2 if a = b = 0 ierr = 3 if x < 0 or x > 1 ierr = 4 if y < 0 or y > 1 ierr = 5 if x + y != 1 ierr = 6 if x = a = 0 ierr = 7 if y = b = 0 ierr = 8 (not used currently) ierr = 9 NaN in a, b, x, or y ierr = 10 (not used currently) ierr = 11 bgrat() error code 1 [+ warning in bgrat()] ierr = 12 bgrat() error code 2 (no warning here) ierr = 13 bgrat() error code 3 (no warning here) ierr = 14 bgrat() error code 4 [+ WARNING in bgrat()] -------------------- Written by Alfred H. Morris, Jr. Naval Surface Warfare Center Dahlgren, Virginia Revised ... Nov 1991 ----------------------------------------------------------------------- -
fpser
public static final double fpser(double a, double b, double x, double eps, boolean log_p) -
apser
public static final double apser(double a, double b, double x, double eps) -
bpser
public static final double bpser(double a, double b, double x, double eps, boolean log_p) -
bup
public static final double bup(double a, double b, double x, double y, int n, double eps, boolean give_log) -
bfrac
public static final double bfrac(double a, double b, double x, double y, double lambda, double eps, boolean log_p) -
brcomp
public static final double brcomp(double a, double b, double x, double y, boolean log_p) -
brcmp1
public static final double brcmp1(int mu, double a, double b, double x, double y, boolean give_log) -
bgrat
public static final double bgrat(double a, double b, double x, double y, double w, double eps, int[] ierr, boolean log_w) -
grat_r
public static final double grat_r(double a, double x, double log_r, double eps) -
basym
public static final double basym(double a, double b, double lambda, double eps, boolean log_p) -
exparg
public static final double exparg(int l) --------------------------------------------------------------------IF L = 0 THEN EXPARG(L) = THE LARGEST POSITIVE W FOR WHICH EXP(W) CAN BE COMPUTED. IF L IS NONZERO THEN EXPARG(L) = THE LARGEST NEGATIVE W FOR WHICH THE COMPUTED VALUE OF EXP(W) IS NONZERO. NOTE... ONLY AN APPROXIMATE VALUE FOR EXPARG(L) IS NEEDED.-------------------------------------------------------------------- -
esum
public static final double esum(int mu, double x, boolean give_log) ----------------------------------------------------------------------- EVALUATION OF EXP(MU + X) ----------------------------------------------------------------------- -
rexpm1
public static final double rexpm1(double x) ----------------------------------------------------------------------- EVALUATION OF THE FUNCTION EXP(X) - 1 ----------------------------------------------------------------------- -
alnrel
public static final double alnrel(double a) ----------------------------------------------------------------------- Evaluation of the function ln(1 + a) ----------------------------------------------------------------------- -
rlog1
public static final double rlog1(double x) ----------------------------------------------------------------------- Evaluation of the function x - ln(1 + x) ----------------------------------------------------------------------- -
erf__
public static final double erf__(double x) ----------------------------------------------------------------------- EVALUATION OF THE REAL ERROR FUNCTION ----------------------------------------------------------------------- -
erfc1
public static final double erfc1(int ind, double x) ----------------------------------------------------------------------- EVALUATION OF THE COMPLEMENTARY ERROR FUNCTION ERFC1(IND,X) = ERFC(X) IF IND = 0 ERFC1(IND,X) = EXP(X*X)*ERFC(X) OTHERWISE ----------------------------------------------------------------------- -
gam1
public static final double gam1(double a) ------------------------------------------------------------------ COMPUTATION OF 1/GAMMA(A+1) - 1 FOR -0.5 <= A <= 1.5 ------------------------------------------------------------------ -
gamln1
public static final double gamln1(double a) ----------------------------------------------------------------------- EVALUATION OF LN(GAMMA(1 + A)) FOR -0.2 <= A <= 1.25 ----------------------------------------------------------------------- -
psi
public static final double psi(double x) --------------------------------------------------------------------- Evaluation of the Digamma function psi(x) ----------- Psi(xx) is assigned the value 0 when the digamma function cannot be computed. The main computation involves evaluation of rational Chebyshev approximations published in Math. Comp. 27, 123-127(1973) by Cody, Strecok and Thacher. --------------------------------------------------------------------- Psi was written at Argonne National Laboratory for the FUNPACK package of special function subroutines. Psi was modified by A.H. Morris (NSWC). --------------------------------------------------------------------- -
betaln
public static final double betaln(double a0, double b0) ----------------------------------------------------------------------- Evaluation of the logarithm of the beta function ln(beta(a0,b0)) ----------------------------------------------------------------------- -
gsumln
public static final double gsumln(double a, double b) ----------------------------------------------------------------------- EVALUATION OF THE FUNCTION LN(GAMMA(A + B)) FOR 1 <= A <= 2 AND 1 <= B <= 2 ----------------------------------------------------------------------- -
bcorr
public static final double bcorr(double a0, double b0) ----------------------------------------------------------------------- EVALUATION OF DEL(A0) + DEL(B0) - DEL(A0 + B0) WHERE LN(GAMMA(A)) = (A - 0.5)*LN(A) - A + 0.5*LN(2*PI) + DEL(A). IT IS ASSUMED THAT A0 >= 8 AND B0 >= 8. ----------------------------------------------------------------------- -
algdiv
public static final double algdiv(double a, double b) ----------------------------------------------------------------------- COMPUTATION OF LN(GAMMA(B)/GAMMA(A+B)) WHEN B >= 8. IN THIS ALGORITHM, DEL(X) IS THE FUNCTION DEFINED BY LN(GAMMA(X)) = (X - 0.5)*LN(X) - X + 0.5*LN(2*PI) + DEL(X). ----------------------------------------------------------------------- -
gamln
public static final double gamln(double a) ----------------------------------------------------------------------- Evaluation of ln(gamma(a)) for positive a ----------------------------------------------------------------------- Written by Alfred H. Morris Naval Surface Warfare Center Dahlgren, Virginia ----------------------------------------------------------------------- -
beta
public static final double beta(double a, double b) This function returns the value of the beta function evaluated with arguments a and b. NOTES This routine is a translation into C of a Fortran subroutine by W. Fullerton of Los Alamos Scientific Laboratory. Some modifications have been made so that the routines conform to the IEEE 754 standard. -
lchoose
public static final double lchoose(double n, double k) -
choose
public static final double choose(double n, double k) -
gamma_cody
public static final double gamma_cody(double x) ---------------------------------------------------------------------- This routine calculates the GAMMA function for a float argument X. Computation is based on an algorithm outlined in reference [1]. The program uses rational functions that approximate the GAMMA function to at least 20 significant decimal digits. Coefficients for the approximation over the interval (1,2) are unpublished. Those for the approximation for X >= 12 are from reference [2]. The accuracy achieved depends on the arithmetic system, the compiler, the intrinsic functions, and proper selection of the machine-dependent constants. Error returns The program returns the value XINF for singularities or when overflow would occur. The computation is believed to be free of underflow and overflow. Intrinsic functions required are: INT, DBLE, EXP, LOG, REAL, SIN References: [1] "An Overview of Software Development for Special Functions", W. J. Cody, Lecture Notes in Mathematics, 506, Numerical Analysis Dundee, 1975, G. A. Watson (ed.), Springer Verlag, Berlin, 1976. [2] Computer Approximations, Hart, Et. Al., Wiley and sons, New York, 1968. Latest modification: October 12, 1989 Authors: W. J. Cody and L. Stoltz Applied Mathematics Division Argonne National Laboratory Argonne, IL 60439 ---------------------------------------------------------------------- -
pd_upper_series
public static final double pd_upper_series(double x, double y, boolean log_p) -
pd_lower_cf
public static final double pd_lower_cf(double y, double d) -
pd_lower_series
public static final double pd_lower_series(double lambda, double y) -
_expm1
public static final double _expm1(double x) Alternative expm1 -- no difference from Java's- Parameters:
x-- Returns:
- expm1
-
_log1p
public static final double _log1p(double x) Alternative log1p. No difference from Java's.- Parameters:
x-- Returns:
- log1p
-
gharmonic
public static final double gharmonic(int n) Calculate harmonic number- Parameters:
n- must be positive- Returns:
- value
-
gharmonic
public static final double gharmonic(int n, double s) -
gharmonic
public static final double gharmonic(int n, double s, double logexponent) Calculate generalized harmonic number- Parameters:
n- must be positives-logexponent-- Returns:
- a value
-
lgharmonic
public static final double lgharmonic(int n) -
lgharmonic
public static final double lgharmonic(int n, double s) -
lgharmonic
public static final double lgharmonic(int n, double s, double logexponent) Calculate the log of generalized harmonic number- Parameters:
n- must be positives-logexponent-- Returns:
- a value
-
cospi
public static final double cospi(double x) -
sinpi
public static final double sinpi(double x) -
tanpi
public static final double tanpi(double x) -
frexp
public static final double frexp(double x, int[] i) Implementation of frexp- Parameters:
x-i- an array of 1 element- Returns:
- frexp
-
ldexp
public static final double ldexp(double x, int p) Implementation of ldexp- Parameters:
x-p-- Returns:
- ldexp
-
isNonInt
public static final boolean isNonInt(double x) -
log1pexp
public static final double log1pexp(double x)
-