@Test public void testLogP() { System.out.println("logP"); NegativeBinomialDistribution instance = new NegativeBinomialDistribution(3, 0.3); instance.rand(); assertEquals(Math.log(0.027), instance.logp(0), 1E-7); assertEquals(Math.log(0.0567), instance.logp(1), 1E-7); assertEquals(Math.log(0.07938), instance.logp(2), 1E-7); assertEquals(Math.log(0.09261), instance.logp(3), 1E-7); assertEquals(Math.log(0.05033709), instance.logp(10), 1E-7); }
@Override public double logp(int k) { if (k < 0) { return Double.NEGATIVE_INFINITY; } else { return lgamma(r + k) - lfactorial(k) - lgamma(r) + r * Math.log(p) + k * Math.log(1 - p); } }
NegativeBinomialDistribution extends DiscreteDistribution { @Override public double logp(int k) { if (k < 0) { return Double.NEGATIVE_INFINITY; } else { return lgamma(r + k) - lfactorial(k) - lgamma(r) + r * Math.log(p) + k * Math.log(1 - p); } } }
NegativeBinomialDistribution extends DiscreteDistribution { @Override public double logp(int k) { if (k < 0) { return Double.NEGATIVE_INFINITY; } else { return lgamma(r + k) - lfactorial(k) - lgamma(r) + r * Math.log(p) + k * Math.log(1 - p); } } NegativeBinomialDistribution(double r, double p); }
NegativeBinomialDistribution extends DiscreteDistribution { @Override public double logp(int k) { if (k < 0) { return Double.NEGATIVE_INFINITY; } else { return lgamma(r + k) - lfactorial(k) - lgamma(r) + r * Math.log(p) + k * Math.log(1 - p); } } NegativeBinomialDistribution(double r, double p); @Override int length(); @Override double mean(); @Override double variance(); @Override double sd(); @Override double entropy(); @Override String toString(); @Override double rand(); @Override double p(int k); @Override double logp(int k); @Override double cdf(double k); @Override double quantile(double p); }
NegativeBinomialDistribution extends DiscreteDistribution { @Override public double logp(int k) { if (k < 0) { return Double.NEGATIVE_INFINITY; } else { return lgamma(r + k) - lfactorial(k) - lgamma(r) + r * Math.log(p) + k * Math.log(1 - p); } } NegativeBinomialDistribution(double r, double p); @Override int length(); @Override double mean(); @Override double variance(); @Override double sd(); @Override double entropy(); @Override String toString(); @Override double rand(); @Override double p(int k); @Override double logp(int k); @Override double cdf(double k); @Override double quantile(double p); final double r; final double p; }