Mahalanobis distance computes X_minus_mu incorrectly
j0ma opened this issue · comments
Jonne Sälevä commented
It seems that on Line 91 in mahalanobis.py
the quantity X_minus_mu
seems to be computed incorrectly.
Based on Wikipedia, both x
and mu
should be vectors:
however using np.mean(...)
without specifying the axis returns a scalar:
import numpy as np
reference_distribution = [[1,2], [3,4]]
print(np.mean(reference_distribution))
> 2.5
Instead, if the array is (N, D)
then we can take an overage over the first dimension with np.mean(..., axis=0)
:
import numpy as np
reference_distribution = [[1,2], [3,4]]
print(np.mean(reference_distribution, axis=0))
> [2. 3.]
This means that the same scalar is being subtracted from all components of X
to create X_minus_mu
, which isn't what we want, right?
Please correct me if my understanding is wrong. Thanks!