## 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 InverseTransformSamplingextends 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
`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
`InverseTransformSampling()`

Method Summary
`protected static InputOutputPair<Double,Double>` ```initializeNewtonsMethod(SmoothCumulativeDistributionFunction cdf, double p, double tolerance)```
Initializes Newton's method for inverse transform sampling.
```static <NumberType extends Number> InputOutputPair<NumberType,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<Double,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<Double,Double>` ```inverseRootFinder(RootFinder rootFinder, CumulativeDistributionFunction<Double> cdf, double p)```
Inverts the given CDF, finding the value of "x" so that CDF(x)=p using a root-finding algorithm.
`static ArrayList<Double>` ```sample(CumulativeDistributionFunction<Double> cdf, Random random, int numSamples)```
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 ArrayList<Double> sample(CumulativeDistributionFunction<Double> cdf,
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.

### inverse

```public static <NumberType extends Number> InputOutputPair<NumberType,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<Double,Double> inverseRootFinder(RootFinder rootFinder,
CumulativeDistributionFunction<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<Double,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<Double,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.