§2.5–2.10Norms · Special Matrices · Eigendecomposition · SVD · Pseudoinverse · Trace

Part I DL pp. 39–46 · ~8 min read

  • norm
  • frobenius norm
  • diagonal matrix
  • symmetric matrix
  • orthogonal matrix
  • eigenvector
  • eigenvalue
  • eigendecomposition
  • positive definite
  • singular value decomposition
  • moore-penrose pseudoinverse
  • trace

§2.5 Norms — measuring the size of a vector

Machine learning measures vector size with a norm , most often from the LpL^p family:

Term by term

xp=(ixip)1/p,p1\|\boldsymbol{x}\|_p = \Big(\sum_i |x_i|^p\Big)^{1/p}, \quad p \ge 1
xi|x_i|each element enters through its absolute value — sign never matters to sizescalar ≥ 0
ppthe exponent that decides HOW sizes combine: small p treats elements equally, large p lets the biggest dominatereal ≥ 1
xp\|\boldsymbol{x}\|_pthe distance from the origin to x, as measured by this pscalar ≥ 0

Formally a norm is any function with three properties: f(x)=0x=0f(\boldsymbol{x}) = 0 \Rightarrow \boldsymbol{x} = \boldsymbol{0}; the triangle inequality f(x+y)f(x)+f(y)f(\boldsymbol{x}+\boldsymbol{y}) \le f(\boldsymbol{x}) + f(\boldsymbol{y}); and homogeneity f(αx)=αf(x)f(\alpha\boldsymbol{x}) = |\alpha| f(\boldsymbol{x}).

The unit ball ‖x‖ₚ = 1, morphing with p — diamond (L¹) → circle (L²) → square (L^∞)
x = [0.6, 0.8]L^∞

‖x‖2 = 1.000

The shaded region is the unit ball ‖x‖ₚ ≤ 1. At p = 1 it has corners ON the axes — the geometric seed of L¹'s preference for exact zeros (§7.1 builds on this).

The family members you will meet constantly:

  • L2L^2 (Euclidean) — so common it is written plainly x\|\boldsymbol{x}\|. Its square is just xx\boldsymbol{x}^\top\boldsymbol{x}, which is far nicer analytically: each derivative x22/xi=2xi\partial \|x\|_2^2 / \partial x_i = 2x_i depends only on its own element, while derivatives of the unsquared norm entangle the whole vector.
  • L1L^1x1=ixi\|\boldsymbol{x}\|_1 = \sum_i |x_i|. The squared L2L^2 norm grows very slowly near the origin; when the difference between exactly-zero and small-but-nonzero matters, L1L^1 grows at the same rate everywhere (ϵ\epsilon of movement costs exactly ϵ\epsilon).
  • "L0L^0" — counting nonzero entries is not a norm (scaling by α\alpha doesn’t change the count, violating homogeneity); the term is a common abuse. L1L^1 is the usual substitute.
  • LL^\infty (max norm)x=maxixi\|\boldsymbol{x}\|_\infty = \max_i |x_i|.
  • Frobenius norm for matrices — AF=i,jAi,j2\|\boldsymbol{A}\|_F = \sqrt{\sum_{i,j} A_{i,j}^2}, the L2L^2 of a matrix flattened.

Worked example — one vector, three sizes

For x=[3,4]\boldsymbol{x} = [3, -4]^\top: x1=3+4=7\|\boldsymbol{x}\|_1 = 3 + 4 = 7; x2=9+16=5\|\boldsymbol{x}\|_2 = \sqrt{9 + 16} = 5; x=4\|\boldsymbol{x}\|_\infty = 4. Always 21\|\cdot\|_\infty \le \|\cdot\|_2 \le \|\cdot\|_1.

Finally, the dot product in norm language: xy=x2y2cosθ\boldsymbol{x}^\top\boldsymbol{y} = \|\boldsymbol{x}\|_2 \|\boldsymbol{y}\|_2 \cos\theta with θ\theta the angle between them.

