gov.sandia.cognition.learning.algorithm.ensemble
Class AdaBoost<InputType>

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 InputOutputPair<? extends InputType,OutputType>>,ResultType>
                  extended by gov.sandia.cognition.learning.algorithm.AbstractAnytimeSupervisedBatchLearner<InputType,Boolean,WeightedBinaryEnsemble<InputType,Evaluator<? super InputType,? extends Boolean>>>
                      extended by gov.sandia.cognition.learning.algorithm.ensemble.AdaBoost<InputType>
Type Parameters:
InputType - The algorithm operates on a Collection<InputOutputPair<InputType,Boolean>>. The InputType will be something like Vector or String.
All Implemented Interfaces:
AnytimeAlgorithm<WeightedBinaryEnsemble<InputType,Evaluator<? super InputType,? extends Boolean>>>, IterativeAlgorithm, StoppableAlgorithm, AnytimeBatchLearner<Collection<? extends InputOutputPair<? extends InputType,Boolean>>,WeightedBinaryEnsemble<InputType,Evaluator<? super InputType,? extends Boolean>>>, BatchLearner<Collection<? extends InputOutputPair<? extends InputType,Boolean>>,WeightedBinaryEnsemble<InputType,Evaluator<? super InputType,? extends Boolean>>>, BatchLearnerContainer<BatchLearner<? super Collection<? extends InputOutputPair<? extends InputType,Boolean>>,? extends Evaluator<? super InputType,? extends Boolean>>>, SupervisedBatchLearner<InputType,Boolean,WeightedBinaryEnsemble<InputType,Evaluator<? super InputType,? extends Boolean>>>, CloneableSerializable, Serializable, Cloneable

@CodeReview(reviewer="Kevin R. Dixon",
            date="2008-07-23",
            changesNeeded=false,
            comments={"Added PublicationReference","Cleaned up javadoc a little bit with code annotations.","Otherwise, looks fine."})
@PublicationReference(author={"Yoav Freund","Robert E.Schapire"},
                      title="A decision-theoretic generalization of on-line learning and an application to boosting",
                      publication="Journal of Computer and System Sciences",
                      notes="Volume 55, Number 1",
                      year=1997,
                      pages={119,139},
                      type=Journal,
                      url="http://www.cse.ucsd.edu/~yfreund/papers/adaboost.pdf")
public class AdaBoost<InputType>
extends AbstractAnytimeSupervisedBatchLearner<InputType,Boolean,WeightedBinaryEnsemble<InputType,Evaluator<? super InputType,? extends Boolean>>>
implements BatchLearnerContainer<BatchLearner<? super Collection<? extends InputOutputPair<? extends InputType,Boolean>>,? extends Evaluator<? super InputType,? extends Boolean>>>

The AdaBoost class implements the Adaptive Boosting (AdaBoost) algorithm formulated by Yoav Freund and Robert Shapire. It creates a weighted binary ensemble as output from the algorithm.

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

Field Summary
static int DEFAULT_MAX_ITERATIONS
          The default maximum number of iterations is 100.
protected  WeightedBinaryEnsemble<InputType,Evaluator<? super InputType,? extends Boolean>> ensemble
          The ensemble learned by the algorithm.
protected  BatchLearner<? super Collection<? extends InputOutputPair<? extends InputType,Boolean>>,? extends Evaluator<? super InputType,? extends Boolean>> weakLearner
          The "weak learner" that must learn from the weighted input-output pairs on each iteration.
protected  ArrayList<DefaultWeightedInputOutputPair<InputType,Boolean>> weightedData
          An array list containing the weighted version of the data.
 
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
AdaBoost()
          Creates a new instance of AdaBoost with no base learner.
AdaBoost(BatchLearner<? super Collection<? extends InputOutputPair<? extends InputType,Boolean>>,? extends Evaluator<? super InputType,? extends Boolean>> weakLearner)
          Creates a new instance of AdaBoost.
AdaBoost(BatchLearner<? super Collection<? extends InputOutputPair<? extends InputType,Boolean>>,? extends Evaluator<? super InputType,? extends Boolean>> weakLearner, int maxIterations)
          Creates a new instance of AdaBoost.
 
Method Summary
protected  void cleanupAlgorithm()
          Called to clean up the learning algorithm's state after learning has finished.
 WeightedBinaryEnsemble<InputType,Evaluator<? super InputType,? extends Boolean>> getEnsemble()
          Gets the ensemble created by this learner.
 BatchLearner<? super Collection<? extends InputOutputPair<? extends InputType,Boolean>>,? extends Evaluator<? super InputType,? extends Boolean>> getLearner()
          Gets the learner contained in this object.
 WeightedBinaryEnsemble<InputType,Evaluator<? super InputType,? extends Boolean>> getResult()
          Gets the current result of the algorithm.
 BatchLearner<? super Collection<? extends InputOutputPair<? extends InputType,Boolean>>,? extends Evaluator<? super InputType,? extends Boolean>> getWeakLearner()
          Gets the weak learner that is passed the weighted training data on each step of the algorithm.
 ArrayList<DefaultWeightedInputOutputPair<InputType,Boolean>> getWeightedData()
          Gets the weighted version of the data.
protected  boolean initializeAlgorithm()
          Called to initialize the learning algorithm's state based on the data that is stored in the data field.
protected  void setEnsemble(WeightedBinaryEnsemble<InputType,Evaluator<? super InputType,? extends Boolean>> ensemble)
          Sets the ensemble created by this learner.
 void setWeakLearner(BatchLearner<? super Collection<? extends InputOutputPair<? extends InputType,Boolean>>,? extends Evaluator<? super InputType,? extends Boolean>> weakLearner)
          Sets the weak learner that is passed the weighted training data on each step of the algorithm.
