gov.sandia.cognition.learning.algorithm.perceptron
Class AbstractLinearCombinationOnlineLearner

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.learning.algorithm.AbstractBatchAndIncrementalLearner<InputOutputPair<? extends InputType,OutputType>,ResultType>
          extended by gov.sandia.cognition.learning.algorithm.AbstractSupervisedBatchAndIncrementalLearner<Vectorizable,Boolean,LinearBinaryCategorizer>
              extended by gov.sandia.cognition.learning.algorithm.perceptron.AbstractOnlineLinearBinaryCategorizerLearner
                  extended by gov.sandia.cognition.learning.algorithm.perceptron.AbstractKernelizableBinaryCategorizerOnlineLearner
                      extended by gov.sandia.cognition.learning.algorithm.perceptron.AbstractLinearCombinationOnlineLearner
All Implemented Interfaces:
BatchAndIncrementalLearner<InputOutputPair<? extends Vectorizable,Boolean>,LinearBinaryCategorizer>, BatchLearner<Collection<? extends InputOutputPair<? extends Vectorizable,Boolean>>,LinearBinaryCategorizer>, IncrementalLearner<InputOutputPair<? extends Vectorizable,Boolean>,LinearBinaryCategorizer>, KernelizableBinaryCategorizerOnlineLearner, SupervisedBatchAndIncrementalLearner<Vectorizable,Boolean,LinearBinaryCategorizer>, SupervisedBatchLearner<Vectorizable,Boolean,LinearBinaryCategorizer>, SupervisedIncrementalLearner<Vectorizable,Boolean,LinearBinaryCategorizer>, VectorFactoryContainer, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
OnlineBinaryMarginInfusedRelaxedAlgorithm, OnlinePassiveAggressivePerceptron, OnlinePerceptron, OnlineShiftingPerceptron

public abstract class AbstractLinearCombinationOnlineLearner
extends AbstractKernelizableBinaryCategorizerOnlineLearner

An abstract class for online learning of linear binary categorizers that take the form of a weighted sum of inputs. It has utility methods for splitting up the computation into three steps and provides both linear and kernel methods for learning.

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

Field Summary
protected  boolean updateBias
          An option controlling whether or not the bias is updated or not.
 
Fields inherited from class gov.sandia.cognition.learning.algorithm.perceptron.AbstractOnlineLinearBinaryCategorizerLearner
vectorFactory
 
Constructor Summary
AbstractLinearCombinationOnlineLearner(boolean updateBias)
          Creates a new AbstractLinearCombinationOnlineLearner with default parameters.
AbstractLinearCombinationOnlineLearner(boolean updateBias, VectorFactory<?> vectorFactory)
          Creates a new AbstractLinearCombinationOnlineLearner with the given parameters.
 
Method Summary
protected
<InputType>
double
computeDecay(DefaultKernelBinaryCategorizer<InputType> target, InputType input, boolean actualCategory, double predicted, double update)
          Computes the decay scalar for the existing weights.
protected  double computeDecay(LinearBinaryCategorizer target, Vector input, boolean actualCategory, double predicted, double update)
          Computes the decay scalar for the existing weight vector.
protected
<InputType>
double
computeRescaling(DefaultKernelBinaryCategorizer<InputType> target, InputType input, boolean actualCategory, double predicted, double update, double decay)
          Computes the rescaling for the new weights.
protected  double computeRescaling(LinearBinaryCategorizer target, Vector input, boolean actualCategory, double predicted, double update, double decay)
          Computes the rescaling for the new weight vector.
protected abstract
<InputType>
double
computeUpdate(DefaultKernelBinaryCategorizer<InputType> target, InputType input, boolean actualCategory, double predicted)
          Compute the update weight in the linear case.
protected abstract  double computeUpdate(LinearBinaryCategorizer target, Vector input, boolean actualCategory, double predicted)
          Compute the update weight in the linear case.
<InputType>
DefaultKernelBinaryCategorizer<InputType>
createInitialLearnedObject(Kernel<? super InputType> kernel)
          Creates the initial learned object with a given kernel.
protected
<InputType>
void
initialize(DefaultKernelBinaryCategorizer<InputType> target, InputType input, boolean actualCategory)
          Initializes the kernel binary categorizer.
protected  void initialize(LinearBinaryCategorizer target, Vector input, boolean actualCategory)
          Initializes the linear binary categorizer.
 boolean isUpdateBias()
          Gets whether or not the algorithm is updating the bias.