§2.6 Special matrices and vectors

v₁000v₂000v₃diagonal — diag(v)x = v ⊙ xa₁₁a₁₂a₁₃a₁₂a₂₂a₂₃a₁₃a₂₃a₃₃symmetric — A = Aᵀ (mirrored pairs)orthogonal — AᵀA = AAᵀ = I, so A⁻¹ = Aᵀ
  • A diagonal matrix diag(v)\mathrm{diag}(\boldsymbol{v}) is mostly zeros; multiplying is just element-wise scaling (diag(v)x=vx\mathrm{diag}(\boldsymbol{v})\boldsymbol{x} = \boldsymbol{v} \odot \boldsymbol{x}) and inverting is element-wise reciprocals (diag(v)1=diag([1/v1,,1/vn])\mathrm{diag}(\boldsymbol{v})^{-1} = \mathrm{diag}([1/v_1, \dots, 1/v_n]^\top), existing iff every vi0v_i \ne 0). Many algorithms get cheaper (and less expressive) when a general matrix is restricted to diagonal. Rectangular diagonal matrices exist too: multiply-then-pad (tall) or multiply-then-truncate (wide).
  • A symmetric matrix equals its transpose — typical when entries come from an order-independent function, like distances: Ai,j=Aj,iA_{i,j} = A_{j,i}.
  • A unit vector has x2=1\|\boldsymbol{x}\|_2 = 1. Vectors with xy=0\boldsymbol{x}^\top\boldsymbol{y} = 0 are orthogonal (at 90° if nonzero); at most nn nonzero vectors in Rn\mathbb{R}^n can be mutually orthogonal; orthogonal + unit norm = orthonormal.
  • An orthogonal matrix has mutually orthonormal rows AND columns: AA=AA=I\boldsymbol{A}^\top\boldsymbol{A} = \boldsymbol{A}\boldsymbol{A}^\top = \boldsymbol{I}, hence A1=A\boldsymbol{A}^{-1} = \boldsymbol{A}^\top — inversion for the price of a transpose. (Watch the naming trap: the matrix is called orthogonal but its rows are orthonormal; there is no special name for merely-orthogonal rows.)

§2.7 Eigendecomposition

Integers reveal their nature when factored into primes — 12=2×2×312 = 2 \times 2 \times 3 tells us things no digit string does. Matrices factor too. An eigenvector of A\boldsymbol{A} is a nonzero direction that multiplication by A\boldsymbol{A} only rescales, and its scale factor is the eigenvalue :

Term by term

Av=λv\boldsymbol{A}\boldsymbol{v} = \lambda\boldsymbol{v}
v\boldsymbol{v}an eigenvector — a direction A does not rotate (any rescaling sv works too, so we use unit v)n×1, ≠ 0
λ\lambdaits eigenvalue — how much A stretches (|λ|>1), shrinks (|λ|<1), or flips (λ<0) that directionscalar

With nn independent eigenvectors as columns of V\boldsymbol{V} and eigenvalues in λ\boldsymbol{\lambda}, the eigendecomposition is A=Vdiag(λ)V1\boldsymbol{A} = \boldsymbol{V}\,\mathrm{diag}(\boldsymbol{\lambda})\,\boldsymbol{V}^{-1}. Not every matrix has one (some need complex numbers; non-square matrices have none) — but every real symmetric matrix decomposes with real values and an orthogonal eigenbasis:

A=QΛQ\boldsymbol{A} = \boldsymbol{Q}\boldsymbol{\Lambda}\boldsymbol{Q}^\top

What this really says

A symmetric matrix is nothing but independent stretches along perpendicular axes: rotate into the eigenbasis (Q\boldsymbol{Q}^\top), scale each axis by its λi\lambda_i (Λ\boldsymbol{\Lambda}), rotate back (Q\boldsymbol{Q}). Every fact below — determinants, definiteness, conditioning in ch. 4 — is read straight off those stretch factors.

