@Test public void testLogP() { System.out.println("logP"); BinomialDistribution instance = new BinomialDistribution(100, 0.3); instance.rand(); assertEquals(Math.log(3.234477e-16), instance.logp(0), 1E-5); assertEquals(Math.log(1.386204e-14), instance.logp(1), 1E-5); assertEquals(Math.log(1.170418e-06), instance.logp(10), 1E-5); assertEquals(Math.log(0.007575645), instance.logp(20), 1E-5); assertEquals(Math.log(0.08678386), instance.logp(30), 1E-5); assertEquals(Math.log(5.153775e-53), instance.logp(100), 1E-5); }
@Override public double logp(int k) { if (k < 0 || k > n) { return Double.NEGATIVE_INFINITY; } else { return lfactorial(n) - lfactorial(k) - lfactorial(n - k) + k * log(p) + (n - k) * log(1.0 - p); } }
BinomialDistribution extends DiscreteDistribution { @Override public double logp(int k) { if (k < 0 || k > n) { return Double.NEGATIVE_INFINITY; } else { return lfactorial(n) - lfactorial(k) - lfactorial(n - k) + k * log(p) + (n - k) * log(1.0 - p); } } }
BinomialDistribution extends DiscreteDistribution { @Override public double logp(int k) { if (k < 0 || k > n) { return Double.NEGATIVE_INFINITY; } else { return lfactorial(n) - lfactorial(k) - lfactorial(n - k) + k * log(p) + (n - k) * log(1.0 - p); } } BinomialDistribution(int n, double p); }
BinomialDistribution extends DiscreteDistribution { @Override public double logp(int k) { if (k < 0 || k > n) { return Double.NEGATIVE_INFINITY; } else { return lfactorial(n) - lfactorial(k) - lfactorial(n - k) + k * log(p) + (n - k) * log(1.0 - p); } } BinomialDistribution(int n, double p); @Override int length(); @Override double mean(); @Override double variance(); @Override double sd(); @Override double entropy(); @Override String toString(); @Override double p(int k); @Override double logp(int k); @Override double cdf(double k); @Override double quantile(double p); @Override double rand(); }
BinomialDistribution extends DiscreteDistribution { @Override public double logp(int k) { if (k < 0 || k > n) { return Double.NEGATIVE_INFINITY; } else { return lfactorial(n) - lfactorial(k) - lfactorial(n - k) + k * log(p) + (n - k) * log(1.0 - p); } } BinomialDistribution(int n, double p); @Override int length(); @Override double mean(); @Override double variance(); @Override double sd(); @Override double entropy(); @Override String toString(); @Override double p(int k); @Override double logp(int k); @Override double cdf(double k); @Override double quantile(double p); @Override double rand(); final double p; final int n; }