@Test public void testQuantile() { System.out.println("quantile"); PoissonDistribution instance = new PoissonDistribution(3.5); instance.rand(); assertEquals(0, instance.quantile(0.01), 1E-7); assertEquals(1, instance.quantile(0.1), 1E-7); assertEquals(2, instance.quantile(0.2), 1E-7); assertEquals(2, instance.quantile(0.3), 1E-7); assertEquals(3, instance.quantile(0.4), 1E-6); assertEquals(3, instance.quantile(0.5), 1E-6); assertEquals(6, instance.quantile(0.9), 1E-6); assertEquals(8, instance.quantile(0.99), 1E-6); }
@Override public double quantile(double p) { if (p < 0.0 || p > 1.0) { throw new IllegalArgumentException("Invalid p: " + p); } if (p < Math.exp(-lambda)) { return 0; } int n = (int) Math.max(Math.sqrt(lambda), 5.0); int nl, nu, inc = 1; if (p < cdf(n)) { do { n = Math.max(n - inc, 0); inc *= 2; } while (p < cdf(n) && n > 0); nl = n; nu = n + inc / 2; } else { do { n += inc; inc *= 2; } while (p > cdf(n)); nu = n; nl = n - inc / 2; } return quantile(p, nl, nu); }
PoissonDistribution extends DiscreteDistribution implements DiscreteExponentialFamily { @Override public double quantile(double p) { if (p < 0.0 || p > 1.0) { throw new IllegalArgumentException("Invalid p: " + p); } if (p < Math.exp(-lambda)) { return 0; } int n = (int) Math.max(Math.sqrt(lambda), 5.0); int nl, nu, inc = 1; if (p < cdf(n)) { do { n = Math.max(n - inc, 0); inc *= 2; } while (p < cdf(n) && n > 0); nl = n; nu = n + inc / 2; } else { do { n += inc; inc *= 2; } while (p > cdf(n)); nu = n; nl = n - inc / 2; } return quantile(p, nl, nu); } }
PoissonDistribution extends DiscreteDistribution implements DiscreteExponentialFamily { @Override public double quantile(double p) { if (p < 0.0 || p > 1.0) { throw new IllegalArgumentException("Invalid p: " + p); } if (p < Math.exp(-lambda)) { return 0; } int n = (int) Math.max(Math.sqrt(lambda), 5.0); int nl, nu, inc = 1; if (p < cdf(n)) { do { n = Math.max(n - inc, 0); inc *= 2; } while (p < cdf(n) && n > 0); nl = n; nu = n + inc / 2; } else { do { n += inc; inc *= 2; } while (p > cdf(n)); nu = n; nl = n - inc / 2; } return quantile(p, nl, nu); } PoissonDistribution(double lambda); }
PoissonDistribution extends DiscreteDistribution implements DiscreteExponentialFamily { @Override public double quantile(double p) { if (p < 0.0 || p > 1.0) { throw new IllegalArgumentException("Invalid p: " + p); } if (p < Math.exp(-lambda)) { return 0; } int n = (int) Math.max(Math.sqrt(lambda), 5.0); int nl, nu, inc = 1; if (p < cdf(n)) { do { n = Math.max(n - inc, 0); inc *= 2; } while (p < cdf(n) && n > 0); nl = n; nu = n + inc / 2; } else { do { n += inc; inc *= 2; } while (p > cdf(n)); nu = n; nl = n - inc / 2; } return quantile(p, nl, nu); } PoissonDistribution(double lambda); static PoissonDistribution fit(int[] data); @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 DiscreteMixture.Component M(int[] x, double[] posteriori); @Override double rand(); }
PoissonDistribution extends DiscreteDistribution implements DiscreteExponentialFamily { @Override public double quantile(double p) { if (p < 0.0 || p > 1.0) { throw new IllegalArgumentException("Invalid p: " + p); } if (p < Math.exp(-lambda)) { return 0; } int n = (int) Math.max(Math.sqrt(lambda), 5.0); int nl, nu, inc = 1; if (p < cdf(n)) { do { n = Math.max(n - inc, 0); inc *= 2; } while (p < cdf(n) && n > 0); nl = n; nu = n + inc / 2; } else { do { n += inc; inc *= 2; } while (p > cdf(n)); nu = n; nl = n - inc / 2; } return quantile(p, nl, nu); } PoissonDistribution(double lambda); static PoissonDistribution fit(int[] data); @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 DiscreteMixture.Component M(int[] x, double[] posteriori); @Override double rand(); final double lambda; }