Fig 2.3 (interactive) — A = QΛQᵀ distorts the unit circle into an ellipse: λᵢ stretches along eigendirection v⁽ⁱ⁾
all unit vectors uv⁽¹⁾v⁽²⁾→ A →their images Auλ₁v⁽¹⁾λ₂v⁽²⁾

A = [[1.68, 0.56], [0.56, 1.02]] (symmetric)

det(A) = λ₁λ₂ = 1.40

class: positive definite

What the decomposition tells you:

  • Uniqueness: sort Λ\boldsymbol{\Lambda} descending; unique iff all eigenvalues distinct (repeated λ’s let any orthogonal basis of their span serve).
  • Singularity: A\boldsymbol{A} is singular ⟺ some eigenvalue is 0 (watch the ellipse flatten in the widget as λ₂ → 0).
  • Quadratic optimization: for f(x)=xAxf(\boldsymbol{x}) = \boldsymbol{x}^\top\boldsymbol{A}\boldsymbol{x} with x2=1\|\boldsymbol{x}\|_2 = 1, ff equals λ\lambda whenever x\boldsymbol{x} is the corresponding eigenvector; max/min over the sphere = max/min eigenvalue.
  • Definiteness: all λ > 0 → positive definite (xAx=0x=0\boldsymbol{x}^\top\boldsymbol{A}\boldsymbol{x} = 0 \Rightarrow \boldsymbol{x} = 0); λ ≥ 0 → positive semidefinite (x,xAx0\forall \boldsymbol{x},\, \boldsymbol{x}^\top\boldsymbol{A}\boldsymbol{x} \ge 0); mirrored for negative (semi)definite.

Worked example — eigen-factor a 2×2

A=[3113]\boldsymbol{A} = \begin{bmatrix} 3 & 1 \\ 1 & 3 \end{bmatrix}: along v(1)=12[1,1]\boldsymbol{v}^{(1)} = \tfrac{1}{\sqrt 2}[1,1]^\top, Av(1)=12[4,4]=4v(1)\boldsymbol{A}\boldsymbol{v}^{(1)} = \tfrac{1}{\sqrt 2}[4,4]^\top = 4\boldsymbol{v}^{(1)} — so λ1=4\lambda_1 = 4. Along v(2)=12[1,1]\boldsymbol{v}^{(2)} = \tfrac{1}{\sqrt 2}[1,-1]^\top, λ2=2\lambda_2 = 2. Set the widget to λ₁=2 → try it: with θ=45° you can reproduce this A up to scale. Positive definite (both λ > 0), det = 8.

§2.8 Singular value decomposition

The SVD factors every real matrix — square or not — where eigendecomposition may not exist:

Term by term

A=UDV\boldsymbol{A} = \boldsymbol{U}\boldsymbol{D}\boldsymbol{V}^\top
U\boldsymbol{U}orthogonal; columns = left-singular vectors = eigenvectors of AAᵀm×m
D\boldsymbol{D}rectangular diagonal; entries = singular values = √ of eigenvalues of AᵀAm×n
V\boldsymbol{V}orthogonal; columns = right-singular vectors = eigenvectors of AᵀAn×n
xinputVᵀxrotate (orthogonal Vᵀ)DVᵀxscale each axis (diagonal D)UDVᵀx = Axrotate (orthogonal U)

Any linear map = rotate → per-axis scale → rotate (diagram not in the book). The EigenLens above is the special case U = V = Q.

§2.9 The Moore-Penrose pseudoinverse

Non-square matrices have no inverse, but linear equations Ax=y\boldsymbol{A}\boldsymbol{x} = \boldsymbol{y} still want solving. The pseudoinverse is defined as A+=limα0(AA+αI)1A\boldsymbol{A}^+ = \lim_{\alpha \to 0}(\boldsymbol{A}^\top\boldsymbol{A} + \alpha\boldsymbol{I})^{-1}\boldsymbol{A}^\top, but computed via the SVD:

