gov.sandia.cognition.statistics.bayesian
Class MetropolisHastingsAlgorithm<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>
                      extended by gov.sandia.cognition.statistics.bayesian.MetropolisHastingsAlgorithm<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, MeasurablePerformanceAlgorithm, 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

@PublicationReference(author="Wikipedia",
                      title="Metropolis\u2013Hastings algorithm",
                      type=WebPage,
                      year=2009,
                      url="http://en.wikipedia.org/wiki/Metropolis-Hastings_algorithm")
public class MetropolisHastingsAlgorithm<ObservationType,ParameterType>
extends AbstractMarkovChainMonteCarlo<ObservationType,ParameterType>
implements MeasurablePerformanceAlgorithm

An implementation of the Metropolis-Hastings MCMC algorithm, which is the most general formulation of MCMC but can be slow.

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

Nested Class Summary
static interface MetropolisHastingsAlgorithm.Updater<ObservationType,ParameterType>
          Creates proposals for the MCMC steps.
 
Field Summary
static String PERFORMANCE_NAME
          Performance statistic name, "Current Log Likelihood".
protected  MetropolisHastingsAlgorithm.Updater<ObservationType,ParameterType> updater
          The object that makes proposal samples from the current location.
 
Fields inherited from class gov.sandia.cognition.statistics.bayesian.AbstractMarkovChainMonteCarlo
currentParameter, DEFAULT_NUM_SAMPLES, previousParameter, random
 
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
MetropolisHastingsAlgorithm()
          Creates a new instance of MetropolisHastingsAlgorithm.
 
Method Summary
 MetropolisHastingsAlgorithm<ObservationType,ParameterType> clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 ParameterType createInitialLearnedObject()
          Creates the initial parameters from which to start the Markov chain.
 NamedValue<Double> getPerformance()
          Gets the name-value pair that describes the current performance of the algorithm.
 MetropolisHastingsAlgorithm.Updater<ObservationType,ParameterType> getUpdater()
          Gets the object that makes proposal samples from the current location.
protected  boolean initializeAlgorithm()
          Called to initialize the learning algorithm's state based on the data that is stored in the data field.
protected  void mcmcUpdate()
          Performs a valid MCMC update step.
 void setUpdater(MetropolisHastingsAlgorithm.Updater<ObservationType,ParameterType> updater)
          Sets the object that makes proposal samples from the current location.
 
Methods inherited from class gov.sandia.cognition.statistics.bayesian.AbstractMarkovChainMonteCarlo
cleanupAlgorithm, getBurnInIterations, getCurrentParameter, getIterationsPerSample, getPreviousParameter, getRandom, getResult, setBurnInIterations, setCurrentParameter, setIterationsPerSample, setRandom, setResult, step
 
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

PERFORMANCE_NAME

public static final String PERFORMANCE_NAME
Performance statistic name, "Current Log Likelihood".

See Also:
Constant Field Values

updater

protected MetropolisHastingsAlgorithm.Updater<ObservationType,ParameterType> updater
The object that makes proposal samples from the current location.

Constructor Detail

MetropolisHastingsAlgorithm

public MetropolisHastingsAlgorithm()
Creates a new instance of MetropolisHastingsAlgorithm.

Method Detail

clone

public MetropolisHastingsAlgorithm<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 AbstractMarkovChainMonteCarlo<ObservationType,ParameterType>
Returns:
A clone of this object.

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.

Overrides:
initializeAlgorithm in class AbstractMarkovChainMonteCarlo<ObservationType,ParameterType>
Returns:
True if the learning algorithm can be run and false if it cannot.

mcmcUpdate

protected void mcmcUpdate()
Description copied from class: AbstractMarkovChainMonteCarlo
Performs a valid MCMC update step. That is, the function is expected to modify the currentParameter member.

Specified by:
mcmcUpdate in class AbstractMarkovChainMonteCarlo<ObservationType,ParameterType>

getPerformance

public NamedValue<Double> getPerformance()
Description copied from interface: MeasurablePerformanceAlgorithm
Gets the name-value pair that describes the current performance of the algorithm. For most algorithms, this is the value that they are attempting to optimize.

Specified by:
getPerformance in interface MeasurablePerformanceAlgorithm
Returns:
The name-value pair that describes the current performance of the algorithm.

getUpdater

public MetropolisHastingsAlgorithm.Updater<ObservationType,ParameterType> getUpdater()
Gets the object that makes proposal samples from the current location.

Returns:
The object that makes proposal samples from the current location.

setUpdater

public void setUpdater(MetropolisHastingsAlgorithm.Updater<ObservationType,ParameterType> updater)
Sets the object that makes proposal samples from the current location.

Parameters:
updater - The object that makes proposal samples from the current location.

createInitialLearnedObject

public ParameterType createInitialLearnedObject()
Description copied from class: AbstractMarkovChainMonteCarlo
Creates the initial parameters from which to start the Markov chain.

Specified by:
createInitialLearnedObject in class AbstractMarkovChainMonteCarlo<ObservationType,ParameterType>
Returns:
initial parameters from which to start the Markov chain.