DiscreteSampler
public class InverseTransformDiscreteSampler extends SamplerBase implements DiscreteSampler
Example:
import org.apache.commons.math3.distribution.IntegerDistribution;
import org.apache.commons.math3.distribution.BinomialDistribution;
import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.rng.sampling.distribution.DiscreteSampler;
import org.apache.commons.rng.sampling.distribution.InverseTransformDiscreteSampler;
import org.apache.commons.rng.sampling.distribution.DiscreteInverseCumulativeProbabilityFunction;
// Distribution to sample.
final IntegerDistribution dist = new BinomialDistribution(11, 0.56);
// Create the sampler.
final DiscreteSampler binomialSampler =
new InverseTransformDiscreteSampler(RandomSource.create(RandomSource.MT),
new DiscreteInverseCumulativeProbabilityFunction() {
public int inverseCumulativeProbability(double p) {
return dist.inverseCumulativeProbability(p);
}
});
// Generate random deviate.
int random = binomialSampler.sample();
Constructor | Description |
---|---|
InverseTransformDiscreteSampler(org.apache.commons.rng.UniformRandomProvider rng,
DiscreteInverseCumulativeProbabilityFunction function) |
Modifier and Type | Method | Description |
---|---|---|
int |
sample() |
Creates a sample.
|
java.lang.String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
nextDouble, nextInt, nextInt, nextLong
public InverseTransformDiscreteSampler(org.apache.commons.rng.UniformRandomProvider rng, DiscreteInverseCumulativeProbabilityFunction function)
rng
- Generator of uniformly distributed random numbers.function
- Inverse cumulative probability function.public int sample()
sample
in interface DiscreteSampler
public java.lang.String toString()
toString
in class SamplerBase
Copyright © 2016–2018 The Apache Software Foundation. All rights reserved.