public class GammaDistribution extends AbstractDistribution
Modifier and Type | Class and Description |
---|---|
static class |
GammaDistribution.Parameterizer
Parameterization class
TODO: allow alternate parameterization, with alpha+beta?
|
Modifier and Type | Field and Description |
---|---|
static double |
EULERS_CONST
Euler–Mascheroni constant
|
private double |
k
Alpha == k
|
(package private) static double[] |
LANCZOS
LANCZOS-Coefficients for Gamma approximation.
|
(package private) static int |
MAX_ITERATIONS
Maximum number of iterations for regularizedGammaP.
|
(package private) static double |
NUM_PRECISION
Numerical precision to use (data type dependent!)
|
private double |
theta
Theta == 1 / Beta
|
random
Constructor and Description |
---|
GammaDistribution(double k,
double theta)
Constructor for Gamma distribution.
|
GammaDistribution(double k,
double theta,
Random random)
Constructor for Gamma distribution.
|
GammaDistribution(double k,
double theta,
RandomFactory random)
Constructor for Gamma distribution.
|
Modifier and Type | Method and Description |
---|---|
double |
cdf(double val)
Return the cumulative density function at the given value.
|
static double |
cdf(double val,
double k,
double theta)
The CDF, static version.
|
protected static double |
chisquaredProbitApproximation(double p,
double nu,
double g)
Approximate probit for chi squared distribution
Based on first half of algorithm AS 91
Reference:
Algorithm AS 91: The percentage points of the $\chi^2$ distribution
D.J. |
static double |
digamma(double x)
Compute the Psi / Digamma function
Reference:
J.
|
static double |
gamma(double x)
Compute the regular Gamma function.
|
protected static double |
gammaQuantileNewtonRefinement(double logpt,
double k,
double theta,
int maxit,
double x)
Refinement of ChiSquared probit using Newton iterations.
|
double |
getK() |
double |
getTheta() |
static double |
logcdf(double val,
double k,
double theta)
The log CDF, static version.
|
static double |
logGamma(double x)
Compute logGamma.
|
static double |
logpdf(double x,
double k,
double theta)
Gamma distribution PDF (with 0.0 for x < 0)
|
static double |
logregularizedGammaP(double a,
double x)
Returns the regularized gamma function log P(a, x).
|
double |
nextRandom()
Generate a new random value
|
static double |
nextRandom(double k,
double theta,
Random random)
Generate a random value with the generators parameters.
|
double |
pdf(double val)
Return the density of an existing value
|
static double |
pdf(double x,
double k,
double theta)
Gamma distribution PDF (with 0.0 for x < 0)
|
double |
quantile(double val)
Quantile aka probit (for normal) aka inverse CDF (invcdf, cdf^-1) function.
|
static double |
quantile(double p,
double k,
double theta)
Compute probit (inverse cdf) for Gamma distributions.
|
static double |
regularizedGammaP(double a,
double x)
Returns the regularized gamma function P(a, x).
|
static double |
regularizedGammaQ(double a,
double x)
Returns the regularized gamma function Q(a, x) = 1 - P(a, x).
|
String |
toString()
Simple toString explaining the distribution parameters.
|
static double |
trigamma(double x)
Compute the Trigamma function.
|
public static final double EULERS_CONST
static final double[] LANCZOS
static final double NUM_PRECISION
static final int MAX_ITERATIONS
private final double k
private final double theta
public GammaDistribution(double k, double theta, Random random)
k
- k, alpha aka. "shape" parametertheta
- Theta = 1.0/Beta aka. "scaling" parameterrandom
- Random generatorpublic GammaDistribution(double k, double theta, RandomFactory random)
k
- k, alpha aka. "shape" parametertheta
- Theta = 1.0/Beta aka. "scaling" parameterrandom
- Random generatorpublic GammaDistribution(double k, double theta)
k
- k, alpha aka. "shape" parametertheta
- Theta = 1.0/Beta aka. "scaling" parameterpublic double pdf(double val)
Distribution
val
- existing valuepublic double cdf(double val)
Distribution
val
- existing valuepublic double quantile(double val)
Distribution
val
- Quantile to findpublic double nextRandom()
Distribution
nextRandom
in interface Distribution
nextRandom
in class AbstractDistribution
public String toString()
toString
in interface Distribution
toString
in class Object
public double getK()
public double getTheta()
public static double cdf(double val, double k, double theta)
val
- Valuek
- Shape ktheta
- Theta = 1.0/Beta aka. "scaling" parameterpublic static double logcdf(double val, double k, double theta)
val
- Valuek
- Shape ktheta
- Theta = 1.0/Beta aka. "scaling" parameterpublic static double pdf(double x, double k, double theta)
x
- query valuek
- Alphatheta
- Theta = 1 / Betapublic static double logpdf(double x, double k, double theta)
x
- query valuek
- Alphatheta
- Theta = 1 / Betapublic static double logGamma(double x)
x
- Parameter xpublic static double gamma(double x)
logGamma(double)
when possible! In particular, this method just computes
Math.exp(logGamma(x))
anyway.
Try to postpone the Math.exp
call to preserve numeric range!x
- Positionpublic static double regularizedGammaP(double a, double x)
a
- Parameter ax
- Parameter xpublic static double logregularizedGammaP(double a, double x)
a
- Parameter ax
- Parameter xpublic static double regularizedGammaQ(double a, double x)
a
- parameter ax
- parameter xpublic static double nextRandom(double k, double theta, Random random)
k
- K parametertheta
- Theta parameterrandom
- Random generator@Reference(title="Algorithm AS 91: The percentage points of the $\\chi^2$ distribution", authors="D.J. Best, D. E. Roberts", booktitle="Journal of the Royal Statistical Society. Series C (Applied Statistics)") protected static double chisquaredProbitApproximation(double p, double nu, double g)
Algorithm AS 91: The percentage points of the $\chi^2$ distribution
D.J. Best, D. E. Roberts
Journal of the Royal Statistical Society. Series C (Applied Statistics)
p
- Probit valuenu
- Shape parameter for Chi, nu = 2 * kg
- log(nu)@Reference(title="Algorithm AS 91: The percentage points of the $\\chi^2$ distribution", authors="D.J. Best, D. E. Roberts", booktitle="Journal of the Royal Statistical Society. Series C (Applied Statistics)") public static double quantile(double p, double k, double theta)
Algorithm AS 91: The percentage points of the $\chi^2$ distribution
D.J. Best, D. E. Roberts
Journal of the Royal Statistical Society. Series C (Applied Statistics)
p
- Probabilityk
- k, alpha aka. "shape" parametertheta
- Theta = 1.0/Beta aka. "scaling" parameterprotected static double gammaQuantileNewtonRefinement(double logpt, double k, double theta, int maxit, double x)
logpt
- Target value of log pk
- Alphatheta
- Theta = 1 / Betamaxit
- Maximum number of iterations to dox
- Initial estimate@Reference(authors="J. M. Bernando", title="Algorithm AS 103: Psi (Digamma) Function", booktitle="Statistical Algorithms") public static double digamma(double x)
J. M. Bernando
Algorithm AS 103: Psi (Digamma) Function
Statistical Algorithms
x
- Positionpublic static double trigamma(double x)
x
- Position