@Test public void testCdf() { System.out.println("cdf"); HyperGeometricDistribution instance = new HyperGeometricDistribution(100, 30, 70); instance.rand(); assertEquals(3.404564e-26, instance.cdf(0), 1E-30); assertEquals(7.152988e-23, instance.cdf(1), 1E-27); assertEquals(3.583732e-20, instance.cdf(2), 1E-25); assertEquals(0.4013632, instance.cdf(20), 1E-7); assertEquals(0.5891093, instance.cdf(21), 1E-7); assertEquals(0.9999568, instance.cdf(28), 1E-7); assertEquals(0.9999981, instance.cdf(29), 1E-7); assertEquals(1.0, instance.cdf(30), 1E-7); assertEquals(1.0, instance.cdf(31), 1E-7); }
@Override public double cdf(double k) { if (k < Math.max(0, m + n - N)) { return 0.0; } else if (k >= Math.min(m, n)) { return 1.0; } double p = 0.0; for (int i = Math.max(0, m + n - N); i <= k; i++) { p += p(i); } return p; }
HyperGeometricDistribution extends DiscreteDistribution { @Override public double cdf(double k) { if (k < Math.max(0, m + n - N)) { return 0.0; } else if (k >= Math.min(m, n)) { return 1.0; } double p = 0.0; for (int i = Math.max(0, m + n - N); i <= k; i++) { p += p(i); } return p; } }
HyperGeometricDistribution extends DiscreteDistribution { @Override public double cdf(double k) { if (k < Math.max(0, m + n - N)) { return 0.0; } else if (k >= Math.min(m, n)) { return 1.0; } double p = 0.0; for (int i = Math.max(0, m + n - N); i <= k; i++) { p += p(i); } return p; } HyperGeometricDistribution(int N, int m, int n); }
HyperGeometricDistribution extends DiscreteDistribution { @Override public double cdf(double k) { if (k < Math.max(0, m + n - N)) { return 0.0; } else if (k >= Math.min(m, n)) { return 1.0; } double p = 0.0; for (int i = Math.max(0, m + n - N); i <= k; i++) { p += p(i); } return p; } 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 cdf(double k) { if (k < Math.max(0, m + n - N)) { return 0.0; } else if (k >= Math.min(m, n)) { return 1.0; } double p = 0.0; for (int i = Math.max(0, m + n - N); i <= k; i++) { p += p(i); } return p; } 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; }