gov.sandia.cognition.learning.function.distance
Class WeightedEuclideanDistanceMetric

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.learning.function.distance.WeightedEuclideanDistanceMetric
All Implemented Interfaces:
DivergenceFunction<Vectorizable,Vectorizable>, Semimetric<Vectorizable>, CloneableSerializable, Serializable, Cloneable

public class WeightedEuclideanDistanceMetric
extends AbstractCloneableSerializable
implements Semimetric<Vectorizable>

A distance metric that weights each dimension of a vector differently before computing Euclidean distance.

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

Field Summary
protected  Vector weights
          The weights assigned to each dimension for the distance.
 
Constructor Summary
WeightedEuclideanDistanceMetric()
          Creates a new WeightedEuclideanDistanceMetric with no initial weights.
WeightedEuclideanDistanceMetric(Vector weights)
          Creates a new WeightedEuclideanDistanceMetric with the given weights.
 
Method Summary
 WeightedEuclideanDistanceMetric clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 double evaluate(Vectorizable first, Vectorizable second)
          Evaluates the weighted Euclidean distance between two vectors.
 int getInputDimensionality()
          Gets the expected dimensionality of the input vectors for this distance metric.
 Vector getWeights()
          Gets the vector of weights for each dimension.
 void setWeights(Vector weights)
          Sets the vector of weights for each dimension.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

weights

protected Vector weights
The weights assigned to each dimension for the distance. The weights cannot be negative.

Constructor Detail

WeightedEuclideanDistanceMetric

public WeightedEuclideanDistanceMetric()
Creates a new WeightedEuclideanDistanceMetric with no initial weights.


WeightedEuclideanDistanceMetric

public WeightedEuclideanDistanceMetric(Vector weights)
Creates a new WeightedEuclideanDistanceMetric with the given weights.

Parameters:
weights - The vector of weights for each dimension. The weights cannot be negative or else this will create an invalid metric.
Method Detail

clone

public WeightedEuclideanDistanceMetric 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 double evaluate(Vectorizable first,
                       Vectorizable second)
Evaluates the weighted Euclidean distance between two vectors.

Specified by:
evaluate in interface DivergenceFunction<Vectorizable,Vectorizable>
Parameters:
first - The first vector.
second - The second vector.
Returns:
The weighted Euclidean distance between the two vectors.

getInputDimensionality

public int getInputDimensionality()
Gets the expected dimensionality of the input vectors for this distance metric.

Returns:
The expected input dimensionality, if it is known. If the weights have not been set, it will be -1.

getWeights

public Vector getWeights()
Gets the vector of weights for each dimension.

Returns:
The vector of weights for each dimension.

setWeights

public void setWeights(Vector weights)
Sets the vector of weights for each dimension.

Parameters:
weights - The vector of weights for each dimension. The weights cannot be negative or else this will create an invalid metric.