Package com.irurueta.statistics
Class Gamma
java.lang.Object
com.irurueta.statistics.GaussLegendreQuadrature
com.irurueta.statistics.Gamma
Defines the gamma function, which is a function that extends the concept of
factorials from natural to real and complex numbers (except zero and negative
integer values).
If argument of gamma function is natural and positive, then it relates to
factorials as: Gamma(n) = (n - 1)!
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
Defines when to switch to quadrature method.private static final double[]
Coefficients for computation of logarithm of gamma function.private static final int
Default number of maximum iterations to compute incomplete gamma functions.private static final double
Epsilon for double.private static boolean
Indicates whether factorials have been initialized and stored in a table for future faster access.private static double[]
Table where factorials are cached for faster future access.private static final double
Constant related to machine precision.private double
Logarithm of gamma function.private static boolean
Indicates whether logarithm of factorials has been initialized and stored in a table for future faster access.private static double[]
Table where logarithms of factorials are cached for faster future access.protected static final int
Maximum number of logarithm of factorials cached.private static final int
Maximum value supported to estimate factorials for.Fields inherited from class com.irurueta.statistics.GaussLegendreQuadrature
N_GAU, W, Y
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic double
beta
(double z, double w) Returns the value of the beta function B(z, w) (aka Euler integral).static double
bico
(int n, int k) Returns the binomial coefficient (n k) as a floating-point number, which indicates the discrete probability distribution of getting exactly k successes in n trials.static double
factln
(int n) Returns logarithm of n!static double
factrl
(int n) Returns the factorial of n (n!) as a floating-point number.static double
gammln
(double xx) Returns the value ln(gamma(xx)) for xx > 0.double
gammp
(double a, double x) Returns the incomplete gamma function P(a,x).private double
gammpapprox
(double a, double x, int psig) Incomplete gamma by quadrature.double
gammq
(double a, double x) Returns the incomplete gamma function Q(a, x) = 1 - P(a, x).private double
gcf
(double a, double x) Returns the incomplete gamma function Q(a, x) evaluated by its continued fraction representation.private double
gcf
(double a, double x, int maxIterations) Returns the incomplete gamma function Q(a, x) evaluated by its continued fraction representation.double
getGln()
Returns logarithm of gamma function.private double
gser
(double a, double x) Returns the incomplete gamma function P(a, x) evaluated by its series representation.private double
gser
(double a, double x, int maxIterations) Returns the incomplete gamma function P(a, x) evaluated by its series representation.double
invgammp
(double p, double a) Inverse function on x of P(a, x).
-
Field Details
-
MAX_CACHED_LOG_FACTORIALS
protected static final int MAX_CACHED_LOG_FACTORIALSMaximum number of logarithm of factorials cached.- See Also:
-
ASWITCH
private static final int ASWITCHDefines when to switch to quadrature method.- See Also:
-
EPS
private static final double EPSEpsilon for double. It is related to machine precision. -
FPMIN
private static final double FPMINConstant related to machine precision. -
MAX_FACTORIALS
private static final int MAX_FACTORIALSMaximum value supported to estimate factorials for.- See Also:
-
DEFAULT_MAX_ITERATIONS
private static final int DEFAULT_MAX_ITERATIONSDefault number of maximum iterations to compute incomplete gamma functions.- See Also:
-
COF
private static final double[] COFCoefficients for computation of logarithm of gamma function. -
factorialsInitialized
private static boolean factorialsInitializedIndicates whether factorials have been initialized and stored in a table for future faster access. -
factorialsTable
private static double[] factorialsTableTable where factorials are cached for faster future access. -
logarithmOfFactorialsInitialized
private static boolean logarithmOfFactorialsInitializedIndicates whether logarithm of factorials has been initialized and stored in a table for future faster access. -
logarithmOfFactorialsTable
private static double[] logarithmOfFactorialsTableTable where logarithms of factorials are cached for faster future access. -
gln
private double glnLogarithm of gamma function.
-
-
Constructor Details
-
Gamma
public Gamma()
-
-
Method Details
-
getGln
public double getGln()Returns logarithm of gamma function.- Returns:
- logarithm of gamma function.
-
gammln
public static double gammln(double xx) Returns the value ln(gamma(xx)) for xx > 0.- Parameters:
xx
- a value.- Returns:
- the logarithm of gamma function.
- Throws:
IllegalArgumentException
- if value is negative.
-
factrl
public static double factrl(int n) Returns the factorial of n (n!) as a floating-point number. Factorials up to 22! have exact double precision representations. Factorials from 23! to 170! are approximate due to IEEE double representation. Factorials equal or greater than 170! are out of range.- Parameters:
n
- value to compute factorial for.- Returns:
- factorial of n, (i.e. n!).
- Throws:
IllegalArgumentException
- if provided value generates a factorial that cannot be represented using double precision.
-
factln
public static double factln(int n) Returns logarithm of n!- Parameters:
n
- value to compute logarithm of factorial for.- Returns:
- logarithm of factorial.
- Throws:
IllegalArgumentException
- if provided value is negative.
-
bico
public static double bico(int n, int k) Returns the binomial coefficient (n k) as a floating-point number, which indicates the discrete probability distribution of getting exactly k successes in n trials.- Parameters:
n
- number of trials.k
- number of successes.- Returns:
- binomial value.
- Throws:
IllegalArgumentException
- if either n or k are negative or if k is greater than n.
-
beta
public static double beta(double z, double w) Returns the value of the beta function B(z, w) (aka Euler integral).- Parameters:
z
- a parameter.w
- a parameter.- Returns:
- value of beta function.
- Throws:
IllegalArgumentException
- if either z or w are negative.
-
gammp
Returns the incomplete gamma function P(a,x).- Parameters:
a
- a parameter.x
- x parameter.- Returns:
- value of incomplete gamma function.
- Throws:
IllegalArgumentException
- if provided values are invalid.MaxIterationsExceededException
- if convergence cannot be reached.
-
gammq
Returns the incomplete gamma function Q(a, x) = 1 - P(a, x).- Parameters:
a
- a parameter.x
- x parameter.- Returns:
- value of incomplete gamma function.
- Throws:
IllegalArgumentException
- if provided values are invalid.MaxIterationsExceededException
- if convergence cannot be reached.
-
gser
Returns the incomplete gamma function P(a, x) evaluated by its series representation.- Parameters:
a
- a parameter to obtain its gamma logarithm.x
- x parameter.- Returns:
- incomplete gamma function.
- Throws:
MaxIterationsExceededException
- if maximum number of iterations is exceeded.
-
gser
Returns the incomplete gamma function P(a, x) evaluated by its series representation.- Parameters:
a
- a parameter to obtain its gamma logarithm.x
- x parameter.maxIterations
- maximum number of iterations.- Returns:
- incomplete gamma function.
- Throws:
MaxIterationsExceededException
- if maximum number of iterations is exceeded.
-
gcf
Returns the incomplete gamma function Q(a, x) evaluated by its continued fraction representation.- Parameters:
a
- a parameter to obtain its gamma logarithm.x
- x parameter.- Returns:
- incomplete gamma function.
- Throws:
MaxIterationsExceededException
- if maximum number of iterations is exceeded.
-
gcf
Returns the incomplete gamma function Q(a, x) evaluated by its continued fraction representation.- Parameters:
a
- a parameter to obtain its gamma logarithm.x
- x parameter.maxIterations
- maximum number of iterations.- Returns:
- incomplete gamma function.
- Throws:
MaxIterationsExceededException
- if maximum number of iterations is exceeded.
-
gammpapprox
private double gammpapprox(double a, double x, int psig) Incomplete gamma by quadrature. Returns P(a, x) or Q(a, x), when psig is 1 or 0 respectively.- Parameters:
a
- a parameter.x
- x parameter.psig
- a flag.- Returns:
- incomplete gamma by quadrature.
-
invgammp
Inverse function on x of P(a, x). Returns x such that P(a,x) = p for an argument p between 0 and 1.- Parameters:
p
- argument p.a
- a parameter.- Returns:
- inverse value.
- Throws:
IllegalArgumentException
- if arguments are invalid.MaxIterationsExceededException
- if maximum number of iterations is exceeded.
-