EnumeratedRealDistribution extends AbstractRealDistribution { @Override public double inverseCumulativeProbability(final double p) throws OutOfRangeException { if (p < 0.0 || p > 1.0) { throw new OutOfRangeException(p, 0, 1); } double probability = 0; double x = getSupportLowerBound(); for (final Pair<Double, Double> sample : innerDistribution.getPmf()) { if (sample.getValue() == 0.0) { continue; } probability += sample.getValue(); x = sample.getKey(); if (probability >= p) { break; } } return x; } EnumeratedRealDistribution(final double[] singletons, final double[] probabilities);  EnumeratedRealDistribution(final RandomGenerator rng,
                                    final double[] singletons, final double[] probabilities); @Override double probability(final double x); double density(final double x); double cumulativeProbability(final double x); @Override double inverseCumulativeProbability(final double p); double getNumericalMean(); double getNumericalVariance(); double getSupportLowerBound(); double getSupportUpperBound(); boolean isSupportLowerBoundInclusive(); boolean isSupportUpperBoundInclusive(); boolean isSupportConnected(); @Override double sample();  }
@Test public void testIssue1065() { EnumeratedRealDistribution distribution = new EnumeratedRealDistribution( new double[] { 14.0, 18.0, 21.0, 28.0, 31.0, 33.0 }, new double[] { 4.0 / 16.0, 5.0 / 16.0, 0.0 / 16.0, 3.0 / 16.0, 1.0 / 16.0, 3.0 / 16.0 }); assertEquals(14.0, distribution.inverseCumulativeProbability(0.0000), 0.0); assertEquals(14.0, distribution.inverseCumulativeProbability(0.2500), 0.0); assertEquals(33.0, distribution.inverseCumulativeProbability(1.0000), 0.0); assertEquals(18.0, distribution.inverseCumulativeProbability(0.5000), 0.0); assertEquals(18.0, distribution.inverseCumulativeProbability(0.5624), 0.0); assertEquals(28.0, distribution.inverseCumulativeProbability(0.5626), 0.0); assertEquals(31.0, distribution.inverseCumulativeProbability(0.7600), 0.0); assertEquals(18.0, distribution.inverseCumulativeProbability(0.5625), 0.0); assertEquals(28.0, distribution.inverseCumulativeProbability(0.7500), 0.0); }