gov.sandia.cognition.statistics.bayesian
Class AbstractMarkovChainMonteCarlo<ObservationType,ParameterType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.algorithm.AbstractIterativeAlgorithm
          extended by gov.sandia.cognition.algorithm.AbstractAnytimeAlgorithm<ResultType>
              extended by gov.sandia.cognition.learning.algorithm.AbstractAnytimeBatchLearner<Collection<? extends ObservationType>,DataDistribution<ParameterType>>
                  extended by gov.sandia.cognition.statistics.bayesian.AbstractMarkovChainMonteCarlo<ObservationType,ParameterType>
Type Parameters:
ObservationType - Type of observations handled by the MCMC algorithm.
ParameterType - Type of parameters to infer.
All Implemented Interfaces:
AnytimeAlgorithm<DataDistribution<ParameterType>>, IterativeAlgorithm, StoppableAlgorithm, AnytimeBatchLearner<Collection<? extends ObservationType>,DataDistribution<ParameterType>>, BatchLearner<Collection<? extends ObservationType>,DataDistribution<ParameterType>>, BayesianEstimator<ObservationType,ParameterType,DataDistribution<ParameterType>>, MarkovChainMonteCarlo<ObservationType,ParameterType>, CloneableSerializable, Randomized, Serializable, Cloneable
Direct Known Subclasses:
DirichletProcessMixtureModel, MetropolisHastingsAlgorithm

public abstract class AbstractMarkovChainMonteCarlo<ObservationType,ParameterType>
extends AbstractAnytimeBatchLearner<Collection<? extends ObservationType>,DataDistribution<ParameterType>>
implements MarkovChainMonteCarlo<ObservationType,ParameterType>

Partial abstract implementation of MarkovChainMonteCarlo.

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

Field Summary
protected  ParameterType currentParameter
          The current parameters in the random walk.
static int DEFAULT_NUM_SAMPLES
          Default number of sample/iterations, 1000.
protected  ParameterType previousParameter
          The previous parameter in the random walk.
protected  Random random
          Random number generator.
 
Fields inherited from class gov.sandia.cognition.learning.algorithm.AbstractAnytimeBatchLearner
data, keepGoing
 
Fields inherited from class gov.sandia.cognition.algorithm.AbstractAnytimeAlgorithm
maxIterations
 
Fields inherited from class gov.sandia.cognition.algorithm.AbstractIterativeAlgorithm
DEFAULT_ITERATION, iteration
 
Constructor Summary
AbstractMarkovChainMonteCarlo()
          Creates a new instance of AbstractMarkovChainMonteCarlo
 
Method Summary
protected  void cleanupAlgorithm()
          Called to clean up the learning algorithm's state after learning has finished.
 AbstractMarkovChainMonteCarlo<ObservationType,ParameterType> clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
abstract  ParameterType createInitialLearnedObject()
          Creates the initial parameters from which to start the Markov chain.
 int getBurnInIterations()
          Gets the number of iterations that must transpire before the algorithm begins collection the samples.
 ParameterType getCurrentParameter()
          Gets the current parameters in the random walk.
 int getIterationsPerSample()
          Gets the number of iterations that must transpire between capturing samples from the distribution.
 ParameterType getPreviousParameter()
          Getter for previousParameter
 Random getRandom()
          Gets the random number generator used by this object.
 DefaultDataDistribution<ParameterType> getResult()
          Gets the current result of the algorithm.
protected  boolean initializeAlgorithm()
          Called to initialize the learning algorithm's state based on the data that is stored in the data field.
protected abstract  void mcmcUpdate()
          Performs a valid MCMC update step.
 void setBurnInIterations(int burnInIterations)
          Sets the number of iterations that must transpire before the algorithm begins collection the samples.
protected  void setCurrentParameter(ParameterType currentParameter)
          Setter for currentParameter.
 void setIterationsPerSample(int iterationsPerSample)
          Sets the number of iterations that must transpire between capturing samples from the distribution.
 void setRandom(Random random)
          Sets the random number generator used by this object.
protected  void setResult(DefaultDataDistribution<ParameterType> result)
          Setter for result
protected  boolean step()
          Called to take a single step of the learning algorithm.
 
Methods inherited from class gov.sandia.cognition.learning.algorithm.AbstractAnytimeBatchLearner
getData, getKeepGoing, learn, setData, setKeepGoing, stop
 
Methods inherited from class gov.sandia.cognition.algorithm.AbstractAnytimeAlgorithm
getMaxIterations, isResultValid, setMaxIterations
 
Methods inherited from class gov.sandia.cognition.algorithm.AbstractIterativeAlgorithm
addIterativeAlgorithmListener, fireAlgorithmEnded, fireAlgorithmStarted, fireStepEnded, fireStepStarted, getIteration, getListeners, removeIterativeAlgorithmListener, setIteration, setListeners
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.learning.algorithm.BatchLearner
learn
 
Methods inherited from interface gov.sandia.cognition.algorithm.AnytimeAlgorithm
getMaxIterations, setMaxIterations
 
Methods inherited from interface gov.sandia.cognition.algorithm.IterativeAlgorithm
addIterativeAlgorithmListener, getIteration, removeIterativeAlgorithmListener
 
Methods inherited from interface gov.sandia.cognition.algorithm.StoppableAlgorithm
isResultValid, stop
 

