de.lmu.ifi.dbs.elki.distance.distancefunction

## Class MahalanobisDistanceFunction

• All Implemented Interfaces:
DistanceFunction<NumberVector>, Norm<NumberVector>, NumberVectorDistanceFunction<NumberVector>, PrimitiveDistanceFunction<NumberVector>

@Reference(authors="P. C. Mahalanobis",
title="On the generalized distance in statistics",
booktitle="Proceedings of the National Institute of Sciences of India. 2 (1)",
bibkey="journals/misc/Mahalanobis36")
public class MahalanobisDistanceFunction
extends MatrixWeightedQuadraticDistanceFunction
Mahalanobis quadratic form distance for feature vectors.

For a weight matrix M, this distance is defined as $\text{Mahalanobis}_M(\vec{x},\vec{y}) := \sqrt{(\vec{x}-\vec{y})^T \cdot M \cdot (\vec{x}-\vec{y})}$

Reference:

P. C. Mahalanobis
On the generalized distance in statistics
Proceedings of the National Institute of Sciences of India. 2 (1)

This is the implementation as quadratic form distance function. In many cases it will be more convenient to use the static function VMath.mahalanobisDistance(double[][], double[], double[]) instead.

TODO: Add a factory with parameterizable weight matrix! Right now, this can only be used from Java and from subclasses, not from command line or MiniGUI.

Since:
0.7.5
Author:
Erich Schubert

• ### Fields inherited from class de.lmu.ifi.dbs.elki.distance.distancefunction.MatrixWeightedQuadraticDistanceFunction

weightMatrix
• ### Constructor Summary

Constructors
Constructor and Description
MahalanobisDistanceFunction(double[][] weightMatrix)
Constructor.
• ### Method Summary

All Methods
Modifier and Type Method and Description
double distance(NumberVector o1, NumberVector o2)
Computes the distance between two given DatabaseObjects according to this distance function.
boolean isMetric()
Is this distance function metric (satisfy the triangle inequality)
boolean isSquared()
Squared distances, that would become metric after square root.
double norm(NumberVector obj)
Compute the norm of object obj.
• ### Methods inherited from class de.lmu.ifi.dbs.elki.distance.distancefunction.MatrixWeightedQuadraticDistanceFunction

equals, getInputTypeRestriction, hashCode
• ### Methods inherited from class de.lmu.ifi.dbs.elki.distance.distancefunction.AbstractNumberVectorDistanceFunction

dimensionality, dimensionality, dimensionality, dimensionality, dimensionality, dimensionality, dimensionality, dimensionality
• ### Methods inherited from class java.lang.Object

clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
• ### Methods inherited from interface de.lmu.ifi.dbs.elki.distance.distancefunction.PrimitiveDistanceFunction

instantiate
• ### Methods inherited from interface de.lmu.ifi.dbs.elki.distance.distancefunction.DistanceFunction

isSymmetric
• ### Constructor Detail

• #### MahalanobisDistanceFunction

public MahalanobisDistanceFunction(double[][] weightMatrix)
Constructor.
Parameters:
weightMatrix - Weight matrix.
• ### Method Detail

• #### distance

public double distance(NumberVector o1,
NumberVector o2)
Description copied from interface: PrimitiveDistanceFunction
Computes the distance between two given DatabaseObjects according to this distance function.
Specified by:
distance in interface NumberVectorDistanceFunction<NumberVector>
Specified by:
distance in interface PrimitiveDistanceFunction<NumberVector>
Overrides:
distance in class MatrixWeightedQuadraticDistanceFunction
Parameters:
o1 - first DatabaseObject
o2 - second DatabaseObject
Returns:
the distance between two given DatabaseObjects according to this distance function
• #### norm

public double norm(NumberVector obj)
Description copied from interface: Norm
Compute the norm of object obj.
Specified by:
norm in interface Norm<NumberVector>
Overrides:
norm in class MatrixWeightedQuadraticDistanceFunction
Parameters:
obj - Object
Returns:
Norm
• #### isMetric

public boolean isMetric()
Description copied from interface: DistanceFunction
Is this distance function metric (satisfy the triangle inequality)
Returns:
true when metric.
• #### isSquared

public boolean isSquared()
Description copied from interface: DistanceFunction
Squared distances, that would become metric after square root. E.g. squared Euclidean.
Specified by:
isSquared in interface DistanceFunction<NumberVector>
Overrides:
isSquared in class MatrixWeightedQuadraticDistanceFunction
Returns:
true when squared.