gov.sandia.cognition.learning.function.categorization
Class LinearBinaryCategorizer

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.learning.function.categorization.AbstractBinaryCategorizer<InputType>
          extended by gov.sandia.cognition.learning.function.categorization.AbstractDiscriminantBinaryCategorizer<Vectorizable>
              extended by gov.sandia.cognition.learning.function.categorization.LinearBinaryCategorizer
All Implemented Interfaces:
Evaluator<Vectorizable,Boolean>, BinaryCategorizer<Vectorizable>, Categorizer<Vectorizable,Boolean>, DiscriminantBinaryCategorizer<Vectorizable>, DiscriminantCategorizer<Vectorizable,Boolean,Double>, ThresholdBinaryCategorizer<Vectorizable>, VectorInputEvaluator<Vectorizable,Boolean>, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
AbstractConfidenceWeightedBinaryCategorizer, OnlineShiftingPerceptron.LinearResult

public class LinearBinaryCategorizer
extends AbstractDiscriminantBinaryCategorizer<Vectorizable>
implements VectorInputEvaluator<Vectorizable,Boolean>, ThresholdBinaryCategorizer<Vectorizable>

The LinearBinaryCategorizer class implements a binary categorizer that is implemented by a linear function. More formally, the classifier is parameterized by a weight vector (w) and a bias (b) and computes the output for a given input (x) as: f(x) = w * x + b The categorization is done by: f(x) >= 0

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

Field Summary
static double DEFAULT_BIAS
          The default bias is 0.0.
 
Fields inherited from class gov.sandia.cognition.learning.function.categorization.AbstractBinaryCategorizer
BINARY_CATEGORIES
 
Constructor Summary
LinearBinaryCategorizer()
          Creates a new instance of LinearBinaryCategorizer.
LinearBinaryCategorizer(LinearBinaryCategorizer other)
          Creates a new copy of a LinearBinaryCategorizer.
LinearBinaryCategorizer(Vector weights, double bias)
          Creates a new instance of LinearBinaryCategorizer with the given weights and bias.
 
Method Summary
 LinearBinaryCategorizer clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 double evaluateAsDouble(Vector input)
          A convenience method for evaluating a Vector object as a double, thus avoiding the convertToVector call from Vectorizable.
 double evaluateAsDouble(Vectorizable input)
          Categorizes the given input vector as a double by: weights * input + bias
 double getBias()
          Gets the bias term.
 int getInputDimensionality()
          Gets the expected dimensionality of the input vector to the evaluator, if it is known.
 double getThreshold()
          Gets the threshold, which is the negative of the bias.
 Vector getWeights()
          Gets the weight vector.
 void setBias(double bias)
          Sets the bias term.
 void setThreshold(double threshold)
          Sets the threshold, which is the negative of the bias.
 void setWeights(Vector weights)
          Sets the weight vector.
 String toString()
           
 
Methods inherited from class gov.sandia.cognition.learning.function.categorization.AbstractDiscriminantBinaryCategorizer
evaluate, evaluateWithDiscriminant
 
Methods inherited from class gov.sandia.cognition.learning.function.categorization.AbstractBinaryCategorizer
getCategories
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.learning.function.categorization.DiscriminantCategorizer
evaluateWithDiscriminant
 
Methods inherited from interface gov.sandia.cognition.learning.function.categorization.Categorizer
getCategories
 
Methods inherited from interface gov.sandia.cognition.evaluator.Evaluator
evaluate
 

Field Detail

DEFAULT_BIAS

public static final double DEFAULT_BIAS
The default bias is 0.0.

See Also:
Constant Field Values
Constructor Detail

LinearBinaryCategorizer

public LinearBinaryCategorizer()
Creates a new instance of LinearBinaryCategorizer.


LinearBinaryCategorizer

public LinearBinaryCategorizer(Vector weights,
                               double bias)
Creates a new instance of LinearBinaryCategorizer with the given weights and bias.

Parameters:
weights - The weight vector.
bias - The bias term.

LinearBinaryCategorizer

public LinearBinaryCategorizer(LinearBinaryCategorizer other)
Creates a new copy of a LinearBinaryCategorizer.

Parameters:
other - The LinearBinaryCategorizer to copy.
Method Detail

clone

public LinearBinaryCategorizer 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.

evaluateAsDouble

public double evaluateAsDouble(Vectorizable input)
Categorizes the given input vector as a double by: weights * input + bias

Specified by:
evaluateAsDouble in interface DiscriminantBinaryCategorizer<Vectorizable>
Parameters:
input - The input vector to categorize.
Returns:
The categorization of the input vector where the sign is the categorization.

evaluateAsDouble

public double evaluateAsDouble(Vector input)
A convenience method for evaluating a Vector object as a double, thus avoiding the convertToVector call from Vectorizable. It calculates: weights * input + bias

Parameters:
input - The input value to convert to a vector.
Returns:
The double result of multiplying the weight vector times the given vector and adding the bias. If the weight vector is null, bias is returned. The sign is treated as the categorization.

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,Boolean>
Returns:
The expected dimensionality of the input vector to the evaluator, or -1 if it is not known.

getThreshold

public double getThreshold()
Gets the threshold, which is the negative of the bias.

Specified by:
getThreshold in interface ThresholdBinaryCategorizer<Vectorizable>
Returns:
The threshold, which is the negative of the bias.

setThreshold

public void setThreshold(double threshold)
Sets the threshold, which is the negative of the bias.

Specified by:
setThreshold in interface ThresholdBinaryCategorizer<Vectorizable>
Parameters:
threshold - the threshold, which is the negative of the bias.

getWeights

public Vector getWeights()
Gets the weight vector.

Returns:
The weight vector.

setWeights

public void setWeights(Vector weights)
Sets the weight vector.

Parameters:
weights - The weight vector.

getBias

public double getBias()
Gets the bias term.

Returns:
The bias term.

setBias

public void setBias(double bias)
Sets the bias term.

Parameters:
bias - The bias term.

toString

public String toString()
Overrides:
toString in class Object