gov.sandia.cognition.learning.algorithm
Class AbstractAnytimeBatchLearner<DataType,ResultType>

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<DataType,ResultType>
Type Parameters:
ResultType - The type of object created by the learning algorithm. For example, a FeedforwardNeuralNetwork.
DataType - The type of the data that the algorithm uses to perform the learning. For example, a Collection<InputOutputPair<Vector, Double>> or String.
All Implemented Interfaces:
AnytimeAlgorithm<ResultType>, IterativeAlgorithm, StoppableAlgorithm, AnytimeBatchLearner<DataType,ResultType>, BatchLearner<DataType,ResultType>, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
AbstractAnytimeFunctionMinimizer, AbstractAnytimeSupervisedBatchLearner, AbstractBaumWelchAlgorithm, AbstractMarkovChainMonteCarlo, AbstractRootFinder, AffinityPropagation, AgglomerativeClusterer, GeneralizedHebbianAlgorithm, GeneticAlgorithm, KMeansClusterer, LatentDirichletAllocationVectorGibbsSampler, MixtureOfGaussians.EMLearner, PartitionalClusterer, ProbabilisticLatentSemanticAnalysis, RootBracketExpander, ScalarMixtureDensityModel.EMLearner, SimulatedAnnealer

@CodeReview(reviewer="Kevin R. Dixon",
            date="2008-07-22",
            changesNeeded=false,
            comments={"Added some HTML formatting to the javadoc, removed useless javadoc.","Code looks fine."})
public abstract class AbstractAnytimeBatchLearner<DataType,ResultType>
extends AbstractAnytimeAlgorithm<ResultType>
implements AnytimeBatchLearner<DataType,ResultType>

The AbstractAnytimeBatchLearner abstract class implements a standard method for conforming to the BatchLearner and AnytimeLearner (IterativeAlgorithm and StoppableAlgorithm) interfaces. In doing so it implements the logic to handle the events that are fired for IterativeLearner and the method calls required for StoppableAlgorithm inside of the learn method for the BatchLearner interface. This means that classes that extend this abstract class can focus on the implementation of the logic of the learning algorithm and get conformance to these useful interfaces without any real effort.

Classes that extend this class must implement the following methods:



The general design pattern for this class that implementing classes should follow is to store all of the main state information of the algorithm as fields so that each of the different methods listed above will modify the state of the algorithm.

Since:
2.0
Author:
Justin Basilico, Kevin R. Dixon
See Also:
Serialized Form

Field Summary
protected  DataType data
          The data to learn from.
protected  boolean keepGoing
          Indicates whether or not the learner should make another step.
 
Fields inherited from class gov.sandia.cognition.algorithm.AbstractAnytimeAlgorithm
maxIterations
 
Fields inherited from class gov.sandia.cognition.algorithm.AbstractIterativeAlgorithm
DEFAULT_ITERATION, iteration
 
Constructor Summary
protected AbstractAnytimeBatchLearner(int maxIterations)
          Creates a new instance of AbstractAnytimeBatchLearner.
 
Method Summary
protected abstract  void cleanupAlgorithm()
          Called to clean up the learning algorithm's state after learning has finished.
 AbstractAnytimeBatchLearner<DataType,ResultType> clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 DataType getData()
          Gets the data to use for learning.
 boolean getKeepGoing()
          Gets the keep going value, which indicates if the algorithm should continue on to another step.
protected abstract  boolean initializeAlgorithm()
          Called to initialize the learning algorithm's state based on the data that is stored in the data field.
 ResultType learn(DataType data)
          The learn method creates an object of ResultType using data of type DataType, using some form of "learning" algorithm.
protected  void setData(DataType data)
          Gets the data to use for learning.
 void setKeepGoing(boolean keepGoing)
          Sets the keep going value, which indicates if the algorithm should continue on to another step.
protected abstract  boolean step()
          Called to take a single step of the learning algorithm.
 void stop()
          Requests that the algorithm stop at the next appropriate point.
 
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.algorithm.AnytimeAlgorithm
getMaxIterations, getResult, setMaxIterations
 
Methods inherited from interface gov.sandia.cognition.algorithm.IterativeAlgorithm
addIterativeAlgorithmListener, getIteration, removeIterativeAlgorithmListener
 
Methods inherited from interface gov.sandia.cognition.algorithm.StoppableAlgorithm
isResultValid
 

Field Detail

keepGoing

protected boolean keepGoing
Indicates whether or not the learner should make another step.


data

protected DataType data
The data to learn from.

Constructor Detail

AbstractAnytimeBatchLearner

protected AbstractAnytimeBatchLearner(int maxIterations)
Creates a new instance of AbstractAnytimeBatchLearner.

Parameters:
maxIterations - The maximum number of iterations, must be greater than zero.
Method Detail

clone

public AbstractAnytimeBatchLearner<DataType,ResultType> 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 AbstractIterativeAlgorithm
Returns:
A clone of this object.

learn

public ResultType learn(DataType data)
Description copied from interface: BatchLearner
The learn method creates an object of ResultType using data of type DataType, using some form of "learning" algorithm.

Specified by:
learn in interface BatchLearner<DataType,ResultType>
Parameters:
data - The data that the learning algorithm will use to create an object of ResultType.
Returns:
The object that is created based on the given data using the learning algorithm.

initializeAlgorithm

protected abstract boolean initializeAlgorithm()
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.

Returns:
True if the learning algorithm can be run and false if it cannot.

step

protected abstract boolean step()
Called to take a single step of the learning algorithm.

Returns:
True if another step can be taken and false it the algorithm should halt.

cleanupAlgorithm

protected abstract void cleanupAlgorithm()
Called to clean up the learning algorithm's state after learning has finished.


stop

public void stop()
Description copied from interface: StoppableAlgorithm
Requests that the algorithm stop at the next appropriate point. The stopping point is determined by the algorithm. The algorithm should try to balance between stopping as soon as possible and leaving the results in some consistent state.

Specified by:
stop in interface StoppableAlgorithm

getKeepGoing

public boolean getKeepGoing()
Description copied from interface: AnytimeBatchLearner
Gets the keep going value, which indicates if the algorithm should continue on to another step.

Specified by:
getKeepGoing in interface AnytimeBatchLearner<DataType,ResultType>
Returns:
The keep going value.

setKeepGoing

public void setKeepGoing(boolean keepGoing)
Sets the keep going value, which indicates if the algorithm should continue on to another step.

Parameters:
keepGoing - The keep going value.

getData

public DataType getData()
Description copied from interface: AnytimeBatchLearner
Gets the data to use for learning. This is set when learning starts and then cleared out once learning is finished.

Specified by:
getData in interface AnytimeBatchLearner<DataType,ResultType>
Returns:
The data to use for learning.

setData

protected void setData(DataType data)
Gets the data to use for learning. This is set when learning starts and then cleared out once learning is finished.

Parameters:
data - The data to use for learning.