@Test public void testLogP() { System.out.println("logP"); HyperGeometricDistribution instance = new HyperGeometricDistribution(100, 30, 70); instance.rand(); assertEquals(Math.log(3.404564e-26), instance.logp(0), 1E-5); assertEquals(Math.log(7.149584e-23), instance.logp(1), 1E-5); assertEquals(Math.log(3.576579e-20), instance.logp(2), 1E-5); assertEquals(Math.log(0.1655920), instance.logp(20), 1E-5); assertEquals(Math.log(0.1877461), instance.logp(21), 1E-5); assertEquals(Math.log(0.00041413), instance.logp(28), 1E-5); assertEquals(Math.log(4.136376e-05), instance.logp(29), 1E-5); assertEquals(Math.log(1.884349e-06), instance.logp(30), 1E-5); }
@Override public double logp(int k) { if (k < Math.max(0, m + n - N) || k > Math.min(m, n)) { return Double.NEGATIVE_INFINITY; } else { return lchoose(m, k) + lchoose(N - m, n - k) - lchoose(N, n); } }
HyperGeometricDistribution extends DiscreteDistribution { @Override public double logp(int k) { if (k < Math.max(0, m + n - N) || k > Math.min(m, n)) { return Double.NEGATIVE_INFINITY; } else { return lchoose(m, k) + lchoose(N - m, n - k) - lchoose(N, n); } } }
HyperGeometricDistribution extends DiscreteDistribution { @Override public double logp(int k) { if (k < Math.max(0, m + n - N) || k > Math.min(m, n)) { return Double.NEGATIVE_INFINITY; } else { return lchoose(m, k) + lchoose(N - m, n - k) - lchoose(N, n); } } HyperGeometricDistribution(int N, int m, int n); }
HyperGeometricDistribution extends DiscreteDistribution { @Override public double logp(int k) { if (k < Math.max(0, m + n - N) || k > Math.min(m, n)) { return Double.NEGATIVE_INFINITY; } else { return lchoose(m, k) + lchoose(N - m, n - k) - lchoose(N, n); } } HyperGeometricDistribution(int N, int m, int n); @Override int length(); @Override double mean(); @Override double variance(); @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(); }
HyperGeometricDistribution extends DiscreteDistribution { @Override public double logp(int k) { if (k < Math.max(0, m + n - N) || k > Math.min(m, n)) { return Double.NEGATIVE_INFINITY; } else { return lchoose(m, k) + lchoose(N - m, n - k) - lchoose(N, n); } } HyperGeometricDistribution(int N, int m, int n); @Override int length(); @Override double mean(); @Override double variance(); @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 int N; final int m; final int n; }