@Test public void testLogP() { System.out.println("logP"); BetaDistribution instance = new BetaDistribution(2, 5); instance.rand(); assertTrue(Double.isInfinite(instance.logp(-0.1))); assertTrue(Double.isInfinite(instance.logp(0.0))); assertEquals(0.6771702, instance.logp(0.1), 1E-7); assertEquals(0.8991853, instance.logp(0.2), 1E-7); assertEquals(0.7705248, instance.logp(0.3), 1E-7); assertEquals(0.4416042, instance.logp(0.4), 1E-7); assertEquals(-0.06453852, instance.logp(0.5), 1E-7); assertTrue(Double.isInfinite(instance.logp(1.0))); assertTrue(Double.isInfinite(instance.logp(1.5))); }
@Override public double logp(double x) { if (x < 0 || x > 1) { return Double.NEGATIVE_INFINITY; } else { return (alpha - 1) * Math.log(x) + (beta - 1) * Math.log(1 - x) - Math.log(Beta.beta(alpha, beta)); } }
BetaDistribution extends AbstractDistribution implements ExponentialFamily { @Override public double logp(double x) { if (x < 0 || x > 1) { return Double.NEGATIVE_INFINITY; } else { return (alpha - 1) * Math.log(x) + (beta - 1) * Math.log(1 - x) - Math.log(Beta.beta(alpha, beta)); } } }
BetaDistribution extends AbstractDistribution implements ExponentialFamily { @Override public double logp(double x) { if (x < 0 || x > 1) { return Double.NEGATIVE_INFINITY; } else { return (alpha - 1) * Math.log(x) + (beta - 1) * Math.log(1 - x) - Math.log(Beta.beta(alpha, beta)); } } BetaDistribution(double alpha, double beta); }
BetaDistribution extends AbstractDistribution implements ExponentialFamily { @Override public double logp(double x) { if (x < 0 || x > 1) { return Double.NEGATIVE_INFINITY; } else { return (alpha - 1) * Math.log(x) + (beta - 1) * Math.log(1 - x) - Math.log(Beta.beta(alpha, beta)); } } BetaDistribution(double alpha, double beta); static BetaDistribution fit(double[] data); double getAlpha(); double getBeta(); @Override int length(); @Override double mean(); @Override double variance(); @Override double entropy(); @Override String toString(); @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); @Override double rand(); }
BetaDistribution extends AbstractDistribution implements ExponentialFamily { @Override public double logp(double x) { if (x < 0 || x > 1) { return Double.NEGATIVE_INFINITY; } else { return (alpha - 1) * Math.log(x) + (beta - 1) * Math.log(1 - x) - Math.log(Beta.beta(alpha, beta)); } } BetaDistribution(double alpha, double beta); static BetaDistribution fit(double[] data); double getAlpha(); double getBeta(); @Override int length(); @Override double mean(); @Override double variance(); @Override double entropy(); @Override String toString(); @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); @Override double rand(); final double alpha; final double beta; }