GammaDistribution extends AbstractRealDistribution { public double density(double x) { if (x < 0) { return 0; } final double y = x / scale; if ((y <= minY) || (FastMath.log(y) >= maxLogY)) { final double aux1 = (y - shiftedShape) / shiftedShape; final double aux2 = shape * (FastMath.log1p(aux1) - aux1); final double aux3 = -y * (Gamma.LANCZOS_G + 0.5) / shiftedShape + Gamma.LANCZOS_G + aux2; return densityPrefactor2 / x * FastMath.exp(aux3); } return densityPrefactor1 * FastMath.exp(-y) * FastMath.pow(y, shape - 1); } GammaDistribution(double shape, double scale);  GammaDistribution(double shape, double scale, double inverseCumAccuracy);  GammaDistribution(RandomGenerator rng, double shape, double scale);  GammaDistribution(RandomGenerator rng,
                             double shape,
                             double scale,
                             double inverseCumAccuracy); @Deprecated double getAlpha(); double getShape(); @Deprecated double getBeta(); double getScale(); double density(double x); @Override double logDensity(double x); double cumulativeProbability(double x); double getNumericalMean(); double getNumericalVariance(); double getSupportLowerBound(); double getSupportUpperBound(); boolean isSupportLowerBoundInclusive(); boolean isSupportUpperBoundInclusive(); boolean isSupportConnected(); @Override double sample(); static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY; }
@Test public void testDensity() { double[] x = new double[]{-0.1, 1e-6, 0.5, 1, 2, 5}; checkDensity(1, 1, x, new double[]{0.000000000000, 0.999999000001, 0.606530659713, 0.367879441171, 0.135335283237, 0.006737946999}); checkDensity(2, 1, x, new double[]{0.000000000000, 0.000000999999, 0.303265329856, 0.367879441171, 0.270670566473, 0.033689734995}); checkDensity(4, 1, x, new double[]{0.000000000e+00, 1.666665000e-19, 1.263605541e-02, 6.131324020e-02, 1.804470443e-01, 1.403738958e-01}); checkDensity(4, 10, x, new double[]{0.000000000e+00, 1.666650000e-15, 1.403738958e+00, 7.566654960e-02, 2.748204830e-05, 4.018228850e-17}); checkDensity(0.1, 10, x, new double[]{0.000000000e+00, 3.323953832e+04, 1.663849010e-03, 6.007786726e-06, 1.461647647e-10, 5.996008322e-24}); checkDensity(0.1, 20, x, new double[]{0.000000000e+00, 3.562489883e+04, 1.201557345e-05, 2.923295295e-10, 3.228910843e-19, 1.239484589e-45}); checkDensity(0.1, 4, x, new double[]{0.000000000e+00, 3.032938388e+04, 3.049322494e-02, 2.211502311e-03, 2.170613371e-05, 5.846590589e-11}); checkDensity(0.1, 1, x, new double[]{0.000000000e+00, 2.640334143e+04, 1.189704437e-01, 3.866916944e-02, 7.623306235e-03, 1.663849010e-04}); }