mahalanobis

Syntax

mahalanobis(X, Y, Z)

Details

Compute the Mahalanobis distance between two numeric vectors (X and Y). The distance is defined as follows:

where V is the covariance matrix, and Z is the inverse of V.

Parameters

X: A numeric vector.

Y: A numeric vector.

Z: The inverse of the covariance matrix.

Returns

A scalar of type DOUBLE.

Examples

len = 50
X = array(DOUBLE, 0).append!(take([1.2, 3.9, 0.8], len))
Y = array(DOUBLE, 0).append!(take([5.6, 0.4, 2.7], len))
Z1 = diag(take(1, len)) Z = inverse(Z1)

mahalanobis(X, Y, Z)
//Output: 24.395286429964294

Related functions

minkowski, seuclidean