@PublicationReference(author="Wikipedia", title="Inverse transform sampling", type=WebPage, year=2008, url="http://en.wikipedia.org/wiki/Inverse_transform_sampling") public class InverseTransformSampling extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static RootFinder |
DEFAULT_ROOT_FINDER
Default root finding method for the algorithm, RootFinderRiddersMethod.
|
static double |
DEFAULT_TOLERANCE
Tolerance for Newton's method, 1.0E-10.
|
static int |
FUNCTION_EVALUATIONS
Number of function evaluations needed to invert the distribution.
|
Constructor and Description |
---|
InverseTransformSampling() |
Modifier and Type | Method and Description |
---|---|
protected static InputOutputPair<java.lang.Double,java.lang.Double> |
initializeNewtonsMethod(SmoothCumulativeDistributionFunction cdf,
double p,
double tolerance)
Initializes Newton's method for inverse transform sampling.
|
static <NumberType extends java.lang.Number> |
inverse(CumulativeDistributionFunction<NumberType> cdf,
double p)
Inverts the given CDF, finding the value of "x" so that CDF(x)=p using
a root-finding algorithm.
|
static InputOutputPair<java.lang.Double,java.lang.Double> |
inverseNewtonsMethod(SmoothUnivariateDistribution distribution,
double p,
double tolerance)
Inverts the given CDF, finding the value of "x" so that CDF(x)=p using
a root-finding algorithm.
|
static InputOutputPair<java.lang.Double,java.lang.Double> |
inverseRootFinder(RootFinder rootFinder,
CumulativeDistributionFunction<java.lang.Double> cdf,
double p)
Inverts the given CDF, finding the value of "x" so that CDF(x)=p using
a root-finding algorithm.
|
static java.util.ArrayList<java.lang.Double> |
sample(CumulativeDistributionFunction<java.lang.Double> cdf,
java.util.Random random,
int numSamples)
Samples from the given CDF using the inverseRootFinder transform sampling method.
|
static void |
sampleInto(CumulativeDistributionFunction<java.lang.Double> cdf,
java.util.Random random,
int numSamples,
java.util.Collection<? super java.lang.Double> output)
Samples from the given CDF using the inverseRootFinder transform sampling method.
|
public static final RootFinder DEFAULT_ROOT_FINDER
public static final double DEFAULT_TOLERANCE
public static int FUNCTION_EVALUATIONS
public static java.util.ArrayList<java.lang.Double> sample(CumulativeDistributionFunction<java.lang.Double> cdf, java.util.Random random, int numSamples)
cdf
- CDF from which to sample.random
- Random number generator.numSamples
- Number of samples to draw from the CDF.public static void sampleInto(CumulativeDistributionFunction<java.lang.Double> cdf, java.util.Random random, int numSamples, java.util.Collection<? super java.lang.Double> output)
cdf
- CDF from which to sample.random
- Random number generator.numSamples
- Number of samples to draw from the CDF.output
- Collection to put samples drawn according to the given CDF.public static <NumberType extends java.lang.Number> InputOutputPair<NumberType,java.lang.Double> inverse(CumulativeDistributionFunction<NumberType> cdf, double p)
NumberType
- Type of number observation.cdf
- CDF to invertp
- Probability, [0,1].public static InputOutputPair<java.lang.Double,java.lang.Double> inverseRootFinder(RootFinder rootFinder, CumulativeDistributionFunction<java.lang.Double> cdf, double p)
rootFinder
- Root-finding algorithm to use.cdf
- CDF to invertp
- Probability, [0,1].public static InputOutputPair<java.lang.Double,java.lang.Double> inverseNewtonsMethod(SmoothUnivariateDistribution distribution, double p, double tolerance)
distribution
- Distribution to invertp
- Probability, [0,1].tolerance
- Tolerance below which we stop.protected static InputOutputPair<java.lang.Double,java.lang.Double> initializeNewtonsMethod(SmoothCumulativeDistributionFunction cdf, double p, double tolerance)
cdf
- CDF to invert.p
- Target value to invert, that is to find "x" such that p=cdf(x).tolerance
- Tolerance before stopping.