protected  void setUpdateBias(boolean updateBias)
          Sets whether or not the algorithm is updating the bias.
<InputType>
void
update(DefaultKernelBinaryCategorizer<InputType> target, InputType input, boolean output)
          Performs a kernel-based incremental update step on the given object using the given supervised data.
 void update(LinearBinaryCategorizer target, Vector input, boolean label)
          The update method updates an object of ResultType using the given a new supervised input-output pair, using some form of "learning" algorithm.
 
Methods inherited from class gov.sandia.cognition.learning.algorithm.perceptron.AbstractKernelizableBinaryCategorizerOnlineLearner
createKernelLearner, learn, update, update, update
 
Methods inherited from class gov.sandia.cognition.learning.algorithm.perceptron.AbstractOnlineLinearBinaryCategorizerLearner
createInitialLearnedObject, getVectorFactory, setVectorFactory, update
 
Methods inherited from class gov.sandia.cognition.learning.algorithm.AbstractSupervisedBatchAndIncrementalLearner
update
 
Methods inherited from class gov.sandia.cognition.learning.algorithm.AbstractBatchAndIncrementalLearner
clone, learn, learn, update
 
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.SupervisedIncrementalLearner
update
 
Methods inherited from interface gov.sandia.cognition.learning.algorithm.BatchAndIncrementalLearner
learn
 
Methods inherited from interface gov.sandia.cognition.learning.algorithm.BatchLearner
learn
 
Methods inherited from interface gov.sandia.cognition.learning.algorithm.IncrementalLearner
createInitialLearnedObject, update, update
 
Methods inherited from interface gov.sandia.cognition.util.CloneableSerializable
clone
 

Field Detail

updateBias

protected boolean updateBias
An option controlling whether or not the bias is updated or not. Individual algorithm implementations choose the default value for this.

Constructor Detail

AbstractLinearCombinationOnlineLearner

public AbstractLinearCombinationOnlineLearner(boolean updateBias)
Creates a new AbstractLinearCombinationOnlineLearner with default parameters.

Parameters:
updateBias - Whether or not the bias should be updated by the algorithm.

AbstractLinearCombinationOnlineLearner

public AbstractLinearCombinationOnlineLearner(boolean updateBias,
                                              VectorFactory<?> vectorFactory)
Creates a new AbstractLinearCombinationOnlineLearner with the given parameters.

Parameters:
updateBias - Whether or not the bias should be updated by the algorithm.
vectorFactory - The vector factory to use.
Method Detail

update

public void update(LinearBinaryCategorizer target,
                   Vector input,
                   boolean label)
Description copied from class: AbstractOnlineLinearBinaryCategorizerLearner
The update method updates an object of ResultType using the given a new supervised input-output pair, using some form of "learning" algorithm.

Specified by:
update in class AbstractOnlineLinearBinaryCategorizerLearner
Parameters:
target - The object to update.
input - The supervised input vector to learn from.
label - The supervised output label to learn from.

createInitialLearnedObject

public <InputType> DefaultKernelBinaryCategorizer<InputType> createInitialLearnedObject(Kernel<? super InputType> kernel)
Description copied from interface: KernelizableBinaryCategorizerOnlineLearner
Creates the initial learned object with a given kernel.

Specified by:
createInitialLearnedObject in interface KernelizableBinaryCategorizerOnlineLearner
Overrides:
createInitialLearnedObject in class AbstractKernelizableBinaryCategorizerOnlineLearner
Type Parameters:
InputType - The input type for supervised learning. Will be passed to the kernel function.
Parameters:
kernel - The kernel function to use.
Returns:
A new, empty learned object.

update

public <InputType> void update(DefaultKernelBinaryCategorizer<InputType> target,
                               InputType input,
                               boolean output)
Description copied from interface: KernelizableBinaryCategorizerOnlineLearner
Performs a kernel-based incremental update step on the given object using the given supervised data.

Type Parameters:
InputType - The input type for supervised learning. Will be passed to the kernel function.
Parameters:
target - The target object to update.
input - The supervised input value.
output - The supervised output value (label).

initialize

protected void initialize(LinearBinaryCategorizer target,
                          Vector input,
                          boolean actualCategory)
Initializes the linear binary categorizer. Can be overridden. The default implementation just sets the weights to the zero vector.

Parameters:
target - The categorizer to initialize.
input - The first input seen.
actualCategory - The actual category of the first input.

computeUpdate

