ContinuousSampler
, SharedStateContinuousSampler
, SharedStateSampler<SharedStateContinuousSampler>
public class InverseTransformContinuousSampler extends SamplerBase implements SharedStateContinuousSampler
Sampling uses UniformRandomProvider.nextDouble()
.
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 |
---|---|---|
static SharedStateContinuousSampler |
of(org.apache.commons.rng.UniformRandomProvider rng,
ContinuousInverseCumulativeProbabilityFunction function) |
Create a new inverse-transform continuous sampler.
|
double |
sample() |
Creates a sample.
|
java.lang.String |
toString() |
|
SharedStateContinuousSampler |
withUniformRandomProvider(org.apache.commons.rng.UniformRandomProvider rng) |
Create a new instance of the sampler with the same underlying state using the given
uniform random provider as the source of randomness.
|
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
public SharedStateContinuousSampler withUniformRandomProvider(org.apache.commons.rng.UniformRandomProvider rng)
Note: The new sampler will share the inverse cumulative probability function. This must be suitable for concurrent use to ensure thread safety.
withUniformRandomProvider
in interface SharedStateSampler<SharedStateContinuousSampler>
rng
- Generator of uniformly distributed random numbers.public static SharedStateContinuousSampler of(org.apache.commons.rng.UniformRandomProvider rng, ContinuousInverseCumulativeProbabilityFunction function)
To use the sampler to
share state
the function must be
suitable for concurrent use.
rng
- Generator of uniformly distributed random numbers.function
- Inverse cumulative probability function.withUniformRandomProvider(UniformRandomProvider)
Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.