Term by term

A+=VD+U\boldsymbol{A}^+ = \boldsymbol{V}\boldsymbol{D}^+\boldsymbol{U}^\top
D+\boldsymbol{D}^+reciprocate the nonzero singular values, then transpose the (rectangular) resultn×m
A+\boldsymbol{A}^+the "best-effort inverse": run the SVD pipeline backwards, skipping the collapsed directionsn×m

Its behavior depends on A\boldsymbol{A}‘s shape:

  • Wide (more columns than rows, typically ∞ solutions): x=A+y\boldsymbol{x} = \boldsymbol{A}^+\boldsymbol{y} is the solution with minimal norm x2\|\boldsymbol{x}\|_2 among all of them.
  • Tall (more rows than columns, possibly no solution): it gives the x\boldsymbol{x} making Ax\boldsymbol{A}\boldsymbol{x} as close as possible to y\boldsymbol{y} in Axy2\|\boldsymbol{A}\boldsymbol{x} - \boldsymbol{y}\|_2 — least squares, previewing chapter 4’s worked example.

§2.10 The trace operator

The trace sums the diagonal: Tr(A)=iAi,i\mathrm{Tr}(\boldsymbol{A}) = \sum_i A_{i,i}. It converts summation-notation gymnastics into algebra:

  • AF=Tr(AA)\|\boldsymbol{A}\|_F = \sqrt{\mathrm{Tr}(\boldsymbol{A}\boldsymbol{A}^\top)}
  • transpose-invariant: Tr(A)=Tr(A)\mathrm{Tr}(\boldsymbol{A}) = \mathrm{Tr}(\boldsymbol{A}^\top)
  • cyclic-permutation-invariant: Tr(ABC)=Tr(CAB)=Tr(BCA)\mathrm{Tr}(\boldsymbol{A}\boldsymbol{B}\boldsymbol{C}) = \mathrm{Tr}(\boldsymbol{C}\boldsymbol{A}\boldsymbol{B}) = \mathrm{Tr}(\boldsymbol{B}\boldsymbol{C}\boldsymbol{A}) — valid even when the cycled products have different shapes: for ARm×n\boldsymbol{A} \in \mathbb{R}^{m\times n}, BRn×m\boldsymbol{B} \in \mathbb{R}^{n\times m}, Tr(AB)=Tr(BA)\mathrm{Tr}(\boldsymbol{A}\boldsymbol{B}) = \mathrm{Tr}(\boldsymbol{B}\boldsymbol{A}) though one is m×mm{\times}m and the other n×nn{\times}n.
  • a scalar is its own trace: a=Tr(a)a = \mathrm{Tr}(a).

Worked example — cycling a trace

A=[1  2]\boldsymbol{A} = [1\; 2] (1×2), B=[3,4]\boldsymbol{B} = [3, 4]^\top (2×1). AB=[11]\boldsymbol{A}\boldsymbol{B} = [11] (1×1), trace 11. BA=[3648]\boldsymbol{B}\boldsymbol{A} = \begin{bmatrix} 3 & 6 \\ 4 & 8 \end{bmatrix} (2×2), trace 3+8=113 + 8 = 11. Different shapes, same trace — this identity powers the PCA derivation in the next section.

Check yourself — norms to trace

1.Why is counting nonzero entries (the so-called 'L⁰ norm') not actually a norm?

2.In the NormBallLab, what happens to the unit ball's corners as p slides from 2 down to 1, and why will ch. 7 care?

3.In the EigenLens, you set λ₁ = 2, λ₂ = 0. What do you observe?

4.Why does the book emphasize the SVD over eigendecomposition?

5.A is tall (more rows than columns) and Ax = y has no exact solution. What does x = A⁺y give you?

5 questions