@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
| Modifier and Type | Class and Description |
|---|---|
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<java.lang.Double,java.lang.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.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_MAX_NUM_POINTS
Default number of points, 50.
|
| Constructor and Description |
|---|
AdaptiveRejectionSampling()
Creates a new instance of AdaptiveRejectionSampling
|
| Modifier and Type | Method and Description |
|---|---|
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 java.util.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(java.util.Random random)
Draws a single sample by the method of adaptive rejection sampling.
|
java.util.ArrayList<java.lang.Double> |
sample(java.util.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
|
public static final int DEFAULT_MAX_NUM_POINTS
public AdaptiveRejectionSampling()
public AdaptiveRejectionSampling clone()
AbstractCloneableSerializableObject 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.clone in interface CloneableSerializableclone in class AbstractCloneableSerializablepublic void initialize(AdaptiveRejectionSampling.LogEvaluator<?> logFunction, double minSupport, double maxSupport, double leftPoint, double midPoint, double rightPoint)
logFunction - Logarithm of the evaluator to considerminSupport - Minimum support (x-axis) of the evaluatormaxSupport - Maximum support (x-axis) of the evaluatorleftPoint - Left point to initializemidPoint - Mid point to initialize withrightPoint - Right point to initialize withpublic void addPoint(double x,
double y)
x - X-axis valuey - Y-axis value from the logFunctionpublic int getNumPoints()
protected java.util.Collection<AdaptiveRejectionSampling.Point> getPoints()
public double sample(java.util.Random random)
random - Random number generatorpublic java.util.ArrayList<java.lang.Double> sample(java.util.Random random,
int numSamples)
random - Random number generatornumSamples - Number of samples to drawpublic AdaptiveRejectionSampling.LogEvaluator<?> getLogFunction()
public void setLogFunction(AdaptiveRejectionSampling.LogEvaluator<?> logFunction)
logFunction - Logarithm of the function that we want to evaluatepublic int getMaxNumPoints()
public void setMaxNumPoints(int maxNumPoints)
maxNumPoints - Maximum number of points that will be storedpublic double getMinSupport()
public void setMinSupport(double minSupport)
minSupport - Minimum support (x-value) of the logFunctionpublic double getMaxSupport()
public void setMaxSupport(double maxSupport)
maxSupport - Maximum support (x-value) of the logFunction