@Alias(value="de.lmu.ifi.dbs.elki.data.synthetic.bymodel.distribution.GammaDistribution") 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,
java.util.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:
D.
|
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.
|
double |
logpdf(double val)
Return the log density of an existing value
|
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,
java.util.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).
|
java.lang.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
These are said to have higher precision than those in "Numerical Recipes". They probably come from
Paul Godfrey: http://my.fit.edu/~gabdo/gamma.txt
static final double NUM_PRECISION
static final int MAX_ITERATIONS
private final double k
private final double theta
public GammaDistribution(double k, double theta, java.util.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 logpdf(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 java.lang.String toString()
toString
in interface Distribution
toString
in class java.lang.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)
Based loosely on "Numerical Recpies" and the work of Paul Godfrey at http://my.fit.edu/~gabdo/gamma.txt
TODO: find out which approximation really is the best...
x
- Parameter xpublic static double gamma(double x)
Note: for numerical reasons, it is preferable to use logGamma(double)
when
possible! In particular, this method just computes
FastMath.exp(logGamma(x))
anyway.
Try to postpone the FastMath.exp
call to preserve numeric range!
x
- Positionpublic static double regularizedGammaP(double a, double x)
Includes the quadrature way of computing.
TODO: find "the" most accurate version of this. We seem to agree with others for the first 10+ digits, but diverge a bit later than that.
a
- Parameter ax
- Parameter xpublic static double logregularizedGammaP(double a, double x)
Includes the quadrature way of computing.
TODO: find "the" most accurate version of this. We seem to agree with others for the first 10+ digits, but diverge a bit later than that.
a
- Parameter ax
- Parameter xpublic static double regularizedGammaQ(double a, double x)
Includes the continued fraction way of computing, based loosely on the book "Numerical Recipes"; but probably not with the exactly same precision, since we reimplemented this in our coding style, not literally.
TODO: find "the" most accurate version of this. We seem to agree with others for the first 10+ digits, but diverge a bit later than that.
a
- parameter ax
- parameter x@Reference(authors="J. H. Ahrens, U. Dieter",title="Computer methods for sampling from gamma, beta, Poisson and binomial distributions",booktitle="Computing 12",url="https://doi.org/10.1007/BF02293108",bibkey="DBLP:journals/computing/AhrensD74") @Reference(authors="J. H. Ahrens, U. Dieter",title="Generating gamma variates by a modified rejection technique",booktitle="Communications of the ACM 25",url="https://doi.org/10.1145/358315.358390",bibkey="DBLP:journals/cacm/AhrensD82") public static double nextRandom(double k, double theta, java.util.Random random)
Along the lines of
J. H. Ahrens, U. Dieter
Computer methods for sampling from gamma, beta, Poisson and binomial
distributions
Computing 12
J. H. Ahrens, U. Dieter
Generating gamma variates by a modified rejection technique
Communications of the ACM 25
k
- K parametertheta
- Theta parameterrandom
- Random generator@Reference(authors="D. J. Best, D. E. Roberts", title="Algorithm AS 91: The percentage points of the \u03c7\u00b2 distribution", booktitle="Journal of the Royal Statistical Society. Series C (Applied Statistics)", url="https://doi.org/10.2307/2347113", bibkey="doi:10.2307/2347113") protected static double chisquaredProbitApproximation(double p, double nu, double g)
Based on first half of algorithm AS 91
Reference:
D. J. Best, D. E. Roberts
Algorithm AS 91: The percentage points of the χ² distribution
Journal of the Royal Statistical Society. Series C (Applied Statistics)
p
- Probit valuenu
- Shape parameter for Chi, nu = 2 * kg
- log(nu)@Reference(authors="D. J. Best, D. E. Roberts", title="Algorithm AS 91: The percentage points of the \u03c7\u00b2 distribution", booktitle="Journal of the Royal Statistical Society. Series C (Applied Statistics)", url="https://doi.org/10.2307/2347113", bibkey="doi:10.2307/2347113") public static double quantile(double p, double k, double theta)
Based on algorithm AS 91:
Reference:
D. J. Best, D. E. Roberts
Algorithm AS 91: The percentage points of the χ² distribution
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", url="https://doi.org/10.2307/2347257", bibkey="doi:10.2307/2347257") public static double digamma(double x)
Reference:
J. M. Bernando
Algorithm AS 103: Psi (Digamma) Function
Statistical Algorithms
TODO: is there a more accurate version maybe in R?
x
- Positionpublic static double trigamma(double x)
TODO: is there a more accurate version maybe in R?
x
- PositionCopyright © 2019 ELKI Development Team. License information.