protected abstract double computeUpdate(LinearBinaryCategorizer target,
                                        Vector input,
                                        boolean actualCategory,
                                        double predicted)
Compute the update weight in the linear case. Must be implemented by subclasses.

Parameters:
target - Target to compute the update for.
input - Input to use in computing the update.
actualCategory - The actual category of the input.
predicted - The predicted category of the input.
Returns:
The update weight for how much to add the input to the target. May be zero if no update is needed.

computeDecay

protected double computeDecay(LinearBinaryCategorizer target,
                              Vector input,
                              boolean actualCategory,
                              double predicted,
                              double update)
Computes the decay scalar for the existing weight vector. Can be overridden. The default implementation just returns 1.0, which means no change. Typically this will be a value between 0.0 and 1.0.

Parameters:
target - Target to compute the update for.
input - Input to use in computing the update.
actualCategory - The actual category of the input.
predicted - The predicted category of the input.
update - The value from the computeUpdate step.
Returns:
The decay to apply to the weight vector. Usually between 0.0 and 1.0.

computeRescaling

protected double computeRescaling(LinearBinaryCategorizer target,
                                  Vector input,
                                  boolean actualCategory,
                                  double predicted,
                                  double update,
                                  double decay)
Computes the rescaling for the new weight vector. Can be overridden. The default implementation just returns 1.0, which means no change. Typically this will be a value between 0.0 and 1.0.

Parameters:
target - Target to compute the update for.
input - Input to use in computing the update.
actualCategory - The actual category of the input.
predicted - The predicted category of the input.
update - The value from the computeUpdate step.
decay - The value from the computeDecay step.
Returns:
The rescaling to apply to the weight vector. Usually between 0.0 and 1.0.

initialize

protected <InputType> void initialize(DefaultKernelBinaryCategorizer<InputType> target,
                                      InputType input,
                                      boolean actualCategory)
Initializes the kernel binary categorizer. Can be overridden. The default implementation does nothing.

Type Parameters:
InputType - The input value for learning.
Parameters:
target - The categorizer to initialize.
input - The first input seen.
actualCategory - The actual category of the first input.

computeUpdate

protected abstract <InputType> double computeUpdate(DefaultKernelBinaryCategorizer<InputType> target,
                                                    InputType input,
                                                    boolean actualCategory,
                                                    double predicted)
Compute the update weight in the linear case. Must be implemented by subclasses.

Type Parameters:
InputType - The input value for learning.
Parameters:
target - Target to compute the update for.
input - Input to use in computing the update.
actualCategory - The actual category of the input.
predicted - The predicted category of the input.
Returns:
The update weight for how much to add the input to the target. May be zero if no update is needed.

computeDecay

protected <InputType> double computeDecay(DefaultKernelBinaryCategorizer<InputType> target,
                                          InputType input,
                                          boolean actualCategory,
                                          double predicted,
                                          double update)
Computes the decay scalar for the existing weights. Can be overridden. The default implementation just returns 1.0, which means no change. Typically this will be a value between 0.0 and 1.0.

Type Parameters:
InputType - The input value for learning.
Parameters:
target - Target to compute the update for.
input - Input to use in computing the update.
actualCategory - The actual category of the input.
predicted - The predicted category of the input.
update - The value from the computeUpdate step.
Returns:
The decay to apply to the weights. Usually between 0.0 and 1.0.

computeRescaling

protected <InputType> double computeRescaling(DefaultKernelBinaryCategorizer<InputType> target,
                                              InputType input,
                                              boolean actualCategory,
                                              double predicted,
                                              double update,
                                              double decay)
Computes the rescaling for the new weights. Can be overridden. The default implementation just returns 1.0, which means no change. Typically this will be a value between 0.0 and 1.0.

Type Parameters:
InputType - The input value for learning.
Parameters:
target - Target to compute the update for.
input - Input to use in computing the update.
actualCategory - The actual category of the input.
predicted - The predicted category of the input.
update - The value from the computeUpdate step.
decay - The value from the computeDecay step.
Returns:
The rescaling to apply to the weights. Usually between 0.0 and 1.0.

isUpdateBias

public boolean isUpdateBias()
Gets whether or not the algorithm is updating the bias.

Returns:
True if the algorithm is updating the bias. Otherwise, false.

setUpdateBias

protected void setUpdateBias(boolean updateBias)
Sets whether or not the algorithm is updating the bias.

Parameters:
updateBias - True if the algorithm is updating the bias. Otherwise, false.