Week 2: Least squares meets probability: normal equations + multivariate distributions
The Week 1 fit had one adjustable direction. What if a model has many parameters, some of which barely change the observations? We need coordinates that separate what the experiment measures strongly, weakly and not at all.
The SVD supplies those coordinates. It also exposes a distinction that will guide the rest of the course: a best prediction can be unique even when its parameters are not, and a unique parameter estimate can still be unreliable. Probability then gives us a language for the uncertainty that a deterministic error bound cannot describe.
Topics
Matrix factorisations (continued): the singular value decomposition
Least squares and normal equations
Finite-dimensional probability
Matrix factorisations (continued)
Recap: eigenvalues/eigenvectors for Hermitian matrices
Eigenvalue problem: given A∈Cn×n, find λ∈C and q∈Cn such that
Aq=λq,∣q∣=1.
If A is Hermitian/self-adjoint (A=A∗), then:
all eigenvalues λ1,…,λn are real
there exists an orthonormal eigenbasis q1,…,qn with
⟨qi,qj⟩=δij={10i=ji=j
writing Q=[q1⋯qn] and Λ=diag(λ1,…,λn),
Q∗Q=I,A=QΛQ∗.
Using outer products:
A=i=1∑nλi(qi⊗qi).
Recall: for vectors a,b, the outer product acts by
(a⊗b)c=⟨a,c⟩b.
The singular value decomposition (SVD)
An eigenbasis uses the same space for inputs and outputs. A rectangular map has no reason to permit that: its input and output dimensions may differ. Instead, seek paired unit directions satisfying Avi=σiui. Measuring an input along vi produces an output along ui, scaled by σi. This is Week 1's “measure then reconstruct” operation with different rulers on each side.
Theorem (SVD)
Let A∈Km×n (with K=R or C). Then there exist unitary matrices
U∈Km×m,V∈Kn×n,
and a diagonal (rectangular) matrix Σ∈Rm×n with diagonal entries
σ1≥σ2≥⋯≥0
(and zeros off-diagonal) such that
A=UΣV∗.
Equivalently: there exist orthonormal bases u1,…,um of Km and v1,…,vn of Kn and nonnegative numbers σ1,…,σr (where r=rank(A)) such that
Diagonalise the SPSD matrix A∗A. If A∗Avi=σi2vi with σi>0, set ui=Avi/σi. Then
⟨ui,uj⟩=σiσj⟨vi,A∗Avj⟩=δij.
Zero-eigenvalue input directions form kerA; complete the output directions to an ONB. Applying A to the expansion of an arbitrary input proves the displayed decomposition. In particular A∗ui=σivi. The same singular value describes a forward measurement and its adjoint.
Remarks
Select a factor to follow the same operation in the explanation.
Ax = ∑ᵢ
Project x onto the input direction vᵢ, scale that coordinate by σᵢ, then reconstruct along the output direction uᵢ. The sum combines all nonzero singular modes.
The leading singular value is the operator norm:
σ1=∣A∣op:=∣x∣=1max∣Ax∣=x=0max∣x∣∣Ax∣.
Truncating the SVD gives a rank-p approximation ("truncated SVD", related to PCA):
A≈A(p):=i=1∑pσi(vi⊗ui).
Later: compact operators will have an SVD with infinitely many terms and σi→0 as i→∞.
The SVD gives a generalised inverse (pseudoinverse) A†∈Kn×m of
A=i=1∑rσi(vi⊗ui)
via
A†=i=1∑rσi1(ui⊗vi),σi=0for i≤r.
The reciprocal singular values increase in this indexing. Reordering the paired directions gives the conventional decreasing order for an SVD of the pseudoinverse.
The factorisation is a sequence of operations on the same points. Play it slowly: first change input coordinates, then scale, then choose output coordinates. The two spaces need not share their singular directions.
Read, scale, reconstruct
Input unit circle
Transform the same points
1. V* reads the input in the singular basis
Track the solid first basis edge and dashed reference circle. Rotation alone preserves lengths; unequal scaling creates the ellipse.
Play once, pause, or scrub to inspect an intermediate state.
Ready to explore.A=R(35°) diag(1.4,0.5) R(−25°). First rotate into input coordinates, then stretch, then rotate into output coordinates. Intermediate maps interpolate each operation; only the endpoint is A. ↗
Exercises (from the notes)
Let A=∑i=1rσi(vi⊗ui) be an SVD. Show:
A∗=i=1∑rσi(ui⊗vi),A∗A=i=1∑rσi2(vi⊗vi).
What is AA∗?
Least squares and normal equations
Given A∈Km×n and b∈Km, consider the least squares problem: find x∈Kn minimising
Φ(x):=21∣Ax−b∣2=21j=1∑m∣(Ax)j−bj∣2.
Over the real numbers, differentiate the squared residual. Over the complex numbers, regard the domain as a real vector space with metric Re⟨⋅,⋅angle; the same gradient expression holds:
∇Φ(x)=A∗Ax−A∗b.
Hessian/second derivative (constant in x):
∇2Φ(x)=A∗A,
and A∗A is SPSD.
Therefore, minimisers are precisely the solutions of the normal equations:
A∗Ax=A∗b.
Special case: if A has full column rank, then A∗A is invertible and the minimiser is unique:
x†:=(A∗A)−1A∗b.
A nontrivial kernel removes uniqueness of the parameters, while leaving the best predicted vector unique.
If A has SVD A=∑i=1rσi(vi⊗ui), then (using the exercise identities)
x†=(A∗A)−1A∗b=i=1∑rσi1(ui⊗vi)b,
i.e.
x†=A†b.
The normal equations are also the perpendicular-residual condition from Week 1: A∗(Ax−b)=0 says that the residual is orthogonal to every attainable prediction. For any minimiser x0 and increment h,
∣A(x0+h)−b∣2=∣Ax0−b∣2+∣Ah∣2.
Thus every minimiser is A†b+z with z∈kerA. Since A†b⊥kerA, it uniquely minimises parameter norm. The inverse (A∗A)−1 in the preceding formula is available only at full column rank; the singular expansion remains valid at any rank.
Numerical interpretation. For full column rank, κ2(A∗A)=κ2(A)2. Normal equations explain the geometry beautifully, but QR or SVD avoids explicitly squaring the condition number when computing sensitive fits.
Stability note
The inverse formula above assumes full column rank. The pseudoinverse itself is defined for rank-deficient matrices as well; it selects the minimum-norm least-squares solution.
Before reading the bounds, consider which data perturbations the inverse amplifies most in Figure 1.
Equal data errors, unequal reconstruction errors
Error norm: 0.361. Upper bound 0.1 / σ₂: 0.500.
1. Resolve the data error
δb = 0.1(cos θ u₁ + sin θ u₂). Its length remains 0.1.
2. Undo each nonzero scale
A†δb = 0.1 cos θ v₁ + (0.1 / σ₂) sin θ v₂.
3. Find the worst direction
For σ₂ < 1 the bound is attained along ±u₂. At σ₂ = 1 every direction is equally sensitive. At σ₂ = 0 the pseudoinverse discards the second mode; it cannot recover information lost there.
Figure 1. A real two-dimensional teaching model: A = diag(1, σ₂), U = V = I. Rotate a data perturbation of fixed length 0.1; then reduce σ₂. The dashed circle and ellipse show all possible endpoints. The panels use different, fixed scales: ±0.12 and ±2.1. ↗
Forward map is stable:
∣A(x+δx)−Ax∣=∣A(δx)∣≤∣A∣op∣δx∣=σ1∣δx∣.
For rank r>0, the inverse map can be sensitive:
∣A†(b+δb)−A†b∣=∣A†(δb)∣≤∣A†∣op∣δb∣=σr1∣δb∣.
The constant σr−1 can be huge; reconstructions A†b are sensitive to perturbations in b parallel to singular vectors ui corresponding to small σi.
At fixed finite rank the pseudoinverse is bounded, but its norm may be enormous. Infinite-dimensional compact inverses in Week 8 can be unbounded: sensitivity then becomes ill-posedness in the continuity sense. For the zero matrix, the pseudoinverse is zero and the positive-singular-value bound is unnecessary.
Hold the amount of observation noise fixed and let just one singular value shrink. The evolving ellipse isolates why a small forward response can produce a large inverse error.
A weak measurement becomes a large inverse error
Fixed observation noise
Error after inversion
σ₂=1.000, max error=0.1/σ₂=0.100
The first inverse direction is unchanged. The weak second measurement stretches the same noise into a long reconstruction-error ellipse.
Play once, pause, or scrub to inspect an intermediate state.
Ready to explore.Fixed data noise has length 0.1. A=diag(1,σ₂), with σ₂ decreasing from 1 to 0.1. The error ellipse has semiaxes 0.1 and 0.1/σ₂. All axis scales remain fixed; zero is excluded. ↗
Probability (finite-dimensional)
A bound such as ∣δx∣≤∣δb∣/σr protects against the worst direction. It does not say how often that direction occurs. To ask about typical errors or uncertainty in a parameter, we must specify which outcomes are possible and how much probability they receive. A probability space makes those choices explicit.
Kolmogorov setup
A non-empty set Ω (sample space/outcome space).
A collection of measurable events F⊆P(Ω), required to be a σ-algebra:
∅,Ω∈F
if E∈F then Ω∖E∈F
if E1,E2∈F then E1∩E2∈F and E1∪E2∈F
if E1,E2,⋯∈F then ⋃n∈NEn∈F and ⋂n∈NEn∈F
(Annotation: F is like a list of questions it is "ok" to ask about the outcome ω∈Ω; if E∈F you may ask whether ω∈E.)
A probability measure P:F→[0,1] such that:
P(Ω)=1 and P(∅)=0
P(Ω∖E)=1−P(E)
if E1,E2,⋯∈F are pairwise disjoint, then
P(n∈N⨆En)=n∈N∑P(En).
Interpretations of probability
Two main meanings of P(E):
Frequentist: idealised replicable experiment; on each run E happens or not; under iid replication, the strong law gives
P(E)=n→∞limnNumber of times E occurs in first n trials
Bayesian/subjectivist: can speak of probability of any statement E, using probabilities to express degrees of belief. Probability one means almost sure, not logical necessity: a specified point in a continuous distribution has probability zero without being impossible.
Epistemic (reducible) uncertainty: due to lack of knowledge; can decrease with more information.
Bayes' formula (events)
For A,B∈F with P(A)>0 and P(B)>0, define conditional probability
P(A∣B):=P(B)P(A∩B).
Then
P(B∣A)P(A)=P(A∩B)=P(A∣B)P(B),
so
P(A∣B)=P(B)P(B∣A)P(A).
Annotations:
P(A∣B): posterior probability
P(A): prior probability (before seeing data B)
P(B∣A): likelihood (from a model for what data should do if A is true)
P(B): normalising factor; also called the marginal likelihood / evidence
Random variables and distributions
A real-valued random variable is a measurable function x:Ω→R defined on a probability space (Ω,F,P).
A random vector is a measurable function x:Ω→Rn, i.e. x=(x1,…,xn) with each xi a random variable.
The law/distribution of x is the induced probability measure μx on Rn:
μx(A):=P({ω∈Ω:x(ω)∈A})=P[x∈A]=P(x−1(A)).
From a law to a question about data
The law tells us how to average any integrable quantity: E[f(x)]=∫f(z)μx(dz). In particular, for a real vector with finite second moment,
m=E[x],C=E[(x−m)(x−m)T],ℓTCℓ=E[(ℓT(x−m))2]≥0.
Covariance is therefore a positive matrix for a reason: every directional test is a variance. Week 3 asks which distributions are completely described by this mean and covariance, and what observing some coordinates tells us about the others.