gov.sandia.cognition.learning.function.vector
Class MultivariateDiscriminant

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.learning.function.vector.MultivariateDiscriminant
All Implemented Interfaces:
Evaluator<Vector,Vector>, GradientDescendable, ParameterGradientEvaluator<Vector,Matrix>, DifferentiableEvaluator<Vector,Vector,Matrix>, DifferentiableVectorFunction, VectorFunction, VectorInputEvaluator<Vector,Vector>, Vectorizable, VectorizableDifferentiableVectorFunction, VectorizableVectorFunction, VectorOutputEvaluator<Vector,Vector>, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
MultivariateDiscriminantWithBias

@CodeReview(reviewer="Justin Basilico",
            date="2006-10-06",
            changesNeeded=true,
            comments={"Can you just add a comment for why the differentiation code is correct?","Otherwise, class looks fine."},
            response=@CodeReviewResponse(respondent="Kevin R. Dixon",date="2006-10-06",moreChangesNeeded=false,comments="Added in-code comment describing the derivation of the differentiation formulae."))
public class MultivariateDiscriminant
extends AbstractCloneableSerializable
implements VectorizableDifferentiableVectorFunction, VectorInputEvaluator<Vector,Vector>, VectorOutputEvaluator<Vector,Vector>, GradientDescendable

Allows learning algorithms (vectorizing, differentiating) on a matrix*vector multiply.

Since:
1.0
Author:
Kevin R. Dixon
See Also:
Serialized Form

Constructor Summary
MultivariateDiscriminant()
          Default constructor.
MultivariateDiscriminant(int numInputs, int numOutputs)
          Creates a new MultivariateDiscriminant
MultivariateDiscriminant(Matrix discriminant)
          Creates a new instance of MatrixVectorMultiplyFunction.
MultivariateDiscriminant(MultivariateDiscriminant other)
          Copy constructor
 
Method Summary
 MultivariateDiscriminant clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
static Matrix computeParameterGradient(Matrix matrix, Vector input)
          Computes the parameter gradient of the given matrix post-multiplied by the input Vector
 Matrix computeParameterGradient(Vector input)
          Computes the derivative of the function about the input with respect to the parameters of the function
 void convertFromVector(Vector parameters)
          Uploads a matrix from a row-stacked vector of parameters.
 Vector convertToVector()
          Creates a row-stacked version of the discriminant.
 Matrix differentiate(Vector input)
          Differentiate the VectorFunction at input and return the Jacobian
 Vector evaluate(Vector input)
          Evaluates the function on the given input and returns the output.
 Matrix getDiscriminant()
          Getter for discriminant.
 int getInputDimensionality()
          Gets the expected dimensionality of the input vector to the evaluator, if it is known.
 int getOutputDimensionality()
          Gets the expected dimensionality of the output vector of the evaluator, if it is known.
protected  void setDiscriminant(Matrix discriminant)
          Setter for discriminant
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MultivariateDiscriminant

public MultivariateDiscriminant()
Default constructor.


MultivariateDiscriminant

public MultivariateDiscriminant(int numInputs,
                                int numOutputs)
Creates a new MultivariateDiscriminant

Parameters:
numInputs - Number of inputs of the function (number of matrix columns)
numOutputs - Number of outputs of the function (number of matrix rows)

MultivariateDiscriminant

public MultivariateDiscriminant(Matrix discriminant)
Creates a new instance of MatrixVectorMultiplyFunction.

Parameters:
discriminant - internal matrix to premultiply input vectors by.

MultivariateDiscriminant

public MultivariateDiscriminant(MultivariateDiscriminant other)
Copy constructor

Parameters:
other - MultivariateDiscriminant to copy
Method Detail

clone

public MultivariateDiscriminant 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 GradientDescendable
Specified by:
clone in interface Vectorizable
Specified by:
clone in interface VectorizableVectorFunction
Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractCloneableSerializable
Returns:
A clone of this object.

getDiscriminant

public Matrix getDiscriminant()
Getter for discriminant.

Returns:
internal matrix to premultiply input vectors by

setDiscriminant

protected void setDiscriminant(Matrix discriminant)
Setter for discriminant

Parameters:
discriminant - internal matrix to premultiply input vectors by

convertToVector

public Vector convertToVector()
Creates a row-stacked version of the discriminant.

Specified by:
convertToVector in interface Vectorizable
Returns:
row-stacked Vector representing the discriminant

convertFromVector

public void convertFromVector(Vector parameters)
Uploads a matrix from a row-stacked vector of parameters.

Specified by:
convertFromVector in interface Vectorizable
Parameters:
parameters - row-stacked version of discriminant

evaluate

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

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

differentiate

public Matrix differentiate(Vector input)
Description copied from interface: DifferentiableVectorFunction
Differentiate the VectorFunction at input and return the Jacobian

Specified by:
differentiate in interface DifferentiableEvaluator<Vector,Vector,Matrix>
Specified by:
differentiate in interface DifferentiableVectorFunction
Parameters:
input - Vector input to the VectorFunction, about which to evaluate the VectorFunction
Returns:
Jacobian at input

computeParameterGradient

public Matrix computeParameterGradient(Vector input)
Description copied from interface: GradientDescendable
Computes the derivative of the function about the input with respect to the parameters of the function

Specified by:
computeParameterGradient in interface GradientDescendable
Specified by:
computeParameterGradient in interface ParameterGradientEvaluator<Vector,Matrix>
Parameters:
input - Point about which to differentiate w.r.t. the parameters
Returns:
Matrix of parameter gradients

computeParameterGradient

public static Matrix computeParameterGradient(Matrix matrix,
                                              Vector input)
Computes the parameter gradient of the given matrix post-multiplied by the input Vector

Parameters:
matrix - Matrix to pre-multiply the input Vector.
input - Vector to post-multiply the Matrix.
Returns:
Derivative of the matrix elements with respect to the inputs.

toString

public String toString()
Overrides:
toString in class Object

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

getOutputDimensionality

public int getOutputDimensionality()
Description copied from interface: VectorOutputEvaluator
Gets the expected dimensionality of the output vector of the evaluator, if it is known. If it is not known, -1 is returned.

Specified by:
getOutputDimensionality in interface VectorOutputEvaluator<Vector,Vector>
Returns:
The expected dimensionality of the output vector of the evaluator, or -1 if it is not known.