gov.sandia.cognition.statistics.bayesian
Class AdaptiveRejectionSampling

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.statistics.bayesian.AdaptiveRejectionSampling
All Implemented Interfaces:
CloneableSerializable, Serializable, Cloneable

@PublicationReference(author={"Christian P. Robert","George Casella"},
                      title="Monte Carlo Statistical Methods, Seconds Edition",
                      type=Book,
                      pages={56,58,70,71},
                      notes={"Algorithm A.7","Algorithm A.17"},
                      year=2004)
public class AdaptiveRejectionSampling
extends AbstractCloneableSerializable

Samples form a univariate distribution using the method of adaptive rejection sampling, which is a very efficient method that iteratively improves the rejection and acceptance envelopes in response to additional points.

Since:
3.0
Author:
Kevin R. Dixon
See Also:
Serialized Form

Nested Class Summary
 class AdaptiveRejectionSampling.AbstractEnvelope
          Describes an enveloping function comprised of a sorted sequence of lines
static class AdaptiveRejectionSampling.LineSegment
          A line that has a minimum and maximum support (x-axis) value.
static class AdaptiveRejectionSampling.LogEvaluator<EvaluatorType extends Evaluator<Double,Double>>
          Wraps an Evaluator and takes the natural logarithm of the evaluate method
 class AdaptiveRejectionSampling.LowerEnvelope
          Define the lower envelope for Adaptive Rejection Sampling
static class AdaptiveRejectionSampling.PDFLogEvaluator
          Wraps a PDF so that it returns the logEvaluate method.
static class AdaptiveRejectionSampling.Point
          An InputOutputPair that has a natural ordering according to their input (x-axis) values.
 class AdaptiveRejectionSampling.UpperEnvelope
          Constructs the upper envelope for sampling.
 
Field Summary
static int DEFAULT_MAX_NUM_POINTS
          Default number of points, 50.
 
Constructor Summary
AdaptiveRejectionSampling()
          Creates a new instance of AdaptiveRejectionSampling
 
Method Summary
 void addPoint(double x, double y)
          Adds a point to the set, which will adject the upper and lower envelopes
 AdaptiveRejectionSampling clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 AdaptiveRejectionSampling.LogEvaluator<?> getLogFunction()
          Getter for logFunction
 int getMaxNumPoints()
          Getter for maxNumPoints
 double getMaxSupport()
          Getter for maxSupport
 double getMinSupport()
          Getter for minSupport
 int getNumPoints()
          Gets the number of points stored
protected  Collection<AdaptiveRejectionSampling.Point> getPoints()
          Getter for points
 void initialize(AdaptiveRejectionSampling.LogEvaluator<?> logFunction, double minSupport, double maxSupport, double leftPoint, double midPoint, double rightPoint)
          Initializes the Adaptive Rejection Sampling method
 double sample(Random random)
          Draws a single sample by the method of adaptive rejection sampling.
 ArrayList<Double> sample(Random random, int numSamples)
          Draws samples by the adaptive rejection sampling method, which will have the distribution of the logFunction
 void setLogFunction(AdaptiveRejectionSampling.LogEvaluator<?> logFunction)
          Setter for logFunction
 void setMaxNumPoints(int maxNumPoints)
          Setter for maxNumPoints
 void setMaxSupport(double maxSupport)
          Setter for maxSupport
 void setMinSupport(double minSupport)
          Setter for minSupport
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAX_NUM_POINTS

public static final int DEFAULT_MAX_NUM_POINTS
Default number of points, 50.

See Also:
Constant Field Values
Constructor Detail

AdaptiveRejectionSampling

public AdaptiveRejectionSampling()
Creates a new instance of AdaptiveRejectionSampling

Method Detail

clone

public AdaptiveRejectionSampling clone()
Description copied from class: AbstractCloneableSerializable
This makes public the clone method on the Object class and removes the exception that it throws. Its default behavior is to automatically create a clone of the exact type of object that the clone is called on and to copy all primitives but to keep all references, which means it is a shallow copy. Extensions of this class may want to override this method (but call super.clone() to implement a "smart copy". That is, to target the most common use case for creating a copy of the object. Because of the default behavior being a shallow copy, extending classes only need to handle fields that need to have a deeper copy (or those that need to be reset). Some of the methods in ObjectUtil may be helpful in implementing a custom clone method. Note: The contract of this method is that you must use super.clone() as the basis for your implementation.

Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractCloneableSerializable
Returns:
A clone of this object.

initialize

public void initialize(AdaptiveRejectionSampling.LogEvaluator<?> logFunction,
                       double minSupport,
                       double maxSupport,
                       double leftPoint,
                       double midPoint,
                       double rightPoint)
Initializes the Adaptive Rejection Sampling method

Parameters:
logFunction - Logarithm of the evaluator to consider
minSupport - Minimum support (x-axis) of the evaluator
maxSupport - Maximum support (x-axis) of the evaluator
leftPoint - Left point to initialize
midPoint - Mid point to initialize with
rightPoint - Right point to initialize with

addPoint

public void addPoint(double x,
                     double y)
Adds a point to the set, which will adject the upper and lower envelopes

Parameters:
x - X-axis value
y - Y-axis value from the logFunction

getNumPoints

public int getNumPoints()
Gets the number of points stored

Returns:
Number of points stored

getPoints

protected Collection<AdaptiveRejectionSampling.Point> getPoints()
Getter for points

Returns:
Input-output point pairs, sorted in ascending order by their x-axis value

sample

public double sample(Random random)
Draws a single sample by the method of adaptive rejection sampling. If a sample is rejected, the method will continue until a successful sample is selected.

Parameters:
random - Random number generator
Returns:
Sample drawn according to the logFunction.

sample

public ArrayList<Double> sample(Random random,
                                int numSamples)
Draws samples by the adaptive rejection sampling method, which will have the distribution of the logFunction

Parameters:
random - Random number generator
numSamples - Number of samples to draw
Returns:
Samples from the adaptive rejection sampling method, which will have the distribution of the logFunction

getLogFunction

public AdaptiveRejectionSampling.LogEvaluator<?> getLogFunction()
Getter for logFunction

Returns:
Logarithm of the function that we want to evaluate

setLogFunction

public void setLogFunction(AdaptiveRejectionSampling.LogEvaluator<?> logFunction)
Setter for logFunction

Parameters:
logFunction - Logarithm of the function that we want to evaluate

getMaxNumPoints

public int getMaxNumPoints()
Getter for maxNumPoints

Returns:
Maximum number of points that will be stored

setMaxNumPoints

public void setMaxNumPoints(int maxNumPoints)
Setter for maxNumPoints

Parameters:
maxNumPoints - Maximum number of points that will be stored

getMinSupport

public double getMinSupport()
Getter for minSupport

Returns:
Minimum support (x-value) of the logFunction

setMinSupport

public void setMinSupport(double minSupport)
Setter for minSupport

Parameters:
minSupport - Minimum support (x-value) of the logFunction

getMaxSupport

public double getMaxSupport()
Getter for maxSupport

Returns:
Maximum support (x-value) of the logFunction

setMaxSupport

public void setMaxSupport(double maxSupport)
Setter for maxSupport

Parameters:
maxSupport - Maximum support (x-value) of the logFunction