gov.sandia.cognition.learning.function.categorization
Class LinearMultiCategorizer<CategoryType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.learning.function.categorization.LinearMultiCategorizer<CategoryType>
Type Parameters:
CategoryType - The type of categories that the categorizer can output.
All Implemented Interfaces:
Evaluator<Vectorizable,CategoryType>, Categorizer<Vectorizable,CategoryType>, DiscriminantCategorizer<Vectorizable,CategoryType,Double>, VectorInputEvaluator<Vectorizable,CategoryType>, CloneableSerializable, Serializable, Cloneable

public class LinearMultiCategorizer<CategoryType>
extends AbstractCloneableSerializable
implements DiscriminantCategorizer<Vectorizable,CategoryType,Double>, VectorInputEvaluator<Vectorizable,CategoryType>

A multi-category version of the LinearBinaryCategorizer that keeps a separate LinearBinaryCategorizer for each category. Each of these linear categorizers are called prototypes. Categorization is done by choosing the prototype (w_c, b_c) such that w_c * x + b_c is highest.

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

Field Summary
protected  Map<CategoryType,LinearBinaryCategorizer> prototypes
          A map of each category to its prototype categorizer.
 
Constructor Summary
LinearMultiCategorizer()
          Creates a new, empty LinearMultiCategorizer.
LinearMultiCategorizer(Map<CategoryType,LinearBinaryCategorizer> prototypes)
          Creates a new LinearMultiCategorizer with the given prototypes.
 
Method Summary
 LinearMultiCategorizer<CategoryType> clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 CategoryType evaluate(Vectorizable input)
          Evaluates the function on the given input and returns the output.
 double evaluateAsDouble(Vector input, CategoryType category)
          Evaluates how much the given input matches the prototype for the given category.
 double evaluateAsDouble(Vectorizable input, CategoryType category)
          Evaluates how much the given input matches the prototype for the given category.
 DefaultWeightedValueDiscriminant<CategoryType> evaluateWithDiscriminant(Vectorizable input)
          Evaluate the categorizer on the given input to produce the expected category plus a discriminant for later producing an ordering of how well items fit into that category.
 Set<? extends CategoryType> getCategories()
          Gets the list of possible categories that the categorizer can produce.
 int getInputDimensionality()
          Gets the expected dimensionality of the input vector to the evaluator, if it is known.
 Map<CategoryType,LinearBinaryCategorizer> getPrototypes()
          Gets the mapping of categories to prototypes.
 void setPrototypes(Map<CategoryType,LinearBinaryCategorizer> prototypes)
          Sets the mapping of categories to prototypes.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

prototypes

protected Map<CategoryType,LinearBinaryCategorizer> prototypes
A map of each category to its prototype categorizer.

Constructor Detail

LinearMultiCategorizer

public LinearMultiCategorizer()
Creates a new, empty LinearMultiCategorizer.


LinearMultiCategorizer

public LinearMultiCategorizer(Map<CategoryType,LinearBinaryCategorizer> prototypes)
Creates a new LinearMultiCategorizer with the given prototypes.

Parameters:
prototypes - The mapping of categories to prototypes.
Method Detail

clone

public LinearMultiCategorizer<CategoryType> 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.

evaluate

public CategoryType evaluate(Vectorizable input)
Description copied from interface: Evaluator
Evaluates the function on the given input and returns the output.

Specified by:
evaluate in interface Evaluator<Vectorizable,CategoryType>
Parameters:
input - The input to evaluate.
Returns:
The output produced by evaluating the input.

evaluateWithDiscriminant

public DefaultWeightedValueDiscriminant<CategoryType> evaluateWithDiscriminant(Vectorizable input)
Description copied from interface: DiscriminantCategorizer
Evaluate the categorizer on the given input to produce the expected category plus a discriminant for later producing an ordering of how well items fit into that category.

Specified by:
evaluateWithDiscriminant in interface DiscriminantCategorizer<Vectorizable,CategoryType,Double>
Parameters:
input - The input value to categorize with a discriminate
Returns:
A pair containing the value and the discriminant value used for ordering results belonging to the same category.

evaluateAsDouble

public double evaluateAsDouble(Vectorizable input,
                               CategoryType category)
Evaluates how much the given input matches the prototype for the given category.

Parameters:
input - The input.
category - The category to match the input against.
Returns:
A real value indicating how much the input matches the category. A larger value indicates a better match.

evaluateAsDouble

public double evaluateAsDouble(Vector input,
                               CategoryType category)
Evaluates how much the given input matches the prototype for the given category.

Parameters:
input - The input.
category - The category to match the input against.
Returns:
A real value indicating how much the input matches the category. A larger value indicates a better match.

getCategories

public Set<? extends CategoryType> getCategories()
Description copied from interface: Categorizer
Gets the list of possible categories that the categorizer can produce.

Specified by:
getCategories in interface Categorizer<Vectorizable,CategoryType>
Returns:
The list of possible categories.

getInputDimensionality

public int getInputDimensionality()
Description copied from interface: VectorInputEvaluator
Gets the expected dimensionality of the input vector to the evaluator, if it is known. If it is not known, -1 is returned.

Specified by:
getInputDimensionality in interface VectorInputEvaluator<Vectorizable,CategoryType>
Returns:
The expected dimensionality of the input vector to the evaluator, or -1 if it is not known.

getPrototypes

public Map<CategoryType,LinearBinaryCategorizer> getPrototypes()
Gets the mapping of categories to prototypes.

Returns:
The mapping of categories to prototypes.

setPrototypes

public void setPrototypes(Map<CategoryType,LinearBinaryCategorizer> prototypes)
Sets the mapping of categories to prototypes.

Parameters:
prototypes - The mapping of categories to prototypes.