protected  void setWeightedData(ArrayList<DefaultWeightedInputOutputPair<InputType,Boolean>> weightedData)
          Sets the weighted version of the data.
protected  boolean step()
          Called to take a single step of the learning algorithm.
 
Methods inherited from class gov.sandia.cognition.learning.algorithm.AbstractAnytimeBatchLearner
clone, 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.util.CloneableSerializable
clone
 
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
 

Field Detail

DEFAULT_MAX_ITERATIONS

public static final int DEFAULT_MAX_ITERATIONS
The default maximum number of iterations is 100.

See Also:
Constant Field Values

weakLearner

protected BatchLearner<? super Collection<? extends InputOutputPair<? extends InputType,Boolean>>,? extends Evaluator<? super InputType,? extends Boolean>> weakLearner
The "weak learner" that must learn from the weighted input-output pairs on each iteration.


ensemble

protected transient WeightedBinaryEnsemble<InputType,Evaluator<? super InputType,? extends Boolean>> ensemble
The ensemble learned by the algorithm.


weightedData

protected transient ArrayList<DefaultWeightedInputOutputPair<InputType,Boolean>> weightedData
An array list containing the weighted version of the data.

Constructor Detail

AdaBoost

public AdaBoost()
Creates a new instance of AdaBoost with no base learner.


AdaBoost

public AdaBoost(BatchLearner<? super Collection<? extends InputOutputPair<? extends InputType,Boolean>>,? extends Evaluator<? super InputType,? extends Boolean>> weakLearner)
Creates a new instance of AdaBoost.

Parameters:
weakLearner - The weak learner to apply learning to on each iteration.

AdaBoost

public AdaBoost(BatchLearner<? super Collection<? extends InputOutputPair<? extends InputType,Boolean>>,? extends Evaluator<? super InputType,? extends Boolean>> weakLearner,
                int maxIterations)
Creates a new instance of AdaBoost.

Parameters:
weakLearner - The weak learner to apply learning to on each iteration.
maxIterations - The maximum number of iterations to run for, which is also the upper bound on the number of learners to create.
Method Detail

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.

Specified by:
initializeAlgorithm in class AbstractAnytimeBatchLearner<Collection<? extends InputOutputPair<? extends InputType,Boolean>>,WeightedBinaryEnsemble<InputType,Evaluator<? super InputType,? extends Boolean>>>
Returns:
True if the learning algorithm can be run and false if it cannot.

step

protected boolean step()
Description copied from class: AbstractAnytimeBatchLearner
Called to take a single step of the learning algorithm.

Specified by:
step in class AbstractAnytimeBatchLearner<Collection<? extends InputOutputPair<? extends InputType,Boolean>>,WeightedBinaryEnsemble<InputType,Evaluator<? super InputType,? extends Boolean>>>
Returns:
True if another step can be taken and false it the algorithm should halt.

cleanupAlgorithm

protected void cleanupAlgorithm()
Description copied from class: AbstractAnytimeBatchLearner
Called to clean up the learning algorithm's state after learning has finished.

Specified by:
cleanupAlgorithm in class AbstractAnytimeBatchLearner<Collection<? extends InputOutputPair<? extends InputType,Boolean>>,WeightedBinaryEnsemble<InputType,Evaluator<? super InputType,? extends Boolean>>>

getResult

public WeightedBinaryEnsemble<InputType,Evaluator<? super InputType,? extends Boolean>> getResult()
Description copied from interface: AnytimeAlgorithm
Gets the current result of the algorithm.

Specified by:
getResult in interface AnytimeAlgorithm<WeightedBinaryEnsemble<InputType,Evaluator<? super InputType,? extends Boolean>>>
Returns:
Current result of the algorithm.

getLearner

public BatchLearner<? super Collection<? extends InputOutputPair<? extends InputType,Boolean>>,? extends Evaluator<? super InputType,? extends Boolean>> getLearner()
Description copied from interface: BatchLearnerContainer
Gets the learner contained in this object.

Specified by:
getLearner in interface BatchLearnerContainer<BatchLearner<? super Collection<? extends InputOutputPair<? extends InputType,Boolean>>,? extends Evaluator<? super InputType,? extends Boolean>>>
Returns:
The learner contained in this object.

getWeakLearner

public BatchLearner<? super Collection<? extends InputOutputPair<? extends InputType,Boolean>>,? extends Evaluator<? super InputType,? extends Boolean>> getWeakLearner()
Gets the weak learner that is passed the weighted training data on each step of the algorithm.

Returns:
The weak learner for the algorithm to use.

setWeakLearner

public void setWeakLearner(BatchLearner<? super Collection<? extends InputOutputPair<? extends InputType,Boolean>>,? extends Evaluator<? super InputType,? extends Boolean>> weakLearner)
Sets the weak learner that is passed the weighted training data on each step of the algorithm.

Parameters:
weakLearner - The weak learner for the algorithm to use.

getEnsemble

public WeightedBinaryEnsemble<InputType,Evaluator<? super InputType,? extends Boolean>> getEnsemble()
Gets the ensemble created by this learner.

Returns:
The ensemble created by this learner.

setEnsemble

protected void setEnsemble(WeightedBinaryEnsemble<InputType,Evaluator<? super InputType,? extends Boolean>> ensemble)
Sets the ensemble created by this learner.

Parameters:
ensemble - The ensemble created by this learner.

getWeightedData

public ArrayList<DefaultWeightedInputOutputPair<InputType,Boolean>> getWeightedData()
Gets the weighted version of the data.

Returns:
The weighted version of the data.

setWeightedData

protected void setWeightedData(ArrayList<DefaultWeightedInputOutputPair<InputType,Boolean>> weightedData)
Sets the weighted version of the data.

Parameters:
weightedData - The weighted version of the data.