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

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
                          extended by gov.sandia.cognition.learning.algorithm.perceptron.OnlinePerceptron
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

@PublicationReference(author="Wikipedia",
                      title="Perceptron Learning algorithm",
                      type=WebPage,
                      year=2008,
                      url="http://en.wikipedia.org/wiki/Perceptron#Learning_algorithm")
public class OnlinePerceptron
extends AbstractLinearCombinationOnlineLearner

An online version of the classic Perceptron algorithm.

Since:
3.1
Author:
Justin Basilico
See Also:
Perceptron, Serialized Form

Field Summary
static boolean DEFAULT_UPDATE_BIAS
          By default the bias is updated.
 
Fields inherited from class gov.sandia.cognition.learning.algorithm.perceptron.AbstractLinearCombinationOnlineLearner
updateBias
 
Fields inherited from class gov.sandia.cognition.learning.algorithm.perceptron.AbstractOnlineLinearBinaryCategorizerLearner
vectorFactory
 
Constructor Summary
OnlinePerceptron()
          Creates a new OnlinePerceptron.
OnlinePerceptron(VectorFactory<?> vectorFactory)
          Creates a new OnlinePerceptron with the given vector factory.
 
Method Summary
static double computeUpdate(boolean actualCategory, double predicted)
          Computes the update weight for the given actual category and predicted value according to the Perceptron update rule.
<InputType>
double
computeUpdate(DefaultKernelBinaryCategorizer<InputType> target, InputType input, boolean actualCategory, double predicted)
          Compute the update weight in the linear case.
 double computeUpdate(LinearBinaryCategorizer target, Vector input, boolean label, double predicted)
          Compute the update weight in the linear case.
 
Methods inherited from class gov.sandia.cognition.learning.algorithm.perceptron.AbstractLinearCombinationOnlineLearner
computeDecay, computeDecay, computeRescaling, computeRescaling, createInitialLearnedObject, initialize, initialize, isUpdateBias, setUpdateBias, update, update
 
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

DEFAULT_UPDATE_BIAS

public static final boolean DEFAULT_UPDATE_BIAS
By default the bias is updated.

See Also:
Constant Field Values
Constructor Detail

OnlinePerceptron

public OnlinePerceptron()
Creates a new OnlinePerceptron.


OnlinePerceptron

public OnlinePerceptron(VectorFactory<?> vectorFactory)
Creates a new OnlinePerceptron with the given vector factory.

Parameters:
vectorFactory - The vector factory to use to create the weight vectors.
Method Detail

computeUpdate

public double computeUpdate(LinearBinaryCategorizer target,
                            Vector input,
                            boolean label,
                            double predicted)
Description copied from class: AbstractLinearCombinationOnlineLearner
Compute the update weight in the linear case. Must be implemented by subclasses.

Specified by:
computeUpdate in class AbstractLinearCombinationOnlineLearner
Parameters:
target - Target to compute the update for.
input - Input to use in computing the update.
label - 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.

computeUpdate

public <InputType> double computeUpdate(DefaultKernelBinaryCategorizer<InputType> target,
                                        InputType input,
                                        boolean actualCategory,
                                        double predicted)
Description copied from class: AbstractLinearCombinationOnlineLearner
Compute the update weight in the linear case. Must be implemented by subclasses.

Specified by:
computeUpdate in class AbstractLinearCombinationOnlineLearner
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.

computeUpdate

public static double computeUpdate(boolean actualCategory,
                                   double predicted)
Computes the update weight for the given actual category and predicted value according to the Perceptron update rule.

Parameters:
actualCategory - The actual category.
predicted - The predicted category.
Returns:
The update value, which is either 0.0 or 1.0.