gov.sandia.cognition.statistics.method

## Class InverseTransformSampling

• java.lang.Object
• gov.sandia.cognition.statistics.method.InverseTransformSampling

• ```@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```
Inverse transform sampling is a method by which one can sample from an arbitrary distribution using only a uniform random-number generator and the ability to empirically invert the CDF. This allows us to convert Java's random-number generator (Random) into a Beta Distribution, Gamma distribution, or any other scalar distribution. It does, however, tend to require several function evaluations to invert the CDF and is typically fairly costly rather than those distributions that can be inverted algebraically.
Since:
3.0
Author:
Kevin R. Dixon
• ### Field Summary

Fields
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 Summary

Constructors
Constructor and Description
`InverseTransformSampling()`
• ### Method Summary

All Methods
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>InputOutputPair<NumberType,java.lang.Double>` ```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.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Field Detail

• #### DEFAULT_ROOT_FINDER

`public static final RootFinder DEFAULT_ROOT_FINDER`
Default root finding method for the algorithm, RootFinderRiddersMethod.
• #### DEFAULT_TOLERANCE

`public static final double DEFAULT_TOLERANCE`
Tolerance for Newton's method, 1.0E-10.
Constant Field Values
• #### FUNCTION_EVALUATIONS

`public static int FUNCTION_EVALUATIONS`
Number of function evaluations needed to invert the distribution.
• ### Constructor Detail

• #### InverseTransformSampling

`public InverseTransformSampling()`
• ### Method Detail

• #### sample

```public 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.
Parameters:
`cdf` - CDF from which to sample.
`random` - Random number generator.
`numSamples` - Number of samples to draw from the CDF.
Returns:
Samples draw according to the given CDF.
• #### sampleInto

```public 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.
Parameters:
`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.
• #### inverse

```public static <NumberType extends java.lang.Number> InputOutputPair<NumberType,java.lang.Double> 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.
Type Parameters:
`NumberType` - Type of number observation.
Parameters:
`cdf` - CDF to invert
`p` - Probability, [0,1].
Returns:
Root of the CDF.
• #### inverseRootFinder

```public 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.
Parameters:
`rootFinder` - Root-finding algorithm to use.
`cdf` - CDF to invert
`p` - Probability, [0,1].
Returns:
Root of the CDF.
• #### inverseNewtonsMethod

```public 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.
Parameters:
`distribution` - Distribution to invert
`p` - Probability, [0,1].
`tolerance` - Tolerance below which we stop.
Returns:
Root of the CDF.
• #### initializeNewtonsMethod

```protected static InputOutputPair<java.lang.Double,java.lang.Double> initializeNewtonsMethod(SmoothCumulativeDistributionFunction cdf,
double p,
double tolerance)```
Initializes Newton's method for inverse transform sampling.
Parameters:
`cdf` - CDF to invert.
`p` - Target value to invert, that is to find "x" such that p=cdf(x).
`tolerance` - Tolerance before stopping.
Returns:
Estimated (xhat,phat) to initialize Newton's method.