@Test public void testP() { System.out.println("p"); BinomialDistribution instance = new BinomialDistribution(100, 0.3); instance.rand(); assertEquals(3.234477e-16, instance.p(0), 1E-20); assertEquals(1.386204e-14, instance.p(1), 1E-18); assertEquals(1.170418e-06, instance.p(10), 1E-10); assertEquals(0.007575645, instance.p(20), 1E-7); assertEquals(0.08678386, instance.p(30), 1E-7); assertEquals(5.153775e-53, instance.p(100), 1E-58); }
@Override public double p(int k) { if (k < 0 || k > n) { return 0.0; } else { return Math.floor(0.5 + exp(lfactorial(n) - lfactorial(k) - lfactorial(n - k))) * Math.pow(p, k) * Math.pow(1.0 - p, n - k); } }
BinomialDistribution extends DiscreteDistribution { @Override public double p(int k) { if (k < 0 || k > n) { return 0.0; } else { return Math.floor(0.5 + exp(lfactorial(n) - lfactorial(k) - lfactorial(n - k))) * Math.pow(p, k) * Math.pow(1.0 - p, n - k); } } }
BinomialDistribution extends DiscreteDistribution { @Override public double p(int k) { if (k < 0 || k > n) { return 0.0; } else { return Math.floor(0.5 + exp(lfactorial(n) - lfactorial(k) - lfactorial(n - k))) * Math.pow(p, k) * Math.pow(1.0 - p, n - k); } } BinomialDistribution(int n, double p); }
BinomialDistribution extends DiscreteDistribution { @Override public double p(int k) { if (k < 0 || k > n) { return 0.0; } else { return Math.floor(0.5 + exp(lfactorial(n) - lfactorial(k) - lfactorial(n - k))) * Math.pow(p, k) * Math.pow(1.0 - p, n - k); } } 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 p(int k) { if (k < 0 || k > n) { return 0.0; } else { return Math.floor(0.5 + exp(lfactorial(n) - lfactorial(k) - lfactorial(n - k))) * Math.pow(p, k) * Math.pow(1.0 - p, n - k); } } 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; }