@Test public void testSd() { System.out.println("sd"); HyperGeometricDistribution instance = new HyperGeometricDistribution(100, 30, 70); instance.rand(); assertEquals(2.110579, instance.sd(), 1E-6); instance = new HyperGeometricDistribution(100, 30, 80); instance.rand(); assertEquals(1.842265, instance.sd(), 1E-6); instance = new HyperGeometricDistribution(100, 30, 60); instance.rand(); assertEquals(2.256304, instance.sd(), 1E-6); }
@Override public double rand() { if (rng == null) { int mm = m; int nn = n; if (mm > N / 2) { mm = N - mm; } if (nn > N / 2) { nn = N - nn; } if ((double) nn * mm >= 20 * N) { rng = new Patchwork(N, m, n); } else { rng = new Inversion(N, m, n); } } return rng.rand(); }
HyperGeometricDistribution extends DiscreteDistribution { @Override public double rand() { if (rng == null) { int mm = m; int nn = n; if (mm > N / 2) { mm = N - mm; } if (nn > N / 2) { nn = N - nn; } if ((double) nn * mm >= 20 * N) { rng = new Patchwork(N, m, n); } else { rng = new Inversion(N, m, n); } } return rng.rand(); } }
HyperGeometricDistribution extends DiscreteDistribution { @Override public double rand() { if (rng == null) { int mm = m; int nn = n; if (mm > N / 2) { mm = N - mm; } if (nn > N / 2) { nn = N - nn; } if ((double) nn * mm >= 20 * N) { rng = new Patchwork(N, m, n); } else { rng = new Inversion(N, m, n); } } return rng.rand(); } HyperGeometricDistribution(int N, int m, int n); }
HyperGeometricDistribution extends DiscreteDistribution { @Override public double rand() { if (rng == null) { int mm = m; int nn = n; if (mm > N / 2) { mm = N - mm; } if (nn > N / 2) { nn = N - nn; } if ((double) nn * mm >= 20 * N) { rng = new Patchwork(N, m, n); } else { rng = new Inversion(N, m, n); } } return rng.rand(); } 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 rand() { if (rng == null) { int mm = m; int nn = n; if (mm > N / 2) { mm = N - mm; } if (nn > N / 2) { nn = N - nn; } if ((double) nn * mm >= 20 * N) { rng = new Patchwork(N, m, n); } else { rng = new Inversion(N, m, n); } } return rng.rand(); } 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; }