@Test public void testLogP() { System.out.println("logP"); GammaDistribution instance = new GammaDistribution(3, 2.1); instance.rand(); assertTrue(Double.isInfinite(instance.logp(-0.1))); assertTrue(Double.isInfinite(instance.logp(0.0))); assertEquals(-3.39515, instance.logp(1.0), 1E-5); assertEquals(-2.485046, instance.logp(2.0), 1E-6); assertEquals(-2.150306, instance.logp(3.0), 1E-6); assertEquals(-2.051132, instance.logp(4.0), 1E-6); assertEquals(-3.075694, instance.logp(10.0), 1E-6); assertEquals(-6.451304, instance.logp(20.0), 1E-6); assertEquals(-10.40228, instance.logp(30.0), 1E-5); }
@Override public double logp(double x) { if (x < 0) { return Double.NEGATIVE_INFINITY; } else { return (k - 1) * Math.log(x) - x / theta - k * logTheta - logGammaK; } }
GammaDistribution extends AbstractDistribution implements ExponentialFamily { @Override public double logp(double x) { if (x < 0) { return Double.NEGATIVE_INFINITY; } else { return (k - 1) * Math.log(x) - x / theta - k * logTheta - logGammaK; } } }
GammaDistribution extends AbstractDistribution implements ExponentialFamily { @Override public double logp(double x) { if (x < 0) { return Double.NEGATIVE_INFINITY; } else { return (k - 1) * Math.log(x) - x / theta - k * logTheta - logGammaK; } } GammaDistribution(double shape, double scale); }
GammaDistribution extends AbstractDistribution implements ExponentialFamily { @Override public double logp(double x) { if (x < 0) { return Double.NEGATIVE_INFINITY; } else { return (k - 1) * Math.log(x) - x / theta - k * logTheta - logGammaK; } } 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 { @Override public double logp(double x) { if (x < 0) { return Double.NEGATIVE_INFINITY; } else { return (k - 1) * Math.log(x) - x / theta - k * logTheta - logGammaK; } } 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; }