Need for Mahalanobis distance
Distance calculated using euclidean geometry provides the absolute value between an origin and the target, yet this quantity lacks on stating how unique/unremarkable a particular point is in a data cluster. Standard deviation of a probability distibution comments on how the variables are spread. Mahalanobis distance is that quantity that tells the measure of a point from the mean in terms of standard deviation. This is particularly required in point clouds because this helps in determining outliers/noise while performing Iterative Closing Point Algorithm.
Formulas to get familiar with
- The Mahalanobis distance is calculated as:
- Setting (the deviation from the mean):
- is the covariance matrix
- Let , so each observation is a 2D vector and the mean is . The deviation vector for observation
- The outer product is . This is a column vector times a row vector — giving a matrix:
note: d is number of features(columns) and n is number of observations (rows)
- Sum over all observations
- Divide by
Reading each entry
- : — variance of feature 1. Same feature squared with itself.
- : — covariance of feature 1 and 2. Two different features multiplied.
- : same as — always symmetric since multiplication is commutative.
- : — variance of feature 2.
Connection to (centered data)
The formula and are the same thing written two different ways:
- The summation form adds up outer products one observation at a time
- The matrix form stacks all observations into and does one matrix multiplication
Both produce the identical covariance matrix — the summation form makes the meaning explicit, the matrix form is compact and fast to compute.
⚠️ Centering requirement: The matrix form only equals the covariance matrix if is mean-centered — each row must be , so every column sums to zero. The summation form has built into each term; the matrix form must bake it into itself.
On raw (uncentered) data, gives the second moment matrix instead:
equal to only when .
Centering ≠ normalising. The ladder:
- Raw → second moment matrix
- Centered → covariance matrix ← what Mahalanobis needs
- Centered + scaled by std dev → correlation matrix Worked example (1 feature, ): let , so .
Centered:
This matches exactly. ✓
Raw (uncentered): using directly
7 is not the variance — it’s inflated by the mean not being zero. This is exactly . ✓
Skipping the centering step silently swaps “spread around the mean” for “spread around zero” — the two only agree when .
Note: The query point in never needs pre-centering — the inside the formula centers it explicitly. Centering only matters for how is computed from the data matrix.
What is covariance, variance and standard deviation? and Ohh my Gaussian Curve
- is variance — the average squared deviation of points from the mean; it measures how spread out the distribution is
-
is the standard deviation — the square root of the variance. Taking the root brings the units back to the first power (e.g. meters instead of meters²), same units as the data.
-
covariance tells how two features vary with respect to each other — positive when they move together, negative when they move oppositely, near zero when unrelated
-
variance () can also be written as
-
Where is:
And is the Gaussian density formula:
-
is the normalising constant to keep area under curve equal to 1.
-
A Gaussian random variable is written where is the mean and is the variance
-
all Gaussian curves are bell shaped but they can be shifted (by tuning ) or stretched/squeezed (by tuning )

-
area under all theses curves is 1
-
Probability gives me a confidence/cerainity score of the belief we have on a method/result. A self driving car gets a LiDAR reading of 3.2 m to hit an obstacle, is it safe? It depends entirely on th threshold value of an acceptable uncertanity score. If is less than 0.05m, then it is fine.
So what the f*ck is Singular Value Decomposition?????
Any matrix irrespective of its shape; number of independent columns it has (rank); and the numbers present in it, can be decomposed into 3 matrices. That is it!!! It is all that is need to be known to understand SVD apart from the formula.
Now, the formula is made up of 3 matrices which basically rotate, transform, and maybe rotate any input vector again. The 3 stooges of matrices are made of the square roots of the eigen values and eigen vector of and eigen vector .
- columns are eigen vectors of
- is the singular values of , which are the square roots of the eigen values of
- matrix consist of columns which are eigenvectors of
NOTE: SVD works only if and are orthonormal vectors. We will see why.
Substituting the normalised input eigen vector from eqn in eqn
Substituting eqn in eqn we get
Since is a unit vector, (a scalar, not the identity matrix — that only applies when dotting a full orthonormal matrix with its transpose, e.g. ). Therefore eqn is
we know that the magnitude of from eqn
In eqn multiply both sides by
normalising we get
If we stack this relationship horizontally for all vector dimensions simultaneously, it maps perfectly to an equivalent matrix-matrix multiplication:
This simplifies neatly down to:
Because is an orthogonal matrix built from an orthonormal basis of eigenvectors, its inverse is identical to its transpose (). Right-multiplying both sides by completely isolates :
So we have answered why we are using orthonormal eigenvectors and values of for decomposing the matrix with the above derivation.

