Class InverseTransformContinuousSampler

  • All Implemented Interfaces:
    ContinuousSampler, SharedStateContinuousSampler, SharedStateSampler<SharedStateContinuousSampler>

    public class InverseTransformContinuousSampler
    extends SamplerBase
    implements SharedStateContinuousSampler
    Distribution sampler that uses the inversion method. It can be used to sample any distribution that provides access to its inverse cumulative probability function.

    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 =
         InverseTransformContinuousSampler.of(RandomSource.XO_RO_SHI_RO_128_PP.create(),
                                              new ContinuousInverseCumulativeProbabilityFunction() {
                                                  public double inverseCumulativeProbability(double p) {
                                                      return dist.inverseCumulativeProbability(p);
                                                  }
                                              });
    
     // Generate random deviate.
     double random = chiSquareSampler.sample();
     
    Since:
    1.0