ObservationType
- Type of observations handled by the MCMC algorithm.ParameterType
- Type of parameters to infer.public abstract class AbstractMarkovChainMonteCarlo<ObservationType,ParameterType> extends AbstractAnytimeBatchLearner<java.util.Collection<? extends ObservationType>,DataDistribution<ParameterType>> implements MarkovChainMonteCarlo<ObservationType,ParameterType>
Modifier and Type | Field and Description |
---|---|
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 java.util.Random |
random
Random number generator.
|
data, keepGoing
maxIterations
DEFAULT_ITERATION, iteration
Constructor and Description |
---|
AbstractMarkovChainMonteCarlo()
Creates a new instance of AbstractMarkovChainMonteCarlo
|
Modifier and Type | Method and Description |
---|---|
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
|
java.util.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(java.util.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.
|
getData, getKeepGoing, learn, setData, setKeepGoing, stop
getMaxIterations, isResultValid, setMaxIterations
addIterativeAlgorithmListener, fireAlgorithmEnded, fireAlgorithmStarted, fireStepEnded, fireStepStarted, getIteration, getListeners, removeIterativeAlgorithmListener, setIteration, setListeners
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
learn
getMaxIterations, setMaxIterations
addIterativeAlgorithmListener, getIteration, removeIterativeAlgorithmListener
isResultValid, stop
public static final int DEFAULT_NUM_SAMPLES
protected java.util.Random random
protected ParameterType currentParameter
protected ParameterType previousParameter
public AbstractMarkovChainMonteCarlo()
public AbstractMarkovChainMonteCarlo<ObservationType,ParameterType> clone()
AbstractCloneableSerializable
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.clone
in interface CloneableSerializable
clone
in class AbstractAnytimeBatchLearner<java.util.Collection<? extends ObservationType>,DataDistribution<ParameterType>>
public int getBurnInIterations()
MarkovChainMonteCarlo
getBurnInIterations
in interface MarkovChainMonteCarlo<ObservationType,ParameterType>
public void setBurnInIterations(int burnInIterations)
MarkovChainMonteCarlo
setBurnInIterations
in interface MarkovChainMonteCarlo<ObservationType,ParameterType>
burnInIterations
- The number of iterations that must transpire before the algorithm
begins collection the samples.public int getIterationsPerSample()
MarkovChainMonteCarlo
getIterationsPerSample
in interface MarkovChainMonteCarlo<ObservationType,ParameterType>
public void setIterationsPerSample(int iterationsPerSample)
MarkovChainMonteCarlo
setIterationsPerSample
in interface MarkovChainMonteCarlo<ObservationType,ParameterType>
iterationsPerSample
- The number of iterations that must transpire between capturing
samples from the distribution.public DefaultDataDistribution<ParameterType> getResult()
AnytimeAlgorithm
getResult
in interface AnytimeAlgorithm<DataDistribution<ParameterType>>
protected void setResult(DefaultDataDistribution<ParameterType> result)
result
- Results to return.public ParameterType getCurrentParameter()
MarkovChainMonteCarlo
getCurrentParameter
in interface MarkovChainMonteCarlo<ObservationType,ParameterType>
protected void setCurrentParameter(ParameterType currentParameter)
currentParameter
- The current location in the random walk.public java.util.Random getRandom()
Randomized
getRandom
in interface Randomized
public void setRandom(java.util.Random random)
Randomized
setRandom
in interface Randomized
random
- The random number generator for this object to use.protected abstract void mcmcUpdate()
public abstract ParameterType createInitialLearnedObject()
protected boolean initializeAlgorithm()
AbstractAnytimeBatchLearner
initializeAlgorithm
in class AbstractAnytimeBatchLearner<java.util.Collection<? extends ObservationType>,DataDistribution<ParameterType>>
protected boolean step()
AbstractAnytimeBatchLearner
step
in class AbstractAnytimeBatchLearner<java.util.Collection<? extends ObservationType>,DataDistribution<ParameterType>>
protected void cleanupAlgorithm()
AbstractAnytimeBatchLearner
cleanupAlgorithm
in class AbstractAnytimeBatchLearner<java.util.Collection<? extends ObservationType>,DataDistribution<ParameterType>>
public ParameterType getPreviousParameter()