Why did you even bring up mahalanobis distance and singular value decomposition together?
Look at the formulas of Mahalanobis distance and SVD they look similar. But that isn’t enough, we need to answer if Mahalanobis distance is doing SVD. This intuition is partly right. Mahalanobis distance is prefere because the formula converts an anisotropic distribution (uneven) to isotropic distribution.
From the previous formulas we can infer that covariance matrix is
Substituting:
(using and since is diagonal)
Therefore:
Note the order — it’s , not . This matters: it tells you (not ) holds the eigenvectors as its columns, matching the standard eigendecomposition convention .
Hence eigenvalues of
where are the singular values of .
Is Mahalanobis distance doing SVD?
Short answer: partly right, partly wrong. Mahalanobis distance uses the same underlying machinery as SVD — rotation by eigenvectors, scaling by eigenvalues — but it is not performing SVD itself. What it’s actually doing is eigendecomposition, applied specifically to the covariance matrix, followed by a distance computation that SVD alone doesn’t give you.
What eigendecomposition actually is
For a symmetric matrix like , eigendecomposition is:
- : columns are eigenvectors of (same on both sides — this only works because is symmetric)
- : diagonal matrix of eigenvalues
Compare this to general SVD:
- Two different matrices and — because is not necessarily symmetric, so its “natural input direction” and “natural output direction” can differ
- contains singular values , not eigenvalues (which can be negative or complex for a non-symmetric )
Why they coincide for
Since the covariance matrix is symmetric and positive semi-definite:
- Its eigenvalues are guaranteed real and
- Its eigenvectors are orthogonal
- Therefore in its SVD, and its singular values equal its eigenvalues exactly
So for specifically, eigendecomposition and SVD collapse into the same operation. That’s the source of the “Mahalanobis is doing SVD” intuition — it isn’t wrong, it’s just that SVD and eigendecomposition happen to be indistinguishable for this one special (symmetric PSD) case.
Building Mahalanobis distance from the eigendecomposition
Start from:
Substitute (valid since for orthogonal ):
Let — this is rotated into the eigenvector basis. Then:
The actual comparison: SVD pipeline vs Mahalanobis pipeline
| Step | SVD applied to a vector () | Mahalanobis distance |
|---|---|---|
| 1 | rotate: | rotate: |
| 2 | scale: multiply by | scale: divide by |
| 3 | rotate again: | no third rotation — take the norm instead |
| output | a transformed vector | a scalar distance |
Two concrete differences:
- SVD stretches; Mahalanobis compresses. SVD’s multiplies by (stretch). Mahalanobis’s divides by (compress) — it’s undoing the natural spread of the data, not applying it.
- SVD ends in a rotation; Mahalanobis ends in a norm. The third SVD step rotates the scaled vector back into output space, giving another vector. Mahalanobis instead takes at that point, collapsing everything to a single number.
What this operation is actually called
The two-step transform (rotate, then scale-down) is called whitening — it takes an anisotropic (unevenly spread, correlated) distribution and turns it into an isotropic (evenly spread in all directions, uncorrelated) one:
Once whitened, ordinary Euclidean distance on is the Mahalanobis distance on — because in the whitened space every direction is equally spread, so there’s no shape left to correct for. That’s the real punchline: Mahalanobis distance = Euclidean distance, computed after first eliminating the covariance.

Verdict
Mahalanobis distance is not doing SVD. It is doing:
- Eigendecomposition of (which happens to coincide with SVD only because is symmetric PSD)
- A whitening transform (rotate + inverse-scale) built from that eigendecomposition
- A final Euclidean norm — a step SVD itself never includes
The formulas look similar because both are built from the same eigenvector/eigenvalue skeleton. But SVD’s job is to decompose a general transformation into a vector output; Mahalanobis’s job is to measure a distance that accounts for the shape of the data, ending in a scalar. Same skeleton, different destinations.
References
Get a detailed understanding here →