@Test public void testGammaDistribution() { System.out.println("GammaDistribution"); MathEx.setSeed(19650218); GammaDistribution instance = new GammaDistribution(3, 2.1); double[] data = instance.rand(1000); GammaDistribution est = GammaDistribution.fit(data); assertEquals(2.09, est.theta, 1E-2); assertEquals(2.95, est.k, 1E-2); }
public GammaDistribution(double shape, double scale) { if (shape <= 0) { throw new IllegalArgumentException("Invalid shape: " + shape); } if (scale <= 0) { throw new IllegalArgumentException("Invalid scale: " + scale); } theta = scale; k = shape; logTheta = Math.log(theta); thetaGammaK = theta * Gamma.gamma(k); logGammaK = Gamma.lgamma(k); entropy = k + Math.log(theta) + Gamma.lgamma(k) + (1 - k) * Gamma.digamma(k); }
GammaDistribution extends AbstractDistribution implements ExponentialFamily { public GammaDistribution(double shape, double scale) { if (shape <= 0) { throw new IllegalArgumentException("Invalid shape: " + shape); } if (scale <= 0) { throw new IllegalArgumentException("Invalid scale: " + scale); } theta = scale; k = shape; logTheta = Math.log(theta); thetaGammaK = theta * Gamma.gamma(k); logGammaK = Gamma.lgamma(k); entropy = k + Math.log(theta) + Gamma.lgamma(k) + (1 - k) * Gamma.digamma(k); } }
GammaDistribution extends AbstractDistribution implements ExponentialFamily { public GammaDistribution(double shape, double scale) { if (shape <= 0) { throw new IllegalArgumentException("Invalid shape: " + shape); } if (scale <= 0) { throw new IllegalArgumentException("Invalid scale: " + scale); } theta = scale; k = shape; logTheta = Math.log(theta); thetaGammaK = theta * Gamma.gamma(k); logGammaK = Gamma.lgamma(k); entropy = k + Math.log(theta) + Gamma.lgamma(k) + (1 - k) * Gamma.digamma(k); } GammaDistribution(double shape, double scale); }
GammaDistribution extends AbstractDistribution implements ExponentialFamily { public GammaDistribution(double shape, double scale) { if (shape <= 0) { throw new IllegalArgumentException("Invalid shape: " + shape); } if (scale <= 0) { throw new IllegalArgumentException("Invalid scale: " + scale); } theta = scale; k = shape; logTheta = Math.log(theta); thetaGammaK = theta * Gamma.gamma(k); logGammaK = Gamma.lgamma(k); entropy = k + Math.log(theta) + Gamma.lgamma(k) + (1 - k) * Gamma.digamma(k); } GammaDistribution(double shape, double scale); static GammaDistribution fit(double[] data); @Override int length(); @Override double mean(); @Override double variance(); @Override double sd(); @Override double entropy(); @Override String toString(); @Override double rand(); @Override double p(double x); @Override double logp(double x); @Override double cdf(double x); @Override double quantile(double p); @Override Mixture.Component M(double[] x, double[] posteriori); }
GammaDistribution extends AbstractDistribution implements ExponentialFamily { public GammaDistribution(double shape, double scale) { if (shape <= 0) { throw new IllegalArgumentException("Invalid shape: " + shape); } if (scale <= 0) { throw new IllegalArgumentException("Invalid scale: " + scale); } theta = scale; k = shape; logTheta = Math.log(theta); thetaGammaK = theta * Gamma.gamma(k); logGammaK = Gamma.lgamma(k); entropy = k + Math.log(theta) + Gamma.lgamma(k) + (1 - k) * Gamma.digamma(k); } GammaDistribution(double shape, double scale); static GammaDistribution fit(double[] data); @Override int length(); @Override double mean(); @Override double variance(); @Override double sd(); @Override double entropy(); @Override String toString(); @Override double rand(); @Override double p(double x); @Override double logp(double x); @Override double cdf(double x); @Override double quantile(double p); @Override Mixture.Component M(double[] x, double[] posteriori); final double theta; final double k; }