gov.sandia.cognition.learning.function.scalar
Class LinearVectorScalarFunction

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.math.AbstractScalarFunction<InputType>
          extended by gov.sandia.cognition.learning.function.regression.AbstractRegressor<Vectorizable>
              extended by gov.sandia.cognition.learning.function.scalar.LinearVectorScalarFunction
All Implemented Interfaces:
Evaluator<Vectorizable,Double>, ScalarFunction<Vectorizable>, CloneableSerializable, Serializable, Cloneable

@CodeReview(reviewer="Kevin R. Dixon",
            date="2009-07-06",
            changesNeeded=false,
            comments={"Made clone() call super.clone().","Otherwise, class looks fine."})
public class LinearVectorScalarFunction
extends AbstractRegressor<Vectorizable>

The LinearVectorScalarFunction class implements a scalar function that is implemented by a linear function. More formally, the scalar function 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

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

Field Summary
static double DEFAULT_BIAS
          The default bias is 0.0.
 
Constructor Summary
LinearVectorScalarFunction()
          Creates a new instance of LinearVectorScalarFunction.
LinearVectorScalarFunction(LinearVectorScalarFunction other)
          Creates a new copy of a LinearVectorScalarFunction.
LinearVectorScalarFunction(Vector weights)
          Creates a new instance of LinearVectorScalarFunction.
LinearVectorScalarFunction(Vector weights, double bias)
          Creates a new instance of LinearVectorScalarFunction with the given weights and bias.
 
Method Summary
 LinearVectorScalarFunction 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)
          Evaluate the given input vector as a double by: weights * input + bias
 double getBias()
          Gets the bias term.
 Vector getWeights()
          Gets the weight vector.
 void setBias(double bias)
          Sets the bias term.
 void setWeights(Vector weights)
          Sets the weight vector.
 String toString()
           
 
Methods inherited from class gov.sandia.cognition.math.AbstractScalarFunction
evaluate
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_BIAS

public static final double DEFAULT_BIAS
The default bias is 0.0.

See Also:
Constant Field Values
Constructor Detail

LinearVectorScalarFunction

public LinearVectorScalarFunction()
Creates a new instance of LinearVectorScalarFunction.


LinearVectorScalarFunction

public LinearVectorScalarFunction(Vector weights)
Creates a new instance of LinearVectorScalarFunction.

Parameters:
weights - The weight vector.

LinearVectorScalarFunction

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

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

LinearVectorScalarFunction

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

Parameters:
other - The LinearVectorScalarFunction to copy.
Method Detail

clone

public LinearVectorScalarFunction 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)
Evaluate the given input vector as a double by: weights * input + bias

Parameters:
input - The input vector to evaluate.
Returns:
Evaluated input.

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.

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