gov.sandia.cognition.learning.algorithm.perceptron
Class OnlineMultiPerceptron<CategoryType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.learning.algorithm.AbstractBatchAndIncrementalLearner<InputOutputPair<? extends Vectorizable,CategoryType>,LinearMultiCategorizer<CategoryType>>
          extended by gov.sandia.cognition.learning.algorithm.perceptron.OnlineMultiPerceptron<CategoryType>
Type Parameters:
CategoryType - The type of output categories. Can be any type that has a valid equals and hashCode method.
All Implemented Interfaces:
BatchAndIncrementalLearner<InputOutputPair<? extends Vectorizable,CategoryType>,LinearMultiCategorizer<CategoryType>>, BatchLearner<Collection<? extends InputOutputPair<? extends Vectorizable,CategoryType>>,LinearMultiCategorizer<CategoryType>>, IncrementalLearner<InputOutputPair<? extends Vectorizable,CategoryType>,LinearMultiCategorizer<CategoryType>>, VectorFactoryContainer, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
OnlineMultiPerceptron.ProportionalUpdate, OnlineMultiPerceptron.UniformUpdate

public class OnlineMultiPerceptron<CategoryType>
extends AbstractBatchAndIncrementalLearner<InputOutputPair<? extends Vectorizable,CategoryType>,LinearMultiCategorizer<CategoryType>>
implements VectorFactoryContainer

An online, multiple category version of the Perceptron algorithm. It learns a separate linear binary categorizer for each category.

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

Nested Class Summary
static class OnlineMultiPerceptron.ProportionalUpdate<CategoryType>
          Variant of a multi-category Perceptron that performs a proportional weight update on all categories that are scored higher than the true category such that the weights sum to 1.0 and are proportional how much larger the score was for each incorrect category than the true category.
static class OnlineMultiPerceptron.UniformUpdate<CategoryType>
          Variant of a multi-category Perceptron that performs a uniform weight update on all categories that are scored higher than the true category such that the weights are equal and sum to -1.
 
Field Summary
static double DEFAULT_MIN_MARGIN
          The default minimum margin is 0.0.
protected  double minMargin
          The minimum margin to enforce.
protected  VectorFactory<?> vectorFactory
          The factory to create weight vectors.
 
Constructor Summary
OnlineMultiPerceptron()
          Creates a new OnlineMultiPerceptron.
OnlineMultiPerceptron(double minMargin)
          Creates a new OnlineMultiPerceptron with the given minimum margin.
OnlineMultiPerceptron(double minMargin, VectorFactory<?> vectorFactory)
          Creates a new OnlineMultiPerceptron with the given minimum margin and backing vector factory.
 
Method Summary
 LinearMultiCategorizer<CategoryType> createInitialLearnedObject()
          Creates a new initial learned object, before any data is given.
 double getMinMargin()
          Gets the minimum margin to enforce.
 VectorFactory<?> getVectorFactory()
          Gets the VectorFactory used to create the weight vector.
 void setMinMargin(double minMargin)
          Gets the minimum margin to enforce.
 void setVectorFactory(VectorFactory<?> vectorFactory)
          Sets the VectorFactory used to create the weight vector.
 void update(LinearMultiCategorizer<CategoryType> target, InputOutputPair<? extends Vectorizable,CategoryType> example)
          The update method updates an object of ResultType using the given new data of type DataType, using some form of "learning" algorithm.
 
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
 

Field Detail

DEFAULT_MIN_MARGIN

public static final double DEFAULT_MIN_MARGIN
The default minimum margin is 0.0.

See Also:
Constant Field Values

minMargin

protected double minMargin
The minimum margin to enforce. Must be non-negative.


vectorFactory

protected VectorFactory<?> vectorFactory
The factory to create weight vectors.

Constructor Detail

OnlineMultiPerceptron

public OnlineMultiPerceptron()
Creates a new OnlineMultiPerceptron.


OnlineMultiPerceptron

public OnlineMultiPerceptron(double minMargin)
Creates a new OnlineMultiPerceptron with the given minimum margin.

Parameters:
minMargin - The minimum margin to consider an example correct.

OnlineMultiPerceptron

public OnlineMultiPerceptron(double minMargin,
                             VectorFactory<?> vectorFactory)
Creates a new OnlineMultiPerceptron with the given minimum margin and backing vector factory.

Parameters:
minMargin - The minimum margin to consider an example correct.
vectorFactory - The vector factory used to create the weight vectors.
Method Detail

createInitialLearnedObject

public LinearMultiCategorizer<CategoryType> createInitialLearnedObject()
Description copied from interface: IncrementalLearner
Creates a new initial learned object, before any data is given.

Specified by:
createInitialLearnedObject in interface IncrementalLearner<InputOutputPair<? extends Vectorizable,CategoryType>,LinearMultiCategorizer<CategoryType>>
Returns:
The initial learned object.

update

public void update(LinearMultiCategorizer<CategoryType> target,
                   InputOutputPair<? extends Vectorizable,CategoryType> example)
Description copied from interface: IncrementalLearner
The update method updates an object of ResultType using the given new data of type DataType, using some form of "learning" algorithm.

Specified by:
update in interface IncrementalLearner<InputOutputPair<? extends Vectorizable,CategoryType>,LinearMultiCategorizer<CategoryType>>
Parameters:
target - The object to update.
example - The new data for the learning algorithm to use to update the object.

getMinMargin

public double getMinMargin()
Gets the minimum margin to enforce. Any value less than or equal to this is considered an error for the algorithm.

Returns:
The minimum margin. Cannot be negative.

setMinMargin

public void setMinMargin(double minMargin)
Gets the minimum margin to enforce. Any value less than or equal to this is considered an error for the algorithm.

Parameters:
minMargin - The minimum margin. Cannot be negative.

getVectorFactory

public VectorFactory<?> getVectorFactory()
Gets the VectorFactory used to create the weight vector.

Specified by:
getVectorFactory in interface VectorFactoryContainer
Returns:
The VectorFactory used to create the weight vector.

setVectorFactory

public void setVectorFactory(VectorFactory<?> vectorFactory)
Sets the VectorFactory used to create the weight vector.

Parameters:
vectorFactory - The VectorFactory used to create the weight vector.