Class MahalanobisMetric

java.lang.Object
org.episteme.core.mathematics.topology.metrics.MahalanobisMetric
All Implemented Interfaces:
Metric<Vector<Real>>

public class MahalanobisMetric extends Object implements Metric<Vector<Real>>
Mahalanobis distance metric.

The Mahalanobis distance is a measure of the distance between a point and a distribution. It accounts for correlations between variables and is scale-invariant.

For vectors x and y with covariance matrix S: d(x, y) = √((x-y)ᵀ S⁻¹ (x-y))

When S is the identity matrix, this reduces to Euclidean distance.

*

Reference:
Fréchet, M. (1906). Sur quelques points du calcul fonctionnel. Rendiconti del Circolo Matematico di Palermo.

Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
  • Constructor Details

    • MahalanobisMetric

      public MahalanobisMetric(DenseMatrix<Real> covariance)
      Creates a Mahalanobis metric with the given covariance matrix.
      Parameters:
      covariance - the covariance matrix
  • Method Details

    • identity

      public static MahalanobisMetric identity(int dimension)
      Creates a Mahalanobis metric with identity covariance (equivalent to Euclidean).
      Parameters:
      dimension - the dimension
      Returns:
      the metric
    • distance

      public Real distance(Vector<Real> x, Vector<Real> y)
      Description copied from interface: Metric
      Computes the distance between two objects.
      Specified by:
      distance in interface Metric<Vector<Real>>
      Parameters:
      x - the first object
      y - the second object
      Returns:
      the distance between a and b (always non-negative)
    • getDimension

      public int getDimension()
      Returns the dimension of this metric space.
      Returns:
      the dimension
    • getCovarianceInverse

      public DenseMatrix<Real> getCovarianceInverse()
      Returns the inverse covariance matrix.
      Returns:
      the inverse covariance matrix
    • toString

      public String toString()
      Overrides:
      toString in class Object