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