Package elki.distance

## Class MahalanobisDistance

• All Implemented Interfaces:
Distance<NumberVector>, Norm<NumberVector>, NumberVectorDistance<NumberVector>, PrimitiveDistance<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 MahalanobisDistance
extends MatrixWeightedQuadraticDistance
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 elki.distance.MatrixWeightedQuadraticDistance

weightMatrix
• ### Constructor Summary

Constructors
Constructor Description
MahalanobisDistance​(double[][] weightMatrix)
Constructor.
• ### Method Summary

All Methods
Modifier and Type Method 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 elki.distance.MatrixWeightedQuadraticDistance

equals, getInputTypeRestriction, hashCode
• ### Methods inherited from class elki.distance.AbstractNumberVectorDistance

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 elki.distance.Distance

isSymmetric
• ### Methods inherited from interface elki.distance.PrimitiveDistance

instantiate
• ### Constructor Detail

• #### MahalanobisDistance

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

• #### distance

public double distance​(NumberVector o1,
NumberVector o2)
Description copied from interface: PrimitiveDistance
Computes the distance between two given DatabaseObjects according to this distance function.
Specified by:
distance in interface NumberVectorDistance<NumberVector>
Specified by:
distance in interface PrimitiveDistance<NumberVector>
Overrides:
distance in class MatrixWeightedQuadraticDistance
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 MatrixWeightedQuadraticDistance
Parameters:
obj - Object
Returns:
Norm
• #### isMetric

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

public boolean isSquared()
Description copied from interface: Distance
Squared distances, that would become metric after square root.

E.g. squared Euclidean.

Specified by:
isSquared in interface Distance<NumberVector>
Overrides:
isSquared in class MatrixWeightedQuadraticDistance
Returns:
true when squared.