Analytic Geometry
Units 1–2 built the board; nothing on it has a size yet. This unit installs the ruler and the protractor: norms for length, inner products for angles, distances for "how far." Then the twist — you get to design the ruler — and half of machine learning turns out to be exactly that: choosing the right way to measure similarity.
The quest for "similar"
Netflix wants to recommend your next film. Behind the screen, you are a vector; every movie is a vector; and the recommender's whole job is to find movies whose vectors are close to yours. Spotify does it with songs, search engines with documents, LLMs with meanings. One question runs the show: what exactly does "close" mean?
Your school reflex says: straight-line (Euclidean) distance. Perfectly valid — and just one option among many. If "director" matters more than "runtime" when comparing movies, you'd want a measure that weights the director dimension more heavily. The standard ruler isn't wrong; it's merely default. This unit is about building custom rulers — safely, so that geometry never breaks.
The route: ① pin down what any notion of length must satisfy (norms); ② reverse-engineer the dot product into a blueprint and generalize it (inner products); ③ meet the engine that powers every legal ruler (symmetric positive-definite matrices); ④ collect the payoff — distances, angles, orthogonality, and the cleanest coordinate systems in mathematics (orthonormal bases, via Gram–Schmidt).
Norms — what "length" is allowed to mean
A norm is any function that behaves the way length must. Three non-negotiables: absolute homogeneity (double the vector, double the length — flipping sign changes nothing); the triangle inequality (no detour is shorter than the direct route); and positive definiteness , with only for (nothing real has negative size; only nothing has size zero).
Two rulers you already own:
Define = the number of non-zero entries of (ML calls it "ℓ₀"). Is it a norm?
A taxi drives from the origin to the point on a perfect street grid. How far does the meter run — and how far did the crow fly?
Inner products — the blueprint under the dot product
The dot product looks like mere arithmetic, but it's secretly an alignment meter: positive when vectors point the same general way, negative when opposed, zero when perpendicular. Take it apart and exactly three load-bearing properties appear. Bilinearity: linear in each slot — , and the same in the second argument. Symmetry: — x's similarity to y is y's similarity to x. Positive definiteness: for every — self-similarity is positive, because it's about to play the role of squared length.
The creative leap of the whole unit: stop treating those three properties as observations about the dot product, and start treating them as a blueprint. ANY function that is bilinear, symmetric, and positive-definite is called an inner product, and the pair an inner product space. The dot product becomes one citizen of a big family — and every member of the family will hand us lengths, distances, and angles that behave. The obvious next question: how do we manufacture new members?
Define . It's bilinear and symmetric. Which axiom does it break?
The engine room — symmetric positive-definite matrices
Here's the master recipe. Notice first that the humble dot product is a matrix sandwich in disguise: — the identity matrix is its engine. Now swap engines. The slides' theorem: on a finite-dimensional space with a chosen basis, is an inner product iff there is a symmetric, positive-definite (SPD) matrix with
Symmetric: (inherits the symmetry axiom). Positive-definite: for all (inherits the length axiom). Two facts fall out immediately, both from Unit 1's toolbox. SPD ⇒ full rank: for every non-zero means no non-zero vector is allowed in the null space — the blind spot is , so is invertible. Diagonals are positive: feed the canonical basis vector into both slots: .
What does the engine do, geometrically? It reshapes space's sense of size. Watch the fingerprint — the unit ball — as you tune the engine:
Why must every diagonal entry of a positive-definite matrix be strictly positive?
Lengths, distances — and the inequality that runs everything
Every inner product ships with a free ruler: the induced norm . (The traffic doesn't flow backwards: the Manhattan norm is a perfectly legal norm that comes from no inner product — inner-product geometry is the smoother, "round-ball" subfamily.) From the norm comes a distance: — with the dot product, that's the Euclidean distance. A distance function (a metric) keeps four promises: ; ; symmetry; and the triangle inequality .
Inner product and metric feel like twins but read in opposite directions: when and huddle close, the distance is small while the inner product is typically large; pull them apart and distance grows while the inner product shrinks. Recommender systems use both dialects — "minimize distance" and "maximize similarity" are the same instinct on different gauges. Don't mix them up mid-formula.
And now the inequality the whole unit leans on — Cauchy–Schwarz:
Alignment can never exceed the product of the sizes. It's the fact that makes "the angle between two vectors" a legal phrase — coming up next.
The slides' two-line proof — one clever vector does all the work
Take any and look at the vector . Its squared length can't be negative: . Now make the smartest possible choice, (you'll recognize it in Section 10 as the shadow coefficient), and the inequality collapses to , i.e. — Cauchy–Schwarz. Nothing used the dot product specifically: the proof runs verbatim for any inner product. Geometry: the residual after removing u's shadow along v has non-negative length — that's the whole theorem.
Why is Cauchy–Schwarz exactly what makes "the angle between and " well-defined?
Angles — the similarity dial
Cauchy–Schwarz says the ratio below always lands in , so there is a unique angle with
— and this number, cosine similarity, is ML's favorite similarity dial: +1 same direction, 0 unrelated (perpendicular), −1 opposite. It measures orientation agreement while ignoring size — which is exactly why search engines compare a three-word query to a thousand-word document with it. Two vectors with are orthogonal, written (the zero vector, ever the freeloader, is orthogonal to everything).
Two embedding vectors drift closer and closer together. What happens to the two gauges?
The high-dimension miracle
The slides end one page with a dare: pick two vectors at random in high dimensions — what happens to the angle between them? Write a small program to see… The program is written; it's below. Sample pairs of random vectors (each coordinate an independent Gaussian), compute their cosine similarity, and pile up a histogram. Then drag the dimension slider and watch a law of nature emerge.
You sample two random vectors in . Their angle is almost certainly…
Orthogonality is in the eye of the ruler
Here's the unit's sneakiest lesson, straight from the slides. Take and . Under the dot product: — perfectly orthogonal. Now switch the engine to :
Same two arrows, new ruler — and they are no longer perpendicular (the angle is about ). Nothing moved except our definition of measurement. If you haven't already, hit the diag(2, 1) preset in Section 4's lens and watch the unit circle deform while the verdict flips. The deep point: "perpendicular" is not a property of two vectors; it's a property of two vectors plus a ruler. Choose the ruler to match the problem — that's feature weighting, Mahalanobis distance, and attention temperature, all in embryo.
and are orthogonal under the dot product. Under with , they are…
Orthonormal matrices — the motions that don't lie
A square matrix whose columns are orthonormal (mutually , each of unit length) is called an orthogonal matrix, and it earns the cleanest identity in the subject:
The inverse is free — just the transpose. (And if the columns are orthonormal, so are the rows: for square matrices a left inverse is automatically the right inverse — if then .) The payoff is behavioral: these transformations cannot distort measurement. Lengths survive: . Angles survive by the same cancellation inside . They are geometry's rigid motions — rotations and reflections, like the rotation matrix — and everything else (shears, stretches) is a liar that bends the ruler as it moves things.
Why does an orthonormal preserve every length?
The shadow machine — projection
A streetlamp shines straight down onto a road that runs along direction . You hold a stick at an angle. The stick's shadow on the road is the part of that lies along ; the rest of the stick sticks straight up, perpendicular to the road. That split — "the part along, plus the part across" — is projection, and it's the single move Gram–Schmidt repeats to build perfect coordinate systems.
The formula falls out of one demand: the leftover must be orthogonal to . Write the shadow as and require ; linearity gives , so
(You met already — it's the "smartest choice" from the Cauchy–Schwarz proof. Same coefficient, same geometry.)
Gram–Schmidt — cleaning a messy basis
Unit 2 taught you to find a basis. This unit's finale upgrades it to the best kind: an orthonormal basis with for and — every direction perpendicular, every direction unit length. (Only orthogonal, not unit length? That's an orthogonal basis — one normalization away.) Why chase it? Because in an orthonormal basis, coordinates stop requiring equation-solving: the address of any is just — read off by inner product. The canonical basis of is one example; rotate it and you get infinitely many others.
The cleaning algorithm is the shadow machine on repeat: take your messy basis in order; normalize the first vector; from each later vector, subtract its shadows on everything already cleaned, then normalize what's left. Step through the companion's example in 3D:
The slides' power tool: Gram–Schmidt by Gaussian elimination (and why it works)
The course adds a beautiful industrial route. Stack the messy basis as columns of , then run plain Gaussian elimination on the augmented matrix — when the left half reaches echelon form, the rows on the right are an orthogonal basis. The slides' example: , give , and elimination lands on
Check the right-hand rows: — orthogonal (the first is rescaled; the second is what's left of after removing its -shadow). Normalize and you have an orthonormal basis. Why it works, in three moves: ① full column rank makes positive-definite (, so the blind spots match and are trivial) — elimination needs no row swaps; ② elimination is multiplication by elementary matrices, i.e. with lower-triangular (Unit 1's recorded elimination!), and the right half becomes ; ③ then is upper-triangular and symmetric — hence diagonal — which is precisely the statement that 's columns are orthogonal. Elimination doesn't just solve systems; run on , it quietly performs Gram–Schmidt.
In Gram–Schmidt, why does subtracting the shadow from do the job?
The whole story, in five lines
① A norm is any length that scales, obeys the triangle inequality, and vanishes only at — the taxi's ℓ₁ and the crow's ℓ₂ both qualify. ② An inner product is the dot product's blueprint made general — bilinear, symmetric, positive-definite — and every SPD matrix builds one: . ③ Each inner product induces a norm, a distance, and — thanks to Cauchy–Schwarz — an angle: , ML's similarity dial. ④ Orthogonality is relative to the ruler, orthonormal matrices are the motions that preserve every measurement, and random high-dimensional vectors are nearly orthogonal by default. ⑤ Gram–Schmidt (shadow-subtraction, or elimination on ) turns any basis into an orthonormal one — the cleanest grid a geometry can have.
Geometry is a choice. The inner product is the lens: pick the matrix, and you have picked what "long," "near," and "perpendicular" mean. Machine learning's obsession with similarity is exactly the craft of choosing that lens well — and Gram–Schmidt guarantees that whatever lens you choose, a perfect coordinate grid exists for it.