public PoissonSampler(double lambda) { limit = 1; gen = RandomUtils.getRandom(); pd = new PoissonDistribution(gen.getRandomGenerator(), lambda, PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS); }
private static void checkDistribution(Sampler<Double> pd, double alpha) { int[] count = new int[(int) Math.max(10, 5 * alpha)]; for (int i = 0; i < 10000; i++) { count[pd.sample().intValue()]++; } IntegerDistribution ref = new PoissonDistribution(RandomUtils.getRandom().getRandomGenerator(), alpha, PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS); for (int i = 0; i < count.length; i++) { assertEquals(ref.probability(i), count[i] / 10000.0, 2.0e-2); } } }
@Test public void testSample() throws Exception { double[] data = new double[10001]; Sampler<Double> sampler = new Normal(); for (int i = 0; i < data.length; i++) { data[i] = sampler.sample(); } Arrays.sort(data); NormalDistribution reference = new NormalDistribution(RandomUtils.getRandom().getRandomGenerator(), 0, 1, NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY); assertEquals("Median", reference.inverseCumulativeProbability(0.5), data[5000], 0.04); } }
public SamplingIterator(RandomWrapper random, Iterator<? extends T> delegate, double samplingRate) { Preconditions.checkNotNull(delegate); Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0, "Must be: 0.0 < samplingRate <= 1.0. But samplingRate = " + samplingRate); // Geometric distribution is special case of negative binomial (aka Pascal) with r=1: geometricDistribution = new PascalDistribution(random.getRandomGenerator(), 1, samplingRate); this.delegate = delegate; }
public SamplingIterator(RandomWrapper random, Iterator<? extends T> delegate, double samplingRate) { Preconditions.checkNotNull(delegate); Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0, "Must be: 0.0 < samplingRate <= 1.0. But samplingRate = " + samplingRate); // Geometric distribution is special case of negative binomial (aka Pascal) with r=1: geometricDistribution = new PascalDistribution(random.getRandomGenerator(), 1, samplingRate); this.delegate = delegate; }
public SamplingIterator(RandomWrapper random, Iterator<? extends T> delegate, double samplingRate) { Preconditions.checkNotNull(delegate); Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0, "Must be: 0.0 < samplingRate <= 1.0. But samplingRate = " + samplingRate); // Geometric distribution is special case of negative binomial (aka Pascal) with r=1: geometricDistribution = new PascalDistribution(random.getRandomGenerator(), 1, samplingRate); this.delegate = delegate; }
public SamplingLongPrimitiveIterator(final RandomWrapper random, final LongPrimitiveIterator delegate, final double samplingRate) { Preconditions.checkNotNull(delegate); Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0, "Must be: 0.0 < samplingRate <= 1.0"); // Geometric distribution is special case of negative binomial (aka Pascal) with r=1: geometricDistribution = new PascalDistribution( random.getRandomGenerator(), 1, samplingRate); this.delegate = delegate; hasNext = true; doNext(); }
public SamplingLongPrimitiveIterator(RandomWrapper random, LongPrimitiveIterator delegate, double samplingRate) { Preconditions.checkNotNull(delegate); Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0, "Must be: 0.0 < samplingRate <= 1.0"); // Geometric distribution is special case of negative binomial (aka Pascal) with r=1: geometricDistribution = new PascalDistribution(random.getRandomGenerator(), 1, samplingRate); this.delegate = delegate; this.hasNext = true; doNext(); }
public SamplingLongPrimitiveIterator(RandomWrapper random, LongPrimitiveIterator delegate, double samplingRate) { Preconditions.checkNotNull(delegate); Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0, "Must be: 0.0 < samplingRate <= 1.0"); // Geometric distribution is special case of negative binomial (aka Pascal) with r=1: geometricDistribution = new PascalDistribution(random.getRandomGenerator(), 1, samplingRate); this.delegate = delegate; this.hasNext = true; doNext(); }
public SamplingLongPrimitiveIterator(RandomWrapper random, LongPrimitiveIterator delegate, double samplingRate) { Preconditions.checkNotNull(delegate); Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0, "Must be: 0.0 < samplingRate <= 1.0"); // Geometric distribution is special case of negative binomial (aka Pascal) with r=1: geometricDistribution = new PascalDistribution(random.getRandomGenerator(), 1, samplingRate); this.delegate = delegate; this.hasNext = true; doNext(); }
public PoissonSampler(double lambda) { limit = 1; gen = RandomUtils.getRandom(); pd = new PoissonDistribution(gen.getRandomGenerator(), lambda, PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS); }
/** * Return a random value from a normal distribution with the given mean and standard deviation * * @param mean * a double mean value * @param sd * a double standard deviation * @return a double sample */ public static double rNorm(double mean, double sd) { RealDistribution dist = new NormalDistribution(RANDOM.getRandomGenerator(), mean, sd, NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY); return dist.sample(); }
/** * Return a random value from a normal distribution with the given mean and standard deviation * * @param mean * a double mean value * @param sd * a double standard deviation * @return a double sample */ public static double rNorm(double mean, double sd) { RealDistribution dist = new NormalDistribution(RANDOM.getRandomGenerator(), mean, sd, NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY); return dist.sample(); }
/** * Return a random value from a normal distribution with the given mean and standard deviation * * @param mean * a double mean value * @param sd * a double standard deviation * @return a double sample */ public static double rNorm(double mean, double sd) { RealDistribution dist = new NormalDistribution(RANDOM.getRandomGenerator(), mean, sd, NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY); return dist.sample(); }