gov.sandia.cognition.algorithm
Class AbstractIterativeAlgorithm

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.algorithm.AbstractIterativeAlgorithm
All Implemented Interfaces:
IterativeAlgorithm, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
AbstractAnytimeAlgorithm, AbstractDecisionTreeLearner, AnytimeAlgorithmWrapper

@CodeReviews(reviews={@CodeReview(reviewer="Kevin R. Dixon",date="2008-02-08",changesNeeded=false,comments="Class looks fine."),@CodeReview(reviewer="Justin Basilico",date="2006-10-02",changesNeeded=false,comments="Interface is fine.")})
public abstract class AbstractIterativeAlgorithm
extends AbstractCloneableSerializable
implements IterativeAlgorithm

The AbstractIterativeAlgorithm class implements a simple part of the IterativeAlgorithm interface that manages the listeners for the algorithm. It contains methods for firing off the various learning events.

Since:
2.0
Author:
Justin Basilico
See Also:
IterativeAlgorithm, Serialized Form

Field Summary
static int DEFAULT_ITERATION
          The default iteration number is zero.
protected  int iteration
          Number of iterations the algorithm has executed.
 
Constructor Summary
AbstractIterativeAlgorithm()
          Creates a new instance of AbstractIterativeAlgorithm.
AbstractIterativeAlgorithm(int iteration)
          Creates a new instance of AbstractIterativeAlgorithm.
 
Method Summary
 void addIterativeAlgorithmListener(IterativeAlgorithmListener listener)
          Adds a listener for the iterations of the algorithm.
 AbstractIterativeAlgorithm clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
protected  void fireAlgorithmEnded()
          Fires off a algorithm ended event for the algorithm, which notifies all the listeners that the algorithm has ended.
protected  void fireAlgorithmStarted()
          Fires off a algorithm started event for this algorithm, which notifies all of the listeners that the algorithm has started.
protected  void fireStepEnded()
          Fires off a algorithm ended event for the algorithm, which notifies all the listeners that a step has ended.
protected  void fireStepStarted()
          Fires off a algorithm started event for the algorithm, which notifies all the listeners that a step has started.
 int getIteration()
          Gets the current number of iterations executed by this algorithm since its it was started.
protected  LinkedList<IterativeAlgorithmListener> getListeners()
          Retrieves the list of listeners for this algorithm.
 void removeIterativeAlgorithmListener(IterativeAlgorithmListener listener)
          Removes a listener for the iterations of the algorithm.
protected  void setIteration(int iteration)
          Sets the current iteration number.
protected  void setListeners(LinkedList<IterativeAlgorithmListener> listeners)
          Sets the list of listeners for this algorithm.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ITERATION

public static final int DEFAULT_ITERATION
The default iteration number is zero.

See Also:
Constant Field Values

iteration

protected int iteration
Number of iterations the algorithm has executed.

Constructor Detail

AbstractIterativeAlgorithm

public AbstractIterativeAlgorithm()
Creates a new instance of AbstractIterativeAlgorithm.


AbstractIterativeAlgorithm

public AbstractIterativeAlgorithm(int iteration)
Creates a new instance of AbstractIterativeAlgorithm.

Parameters:
iteration - The initial iteration number.
Method Detail

clone

public AbstractIterativeAlgorithm 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 AbstractCloneableSerializable
Returns:
A clone of this object.

fireAlgorithmStarted

protected void fireAlgorithmStarted()
Fires off a algorithm started event for this algorithm, which notifies all of the listeners that the algorithm has started.


fireAlgorithmEnded

protected void fireAlgorithmEnded()
Fires off a algorithm ended event for the algorithm, which notifies all the listeners that the algorithm has ended.


fireStepStarted

protected void fireStepStarted()
Fires off a algorithm started event for the algorithm, which notifies all the listeners that a step has started.


fireStepEnded

protected void fireStepEnded()
Fires off a algorithm ended event for the algorithm, which notifies all the listeners that a step has ended.


addIterativeAlgorithmListener

public void addIterativeAlgorithmListener(IterativeAlgorithmListener listener)
Description copied from interface: IterativeAlgorithm
Adds a listener for the iterations of the algorithm.

Specified by:
addIterativeAlgorithmListener in interface IterativeAlgorithm
Parameters:
listener - The listener to add.

removeIterativeAlgorithmListener

public void removeIterativeAlgorithmListener(IterativeAlgorithmListener listener)
Description copied from interface: IterativeAlgorithm
Removes a listener for the iterations of the algorithm.

Specified by:
removeIterativeAlgorithmListener in interface IterativeAlgorithm
Parameters:
listener - The listener to remove.

getListeners

protected LinkedList<IterativeAlgorithmListener> getListeners()
Retrieves the list of listeners for this algorithm.

Returns:
The list of current listeners.

setListeners

protected void setListeners(LinkedList<IterativeAlgorithmListener> listeners)
Sets the list of listeners for this algorithm.

Parameters:
listeners - The new list of listeners.

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
Returns:
Current number of iterations executed by this algorithm.

setIteration

protected void setIteration(int iteration)
Sets the current iteration number.

Parameters:
iteration - Number of iterations executed in the algorithm.