Field Detail

DEFAULT_NUM_SAMPLES

public static final int DEFAULT_NUM_SAMPLES
Default number of sample/iterations, 1000.

See Also:
Constant Field Values

random

protected Random random
Random number generator.


currentParameter

protected ParameterType currentParameter
The current parameters in the random walk.


previousParameter

protected ParameterType previousParameter
The previous parameter in the random walk.

Constructor Detail

AbstractMarkovChainMonteCarlo

public AbstractMarkovChainMonteCarlo()
Creates a new instance of AbstractMarkovChainMonteCarlo

Method Detail

clone

public AbstractMarkovChainMonteCarlo<ObservationType,ParameterType> 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 AbstractAnytimeBatchLearner<Collection<? extends ObservationType>,DataDistribution<ParameterType>>
Returns:
A clone of this object.

getBurnInIterations

public int getBurnInIterations()
Description copied from interface: MarkovChainMonteCarlo
Gets the number of iterations that must transpire before the algorithm begins collection the samples.

Specified by:
getBurnInIterations in interface MarkovChainMonteCarlo<ObservationType,ParameterType>
Returns:
The number of iterations that must transpire before the algorithm begins collection the samples.

setBurnInIterations

public void setBurnInIterations(int burnInIterations)
Description copied from interface: MarkovChainMonteCarlo
Sets the number of iterations that must transpire before the algorithm begins collection the samples.

Specified by:
setBurnInIterations in interface MarkovChainMonteCarlo<ObservationType,ParameterType>
Parameters:
burnInIterations - The number of iterations that must transpire before the algorithm begins collection the samples.

getIterationsPerSample

public int getIterationsPerSample()
Description copied from interface: MarkovChainMonteCarlo
Gets the number of iterations that must transpire between capturing samples from the distribution.

Specified by:
getIterationsPerSample in interface MarkovChainMonteCarlo<ObservationType,ParameterType>
Returns:
The number of iterations that must transpire between capturing samples from the distribution.

setIterationsPerSample

public void setIterationsPerSample(int iterationsPerSample)
Description copied from interface: MarkovChainMonteCarlo
Sets the number of iterations that must transpire between capturing samples from the distribution.

Specified by:
setIterationsPerSample in interface MarkovChainMonteCarlo<ObservationType,ParameterType>
Parameters:
iterationsPerSample - The number of iterations that must transpire between capturing samples from the distribution.

getResult

public DefaultDataDistribution<ParameterType> getResult()
Description copied from interface: AnytimeAlgorithm
Gets the current result of the algorithm.

Specified by:
getResult in interface AnytimeAlgorithm<DataDistribution<ParameterType>>
Returns:
Current result of the algorithm.

setResult

protected void setResult(DefaultDataDistribution<ParameterType> result)
Setter for result

Parameters:
result - Results to return.

getCurrentParameter

public ParameterType getCurrentParameter()
Description copied from interface: MarkovChainMonteCarlo
Gets the current parameters in the random walk.

Specified by:
getCurrentParameter in interface MarkovChainMonteCarlo<ObservationType,ParameterType>
Returns:
The current parameters in the random walk.

setCurrentParameter

protected void setCurrentParameter(ParameterType currentParameter)
Setter for currentParameter.

Parameters:
currentParameter - The current location in the random walk.

getRandom

public Random getRandom()
Description copied from interface: Randomized
Gets the random number generator used by this object.

Specified by:
getRandom in interface Randomized
Returns:
The random number generator used by this object.

setRandom

public void setRandom(Random random)
Description copied from interface: Randomized
Sets the random number generator used by this object.

Specified by:
setRandom in interface Randomized
Parameters:
random - The random number generator for this object to use.

mcmcUpdate

protected abstract void mcmcUpdate()
Performs a valid MCMC update step. That is, the function is expected to modify the currentParameter member.


createInitialLearnedObject

public abstract ParameterType createInitialLearnedObject()
Creates the initial parameters from which to start the Markov chain.

Returns:
initial parameters from which to start the Markov chain.

initializeAlgorithm

protected boolean initializeAlgorithm()
Description copied from class: AbstractAnytimeBatchLearner
Called to initialize the learning algorithm's state based on the data that is stored in the data field. The return value indicates if the algorithm can be run or not based on the initialization.

Specified by:
initializeAlgorithm in class AbstractAnytimeBatchLearner<Collection<? extends ObservationType>,DataDistribution<ParameterType>>
Returns:
True if the learning algorithm can be run and false if it cannot.

step

protected boolean step()
Description copied from class: AbstractAnytimeBatchLearner
Called to take a single step of the learning algorithm.

Specified by:
step in class AbstractAnytimeBatchLearner<Collection<? extends ObservationType>,DataDistribution<ParameterType>>
Returns:
True if another step can be taken and false it the algorithm should halt.

cleanupAlgorithm

protected void cleanupAlgorithm()
Description copied from class: AbstractAnytimeBatchLearner
Called to clean up the learning algorithm's state after learning has finished.

Specified by:
cleanupAlgorithm in class AbstractAnytimeBatchLearner<Collection<? extends ObservationType>,DataDistribution<ParameterType>>

getPreviousParameter

public ParameterType getPreviousParameter()
Getter for previousParameter

Returns:
The previous parameter in the random walk.