@Test public void testDiscreteSampler() { Vector distribution = new DenseVector(new double[] {1, 0, 2, 3, 5, 0}); Sampler sampler = new Sampler(RandomUtils.getRandom(), distribution); Vector sampledDistribution = distribution.like(); int i = 0; while (i < 100000) { int index = sampler.sample(); sampledDistribution.set(index, sampledDistribution.get(index) + 1); i++; } assertTrue("sampled distribution is far from the original", l1Dist(distribution, sampledDistribution) < 1.0e-2); }
public int sample(Vector distribution) { return sample(samplerFor(distribution)); }
Sampler { public int sample(Vector distribution) { return sample(samplerFor(distribution)); } }
Sampler { public int sample(Vector distribution) { return sample(samplerFor(distribution)); } Sampler(Random random);  Sampler(Random random, double[] sampler);  Sampler(Random random, Vector distribution); }
Sampler { public int sample(Vector distribution) { return sample(samplerFor(distribution)); } Sampler(Random random);  Sampler(Random random, double[] sampler);  Sampler(Random random, Vector distribution); int sample(Vector distribution); int sample(); }
Sampler { public int sample(Vector distribution) { return sample(samplerFor(distribution)); } Sampler(Random random);  Sampler(Random random, double[] sampler);  Sampler(Random random, Vector distribution); int sample(Vector distribution); int sample();  }