Norms and Distance Metrics

2 min read

A norm x\|\mathbf{x}\| measures the "size" of a vector. Norms underlie nearly every loss function, regularizer, and similarity measure in ML.

Common norms (LpL^p family):

NormFormulaUse in ML
L1L^1 (Manhattan)ixi\sum_i \|x_i\|Lasso regression, sparse solutions
L2L^2 (Euclidean)ixi2\sqrt{\sum_i x_i^2}Default distance, Ridge regression, weight decay
LL^\infty (Max)maxixi\max_i \|x_i\|Adversarial robustness (perturbation budgets)
L0L^0 (pseudo-norm)count of nonzero entriesSparsity (NP-hard to optimize, L1L^1 is the convex relaxation)

Frobenius norm for matrices: AF=ijaij2\|A\|_F = \sqrt{\sum_{ij} a_{ij}^2} — the L2L^2 norm of a matrix flattened into a vector.

Key distance metrics:

  • Euclidean distance: d(a,b)=ab2d(\mathbf{a}, \mathbf{b}) = \|\mathbf{a} - \mathbf{b}\|_2
  • Cosine similarity: abab\frac{\mathbf{a} \cdot \mathbf{b}}{\|\mathbf{a}\|\|\mathbf{b}\|} — measures angle, ignores magnitude. Dominant in embeddings and retrieval
  • Mahalanobis distance: accounts for covariance structure — Euclidean distance after whitening

Why this matters everywhere:

  • Regularization is just adding a norm penalty: L1L^1 → sparsity, L2L^2 → small weights
  • Loss Functions are often norms of the residual: MSE = squared L2L^2, MAE = L1L^1
  • Cosine similarity is the scoring function inside Self-Attention (after normalization by dk\sqrt{d_k})

See also: Dot Product, Regularization, Embeddings

Linked from