gov.sandia.cognition.algorithm
Class AnytimeAlgorithmWrapper<ResultType,InternalAlgorithm extends AnytimeAlgorithm<?>>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.algorithm.AbstractIterativeAlgorithm
          extended by gov.sandia.cognition.algorithm.AnytimeAlgorithmWrapper<ResultType,InternalAlgorithm>
Type Parameters:
ResultType - Result type of the algorithm.
InternalAlgorithm - Internal algorithm to wrap.
All Implemented Interfaces:
AnytimeAlgorithm<ResultType>, IterativeAlgorithm, IterativeAlgorithmListener, StoppableAlgorithm, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
AbstractMinimizerBasedParameterCostMinimizer, DirichletProcessClustering, DistributionParameterEstimator, GaussianContextRecognizer.Learner, MinimizerBasedRootFinder, MixtureOfGaussians.Learner

public abstract class AnytimeAlgorithmWrapper<ResultType,InternalAlgorithm extends AnytimeAlgorithm<?>>
extends AbstractIterativeAlgorithm
implements AnytimeAlgorithm<ResultType>, IterativeAlgorithmListener

Wraps an AnytimeAlgorithm. This allows the creation of an AnytimeAlgorithm while using another AnytimeAlgorithm as a wrapped "workhorse" algorithm.

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

Field Summary
 
Fields inherited from class gov.sandia.cognition.algorithm.AbstractIterativeAlgorithm
DEFAULT_ITERATION, iteration
 
Constructor Summary
AnytimeAlgorithmWrapper()
          Creates a new instance of AnytimeAlgorithmWrapper
AnytimeAlgorithmWrapper(InternalAlgorithm algorithm)
          Creates a new instance of AnytimeAlgorithmWrapper
 
Method Summary
 void algorithmEnded(IterativeAlgorithm algorithm)
          This method is called when the algorithm has ended, after the last step of the algorithm.
 void algorithmStarted(IterativeAlgorithm algorithm)
          This method is called when a algorithm has started, before the first step of the algorithm.
 AnytimeAlgorithmWrapper<ResultType,InternalAlgorithm> clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 InternalAlgorithm getAlgorithm()
          Gets the underlying wrapped algorithm.
 int getIteration()
          Gets the current number of iterations executed by this algorithm since its it was started.
 int getMaxIterations()
          Gets the maximum number of total iterations before stopping.
 boolean isResultValid()
          Indicates whether or not the algorithm results are in a consistent state or not.
protected  Object readResolve()
          This method is detected by the Java Serialization code and is called on deserialization.
 void setAlgorithm(InternalAlgorithm algorithm)
          Sets the underlying algorithm.
 void setMaxIterations(int maxIterations)
          Sets the maximum number of total iterations before stopping.
 void stepEnded(IterativeAlgorithm algorithm)
          This method is called when the algorithm has ended a step of its execution.
 void stepStarted(IterativeAlgorithm algorithm)
          This method is called when the algorithm has started a step in its execution.
 void stop()
          Requests that the algorithm stop at the next appropriate point.
 
Methods inherited from class gov.sandia.cognition.algorithm.AbstractIterativeAlgorithm
addIterativeAlgorithmListener, fireAlgorithmEnded, fireAlgorithmStarted, fireStepEnded, fireStepStarted, 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
getResult
 
Methods inherited from interface gov.sandia.cognition.algorithm.IterativeAlgorithm
addIterativeAlgorithmListener, removeIterativeAlgorithmListener
 

Constructor Detail

AnytimeAlgorithmWrapper

public AnytimeAlgorithmWrapper()
Creates a new instance of AnytimeAlgorithmWrapper


AnytimeAlgorithmWrapper

public AnytimeAlgorithmWrapper(InternalAlgorithm algorithm)
Creates a new instance of AnytimeAlgorithmWrapper

Parameters:
algorithm - Underlying algorithm to wrap.
Method Detail

clone

public AnytimeAlgorithmWrapper<ResultType,InternalAlgorithm> 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.

getMaxIterations

public int getMaxIterations()
Description copied from interface: AnytimeAlgorithm
Gets the maximum number of total iterations before stopping.

Specified by:
getMaxIterations in interface AnytimeAlgorithm<ResultType>
Returns:
Maximum number of total iterations before stopping. Must be greater than zero.

setMaxIterations

public void setMaxIterations(int maxIterations)
Description copied from interface: AnytimeAlgorithm
Sets the maximum number of total iterations before stopping.

Specified by:
setMaxIterations in interface AnytimeAlgorithm<ResultType>
Parameters:
maxIterations - Maximum number of iterations before stopping. Must be greater than zero.

getAlgorithm

public InternalAlgorithm getAlgorithm()
Gets the underlying wrapped algorithm.

Returns:
The underlying algorithm being wrapped.

setAlgorithm

public void setAlgorithm(InternalAlgorithm algorithm)
Sets the underlying algorithm.

Parameters:
algorithm - The underlying algorithm to wrap.

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

getIteration

public int getIteration()
Description copied from interface: IterativeAlgorithm
Gets the current number of iterations executed by this algorithm since its it was started.

Specified by:
getIteration in interface IterativeAlgorithm
Overrides:
getIteration in class AbstractIterativeAlgorithm
Returns:
Current number of iterations executed by this algorithm.

isResultValid

public boolean isResultValid()
Description copied from interface: StoppableAlgorithm
Indicates whether or not the algorithm results are in a consistent state or not. A StoppableAlgorithm may not always be able to stop in a manner that makes its results valid. This method is used to check whether the results are in a consistent state or not.

Specified by:
isResultValid in interface StoppableAlgorithm
Returns:
True if the results of the algorithm are in valid state and false if they are not valid.

algorithmStarted

public void algorithmStarted(IterativeAlgorithm algorithm)
Description copied from interface: IterativeAlgorithmListener
This method is called when a algorithm has started, before the first step of the algorithm.

Specified by:
algorithmStarted in interface IterativeAlgorithmListener
Parameters:
algorithm - The algorithm that has started.

algorithmEnded

public void algorithmEnded(IterativeAlgorithm algorithm)
Description copied from interface: IterativeAlgorithmListener
This method is called when the algorithm has ended, after the last step of the algorithm.

Specified by:
algorithmEnded in interface IterativeAlgorithmListener
Parameters:
algorithm - The algorithm that has ended.

stepStarted

public void stepStarted(IterativeAlgorithm algorithm)
Description copied from interface: IterativeAlgorithmListener
This method is called when the algorithm has started a step in its execution.

Specified by:
stepStarted in interface IterativeAlgorithmListener
Parameters:
algorithm - The algorithm that has started another step of its execution.

stepEnded

public void stepEnded(IterativeAlgorithm algorithm)
Description copied from interface: IterativeAlgorithmListener
This method is called when the algorithm has ended a step of its execution.

Specified by:
stepEnded in interface IterativeAlgorithmListener
Parameters:
algorithm - The algorithm that has ended another step of its execution.

readResolve

protected Object readResolve()
This method is detected by the Java Serialization code and is called on deserialization. It allows the object to deal with transient values.

Returns:
Returns this.