Singular Value Decomposition and Vector Calculus
Prerequisite Knowledge
This lecture builds on the following concepts from earlier lectures. If any feel unfamiliar, review the linked notes before proceeding.
Previously Covered in This Subject
- Singular Value Decomposition (SVD) — introduced in Lecture 7 (section 7.7), which this lecture develops fully with a numerical worked example.
- Eigen Decomposition / Diagonalization — covered in Lecture 6 (section 6.3) and Lecture 7 (section 7.6); SVD generalizes it to rectangular matrices.
- Eigenvalues & Eigenvectors — Lecture 6 (section 6.3); needed because right singular vectors are eigenvectors of .
- Determinants & Characteristic Equation — Lecture 6/7; used to find eigenvalues via .
- Rank, Null Space & Rank-Nullity Theorem — Lecture 7 (sections 7.3); the cap reappears here.
- Matrix Decompositions (Cholesky, Eigen) — Lecture 7 (sections 7.4–7.6); SVD is the third major decomposition in that sequence.
Singular Value Decomposition and Vector Calculus
8.1 Singular Value Decomposition — The Rectangular Reality
8.1.1 Definition and Motivation
Hook. Eigen decomposition diagonalizes a matrix — but only if the matrix is square. What happens when your data has 10,000 users and 20 features? You need a tool that works on rectangles. That tool exists. It is the singular value decomposition.
Intuition. Think of a passport photo. It is a rectangle — taller than it is wide. If you try to force it through a square-cutter (eigen decomposition), it breaks. SVD is the rectangle-cutter. It slices any matrix into three clean pieces, no matter the shape.
The pieces are always the same kind: two rotation-like matrices and one scaling matrix. One rotation lines things up, the scaling stretches or squishes, and the second rotation puts everything back into the original coordinate frame.
A singular value decomposition (SVD) breaks any matrix — square or not — into three constrained matrices. You met eigen decomposition already. It has one hard limit. It only works on square matrices, where rows equal columns.
Real data is almost never square. A Netflix-style dataset has millions of users (rows) but only a few features per user (columns). A phone photo is a 1920 × 1080 grid of pixels — a non-square matrix. Tweet collections hold millions of messages but only a few hundred feature columns. In all these cases, eigen decomposition cannot apply. You need a tool that works on rectangles.
That tool is SVD. It is the natural sequel to eigen decomposition. It is the most important answer to one question: how do you decompose a non-square matrix?
8.1.2 Why Eigen Decomposition Falls Short
Eigen decomposition assumes the matrix is square: . Number of rows of must equal the number of columns. That is the hard assumption.
Most working data breaks this rule. Structured-data problems tend to be long. They have many more rows than columns. Example — predicting who subscribes next month. The user roster runs to millions. The feature set (age, gender, genre preferences) is a few dozen. The matrix is tall, not square. So eigen decomposition dies there. SVD does not.
8.1.3 Long Format vs Wide Format Data
SVD handles both long and wide non-square matrices. The computation strategy depends on which dimension is smaller.
- Long format — number of rows is much greater than number of columns. This is the common case for tables of users, transactions, documents.
- Wide format — number of columns is greater than number of rows. Rare, but it occurs.
For a long-format matrix (rows ≫ cols), start the SVD computation from the smaller side, . For a wide-format matrix (cols ≫ rows), start from . Always pick the smaller square to keep the algebra short.
8.1.4 Symbol Registry
- — the data matrix being decomposed, with rows and columns. This is the standard notation: is always rows, is always columns.
- — matrix of left singular vectors, square and orthogonal.
- — rectangular diagonal matrix of singular values, same shape as .
- — matrix of right singular vectors (transposed), square and orthogonal.
- — the -th singular value — scalar , ordered .
- — eigenvalue of (or ) — scalar.
The notation is standard across textbooks (Strang, Aggarwal): is , is , is , and is .
8.1.5 Assumptions and Scope
Scope. SVD applies to any real-valued matrix — no square requirement, no full-rank requirement, no symmetry requirement. The decomposition always exists.
Assumptions. Singular values are always non-negative (). This holds because they come from the eigenvalues of , which is positive semidefinite. If your matrix has negative eigenvalues in , something is wrong with the computation, not with SVD itself.
When it breaks. SVD breaks only at the computational level. If is ill-conditioned, the numerical computation can become unstable. But mathematically, the decomposition always exists.
8.1.6 Visual Intuition
Picture a rectangular sheet of grid paper. The grid lines are the original coordinate axes. Now apply the matrix to every point on that sheet. The grid warps — lines bend, stretch, or rotate.
SVD says this warping always breaks into three clean stages. First, rotate the sheet so the main stretch directions line up with the axes (). Then stretch or squish along those axes (). Finally, rotate the warped sheet one more time into its final orientation (). Every matrix, no matter how messy, decomposes into rotate → scale → rotate. The singular values are exactly how much each axis stretches or shrinks.
8.1.7 Pitfalls
- Assuming eigen decomposition works everywhere. When you see a non-square matrix, eigen decomposition is off the table. Many students try it anyway — it does not work.
- Confusing the dimension convention. The notation is universal. Some sources swap and . Always check which convention a problem uses by looking at the matrix dimensions first. In this course, means rows, columns.
- Thinking SVD is only for compression. SVD is foundational to linear algebra itself. Compression is one application. It also reveals the four fundamental subspaces, solves least-squares problems, and computes matrix pseudoinverses.
8.1.8 Recap and Bridge
SVD decomposes any matrix — rectangular or square — into . Eigen decomposition fails on non-square matrices; SVD steps in. Next, you will learn what rank means and why it limits how many singular values can be non-zero.
8.1.9 Real-World and Domain Connection
SVD underpins dimensionality reduction everywhere in data science. When Netflix recommends movies, it does not store every user's every rating. It decomposes the giant user × movie matrix via SVD and keeps only the top singular values. That captures taste patterns without storing billions of entries. The same idea powers image compression and latent semantic analysis in NLP. It also powers modern PEFT methods like LoRA, which fine-tune large language models by decomposing weight matrices.
8.1.10 Student Questions and Answers
Q: Is reducing dimensions the same idea as multicollinearity?
A: Yes — highly related. Multicollinearity means features are near-linear combinations of each other. SVD exploits exactly that redundancy to shrink dimensions. When people say "low rank approximation," "decomposition," or "rank approximation," SVD is a first candidate.
8.2 Rank and Maximum Possible Rank
8.2.1 Definition
Hook. You have 1000 rows of data but only 2 columns. How many truly independent directions can you possibly have? Not 1000 — at most 2. That is the hard ceiling that rank enforces.
Intuition. Think of a bookshelf with 50 books (rows) but only 2 unique authors (columns). Even though you have 50 rows, the "content" boils down to 2 distinct styles. The rank is 2. No matter how many books you add, if they are all by the same two authors, the rank stays 2.
The analogy breaks when you have genuinely independent data. If each book had a unique author, the rank could go up. But here, columns are the limiting factor — just like in a data matrix.
The rank of a matrix is how many linearly independent rows or columns it has. The maximum possible rank is the smaller of the row count and the column count. Formally:
A 1000 × 2 matrix has maximum possible rank 2. Even with 1000 rows, only two columns exist. So you can have at most two independent directions.
8.2.2 Worked Intuition — Age vs Experience
Take a 1000-row dataset with two columns: age and years of experience.
Maximum possible rank: .
But age and experience often move together. Say experience age 22 from people starting work around 22. Then:
This is a linear relationship — the second column is (roughly) the first column shifted by a constant. The two columns are linearly dependent, so the true rank drops to .
Sense check: Plot age on the x-axis, experience on the y-axis. The points hug a single line. The two features tell almost the same story. You can represent the same information with one column instead of two — reducing storage by half without losing signal.
8.2.3 When Correlation Reduces Rank
Experience may be a scaled version of age. Say experience age, or experience age 22 from people starting work around 22. The two columns are then linearly related. The matrix rank falls from a possible 2 down to 1.
Now scale the idea up. With hundreds of columns, many overlap this way. Rank drops, and that is the door SVD walks through to compress data.
8.2.4 Assumptions and Scope
Scope. The rank bound holds for every real matrix. It is a theoretical ceiling, not an empirical estimate.
What reduces actual rank. Linear dependence among rows or columns drives the actual rank below the maximum. One example is age nearly equaling experience minus a constant. Correlation does not guarantee reduced rank (nonlinear relationships do not count), but linear correlation does.
Full rank. If , the matrix is said to have full rank. In the 1000 × 2 case, full rank means 2 independent columns. That is the best you can do.
8.2.5 Visual Intuition
Draw two axes: age on the x-axis (from 20 to 60) and experience on the y-axis (from 0 to 40). Every person is a dot. If age and experience are independent, dots scatter across the full 2D plane — rank is 2. If experience always equals age minus 22, every dot lands exactly on the line . The dots collapse to a 1D line. The data still has 1000 dots, but the effective dimension — the rank — is 1. The second dimension carries no new information.
8.2.6 Pitfalls
- Confusing rank with row count. A 1000 × 2 matrix can have rank at most 2, not 1000. Rank counts independent directions, not data points.
- Thinking correlation always reduces rank. Only linear correlation drops rank. If age and experience have a perfect U-shaped relationship, the rank is still 2. Rank only cares about linear combinations.
- Forgetting that rank is about both rows and columns. Row rank always equals column rank. You cannot have 3 independent rows and only 2 independent columns in the same matrix.
8.2.7 Recap and Bridge
Rank is the number of independent directions in your data, capped at . Correlation drops rank — and that drop is exactly what SVD exploits for compression. Low rank approximation, next, is the art of safely throwing away the redundant directions.
8.2.8 Real-World and Domain Connection
Rank is the engine behind every recommender system. A movie-rating matrix with millions of users and thousands of films might have a true rank of 50. That means only 50 underlying "taste factors" explain all the ratings. SVD recovers those factors. Dimensionality reduction, feature selection, and compressed sensing all share one insight. Your data's rank is far smaller than its row count.
8.2.9 Student Questions and Answers
Q: Can experience be age minus a fixed quantity — like people starting work at 20 or 22?
A: Yes. That is a linear relationship too. When two features are linear combinations of each other (scaled, shifted, or combined), they reduce to one independent direction. The rank drops accordingly.
8.3 Low Rank Approximation
8.3.1 Intuition
Hook. You can throw away half your data and lose almost nothing. How? Because that half is redundant. Low rank approximation finds the redundancy and cuts it out.
Intuition. Think of a compressed JPEG photo. A 12-megapixel image boils down to a few hundred numbers that capture edges, colors, and textures. The rest is detail you cannot notice. A low rank approximation does the same thing for any matrix. Keep the big structural pieces, discard the noise, and the result looks nearly identical.
The mapping: the "big pieces" are the directions with large singular values. The "noise" is the directions with tiny singular values. You keep the former, zero out the latter, and the reconstructed matrix barely changes.
A low rank approximation takes a huge matrix and approximates it with a matrix of much lower rank. You drop redundant rows and columns and keep the essential structure. The data shrinks, but the signal survives.
The age/experience example made this concrete. Two columns collapsed to one because they were near-copies. SVD is one of the most important low-rank approximation methods. Wherever you see "decomposition," "rank approximation," or "approximation," SVD is a candidate.
8.3.2 Reducing Rows Loses Nothing When They Overlap
A natural worry: if you cut rows, do you lose data points? Only the redundant ones. If two users have identical age and salary rows, their plotted points sit on top of each other. The second row teaches the model nothing new. Removing it keeps every bit of information.
So low rank approximation trims redundant rows and redundant columns. It can also cut non-redundant rows. A small singular value proves a direction carries little information. That is the deeper point the worked example will show.
8.3.3 Formalizing: The SVD Connection
SVD gives the exact machinery for low rank approximation. After decomposing , the rank- approximation () is:
You keep the first terms in the sum — the ones with the largest singular values — and drop the rest. The Eckart-Young theorem guarantees this is the best rank- approximation in the Frobenius norm: no other rank- matrix is closer to .
8.3.4 Assumptions and Scope
Scope. Low rank approximation works best when the singular values decay rapidly — a few large ones, then a sharp drop. If all singular values are comparable, no rank- approximation with will be good.
When it fails. If the data genuinely spans independent directions of equal importance, you cannot truncate without losing signal. The singular value spectrum (the list of in descending order) tells you how much you can safely cut.
8.3.5 Visual Intuition
Plot the singular values of a typical data matrix as a bar chart. Put through on the x-axis, magnitude on the y-axis. A "good" spectrum looks like a ski slope: high at , steep drop, then a long flat tail near zero. The tail is where you truncate. A "bad" spectrum looks like a gentle ramp — every bar is roughly the same height. Truncation there discards real signal. The shape of this bar chart is your decision tool.
8.3.6 Pitfalls
- Blindly truncating to a fixed . The right depends on the singular value spectrum, not a magic number. One dataset may need , another .
- Thinking "low rank = always safe." Low rank approximation is lossy compression. It trades fidelity for size. Whether the trade is worth it depends on how fast the singular values decay.
- Confusing removal of rows with removal of data. When rows are redundant, removing them loses nothing. When rows carry independent signal, removing them loses information. The singular value tells you which case you are in.
8.3.7 Recap and Bridge
Low rank approximation keeps the big singular values and drops the small ones. It is the core of compression, noise removal, and parameter-efficient ML. SVD gives you the tools to decide exactly how much rank to keep.
8.3.8 Real-World: LoRA and Parameter-Efficient Fine-Tuning
Low rank approximation is not just for compressing old data. It now powers the latest large language models. LoRA (Low-Rank Adaptation) freezes a pre-trained model's giant weight matrices and inserts small, trainable low-rank matrices alongside them. These tiny add-ons capture the new task (e.g., medical Q&A) without touching the billions of original parameters. The result: fine-tuning that costs a fraction of the compute while matching full fine-tuning accuracy. Every article on "parameter-efficient fine-tuning" or "PEFT" rides on one idea. A weight update can be re-expressed as a low-rank product — pure SVD thinking applied to modern AI infrastructure.
8.3.9 Student Questions and Answers
Q: Does reducing dimensions mean we lose data without hurting model accuracy?
A: Yes — when the dropped dimensions are redundant. You remove rows that teach the model nothing new. The model's accuracy does not degrade. You are just cutting extra compute effort. The same information stays; the model runs faster and uses less memory. But this only holds when the dropped singular values are genuinely small. If they are comparable to the kept ones, accuracy will drop.
8.4 SVD Formal Definition and Dimensions
8.4.1 The Decomposition
Hook. Every matrix — square, rectangular, tall, wide, full-rank, or rank-deficient — can be written as exactly three matrices multiplied together. One for rotation, one for scaling, one for rotation. Always.
Intuition. Take a lump of clay. You want to reshape it into a specific form. Any reshaping can be broken into steps. First, rotate the clay block so its main axes align with your hands (). Then stretch or squish along those axes to the right proportions (). Finally, rotate the result one more time to face the right direction (). SVD says every linear transformation — no matter how complicated — is exactly rotate → scale → rotate. The singular values are how hard each axis gets pulled.
Any rectangular matrix factors into three constrained matrices:
- — matrix of left singular vectors, square and orthogonal ().
- — rectangular diagonal matrix of singular values, same shape as . Only entries with can be non-zero. All singular values , ordered .
- — matrix of right singular vectors (transposed), square and orthogonal ().
The notation is standard across textbooks (Strang, Aggarwal): always denotes rows, always denotes columns. The dimensions then follow mechanically: is , is , and is .
Singular vectors generalize eigenvectors to rectangular matrices. The right singular vectors (columns of ) are the eigenvectors of . The left singular vectors (columns of ) are the eigenvectors of . The singular values are the square roots of the eigenvalues shared by both.
8.4.2 Geometric Roles of the Three Matrices
A matrix can scale, shear, or rotate its input space. SVD cleanly separates those effects:
- — a rotation (or reflection) that aligns the input with the principal axes of .
- — a scaling (stretch or squish) along those axes by the singular values.
- — a rotation (or reflection) back into the output orientation.
This is the polar decomposition perspective: every matrix is an orthogonal transformation times a positive semidefinite scaling. SVD makes this explicit.
8.4.3 Worked Dimension Walk — A 1000 × 2 Matrix
Take 1000 people, each with age and experience (2 columns). So is 1000 × 2.
- is 1000 × 1000 — left singular vectors. Only the first 2 columns matter (they pair with non-zero singular values). The remaining 998 columns span the nullspace of .
- is 1000 × 2 — singular values. Only the first 2 entries can be non-zero. The rest are padding zeros.
- is 2 × 2 — right singular vectors. All 4 entries can be non-zero.
The dimension you cannot ignore: has the same shape as . Even though has 1000 rows, only the first singular values can be non-zero.
8.4.4 Assumptions and Scope
Scope. SVD exists for every real matrix — no exceptions. The proof relies on the fact that is always symmetric positive semidefinite, so it always has real, non-negative eigenvalues and orthonormal eigenvectors.
Complex case. SVD extends to complex matrices too, with conjugate transposes replacing regular transposes.
Uniqueness. Singular values are unique. Singular vectors are unique up to sign flips (multiplying a pair by simultaneously leaves the product unchanged).
8.4.5 Visual Intuition
Draw a unit circle in 2D. Applying a 2×2 matrix deforms it into an ellipse. The singular values are the lengths of the semi-axes of that ellipse. The right singular vectors (columns of ) are the directions of the original circle's radii that become the ellipse's axes. The left singular vectors (columns of ) are the directions those axes point to after transformation. The SVD is the geometric statement. Every linear map takes a circle to an ellipse, and the singular values describe that ellipse's shape.
8.4.6 Pitfalls
- Swapping and . comes from and has columns. comes from and has columns. Their sizes differ when . You cannot swap them.
- Forgetting is rectangular. When , is not square. It has the exact shape of . Filling a square diagonal matrix with singular values and extra zeros is wrong — only the leading diagonal entries carry values.
- Thinking singular vectors are eigenvectors of . They are eigenvectors of and , not of itself (unless is symmetric positive semidefinite).
8.4.7 Recap and Bridge
is the universal decomposition. and rotate, scales. Every matrix, every time. The geometric story — circle to ellipse — carries through to the next section, where you see the three steps in sequence.
8.4.8 Real-World and Domain Connection
The SVD's geometric interpretation — rotate, scale, rotate — is the foundation for 3D computer graphics and game engines. When a GPU renders a character, every vertex gets transformed by a series of matrix multiplications. SVD decomposes any such transform into its purest elements: orientation, stretch, orientation. Game physics engines also use SVD to compute the polar decomposition. This separates a deformation into pure rotation and pure stretch. It lets them simulate soft-body collisions realistically.
8.4.9 Symbol Registry
- — the matrix being decomposed — tall or wide.
- — left singular vectors — square, orthogonal.
- — singular values — rectangular, diagonal, same shape as .
- — right singular vectors (transposed) — square, orthogonal.
- — row count and column count of — positive integers.
8.5 Geometric Intuition — Rotation, Scaling, Rotation
8.5.1 Align to the Direction of Most Variance
Hook. Your data has a shape — a direction where it spreads most. SVD rotates the whole dataset so that direction lines up with the x-axis. Now every axis carries independent information.
Intuition. Hold a pencil at a slant on a piece of paper. If you try to describe its position by how far it extends along the desk's edges, you need two numbers and a messy description. But if you first rotate the paper so the pencil lies flat along one edge, the description collapses to one simple number: its length. SVD finds the rotation that makes your data simplest to describe. The rotation is .
Picture age on the x-axis and experience on the y-axis after normalization. Both axes share a scale of roughly to . The data spreads most along a diagonal. That is the axis of maximum variance, also called maximum explainability.
The first step, , rotates the entire grid so the data's main spread lines up with the coordinate axes. You do not know in advance how much to rotate or where to stop. You find the rotation that exposes the axes of greatest variance. The rotation comes from the eigenvectors of : each column of is an eigenvector of , ordered by descending eigenvalue. The first column of points along the direction of maximum variance, the second along the next most, and so on.
8.5.2 Scaling Is Stretching — and Squishing
The second step, , scales each aligned axis. Scaling can stretch or squish. When one direction carries little variance, the corresponding singular value is small, and squishes that axis toward zero. A 3D point cloud that really lives in a flat 2D pancake gets squished to a 2D plane. The "depth" axis shrinks away.
The singular values tell you exactly how much each direction matters. scales the direction of most variance, scales the next, and so on. If , that direction carries almost no information — and can be dropped entirely, which is how PCA works.
8.5.3 Rotate Back, Land on Principal Axes
The third step, , rotates the squished data back to a natural orientation. You started with a 3D spread. You rotated, scaled, dropped the thin direction, and rotated back. You land on a lower-dimensional representation that keeps the high-variance structure.
The columns of are the principal axes in the output space — the directions along which the transformed data varies. Together, and tell you the relationship between input and output orientations.
8.5.4 Assumptions and Scope
Scope. The rotation-scaling-rotation interpretation is exact when the singular values are non-negative and the vectors are orthonormal. This holds for all real matrices.
Reflections possible. "Rotation" can include reflections (determinant ). and are orthogonal, not necessarily proper rotations. SVD does not distinguish the two — it separates the transformation into orthogonal × diagonal × orthogonal regardless.
8.5.5 Pitfalls
- Thinking scaling means only stretching. Scaling includes compression. A singular value of 0.01 means "squish this axis to 1% of its size." The operation is still scaling — it just shrinks the axis instead of growing it.
- Confusing "maximum variance" with "important." High variance directions carry lots of signal for many tasks, but not all. In anomaly detection, the low variance directions — the ones SVD would drop — sometimes contain the interesting outliers.
- Forgetting that rotation angles come from eigenvectors. is not an arbitrary rotation. Its columns are the eigenvectors of . You compute them, not guess them.
8.5.6 Recap and Bridge
SVD's three steps — rotate to align with variance (), scale (), rotate to output () — are the geometric story behind every linear transformation. This story makes the SVD computation concrete in the next section.
8.5.7 Real-World and Domain Connection
The rotation-scaling-rotation decomposition is the mathematical engine behind Principal Component Analysis (PCA). When you run PCA(n_components=2) on a high-dimensional dataset, the algorithm computes the SVD of the centered data matrix. The first two right singular vectors (columns of ) give you the directions of maximum variance — exactly the principal components. Every dimensionality reduction pipeline built on PCA is, under the hood, running SVD and keeping the top singular vectors. This includes everything from gene expression analysis to customer segmentation.
8.5.8 Student Questions and Answers
Q: Is the second step scaling or shrinking?
A: It is scaling. The data shrinks as a side effect — axes with little information get squished. But the operation itself is scaling, which includes compressing some axes. The term "scaling" covers both stretching () and squishing ().
Q: Variance gives explainability of the data. SVD aligns data where variance is most — does that mean better explainability?
A: Yes. Where there is more variance, there is more explainability. Explainability here means how much of the data's total spread each direction captures. SVD rotates the data toward the direction of most change. The result carries more signal per retained dimension.
Q: Why is the initial rotation needed?
A: To align the data to the axis of maximum variance before scaling. You cannot usefully scale axes that do not line up with where the data spreads. If you scale first without rotating, the scaling affects the original features arbitrarily rather than the directions that actually matter.
8.6 Worked Example — SVD of a 3 × 2 Matrix
8.6.1 Setup and Strategy
Hook. Computing an SVD by hand sounds intimidating. But the process is actually a recipe: build the small square, eigen-decompose it, then recover the other half with a one-line identity.
Intuition. You have a rectangular door (3 feet by 2 feet) and need to measure its diagonal. Rather than measuring across the rectangle directly, you measure the smaller 2×2 square corner. Then use the Pythagorean theorem to get the rest. SVD works the same way. Decompose the smaller of (2×2) or (3×3). Then derive the other from the identity .
Given:
The two columns, and , are not multiples of each other. So the columns are linearly independent. The first and third rows do relate — is the reverse of — but columns stay independent. This cannot be eigen decomposed (it is not square). You must SVD it.
Strategy: build a square matrix from , eigen decompose that, and recover the SVD factors. The two square options are (2 × 2) and (3 × 3). Always start from the smaller one.
Exam note: For a long-format matrix (rows ≫ cols), compute first — it is the smaller square. For wide-format, compute first. You can derive the larger from the smaller afterward.
8.6.2 Compute (the Smaller Square)
So:
This matrix is symmetric. Eigenvectors of a symmetric matrix are orthogonal. You will use that shortly.
8.6.3 Eigenvalues of
Solve :
Expand:
Factor:
These are the two eigenvalues of . Both are non-negative, as expected for a symmetric positive definite matrix. The singular values will come from these.
8.6.4 Eigenvectors of — the Matrix
For , solve :
Both rows reduce to , so . Pick ; the eigenvector is .
Normalize: length . Unit eigenvector:
For :
Both rows give . Pick ; the eigenvector is . Normalize:
The right singular vectors form . Largest singular value first:
Check orthogonality: . The matrix is orthogonal.
8.6.5 The Singular Value Matrix
The singular values are the square roots of the eigenvalues of :
Since is positive semidefinite, all eigenvalues are , so all singular values are real and non-negative. For this problem:
The third singular value is 0 because has rank 2 and only singular values can be non-zero. holds only 2 non-zero diagonal entries. Place them in descending order:
8.6.6 Computing — the Identity
You could build (3 × 3), find its three eigenvalues and three eigenvectors, and assemble from them. That is long and error prone. There is a shortcut.
Start from and multiply both sides by . Since :
Column by column, for the -th column:
First column :
Divide by :
Verify: . All three forms are equivalent.
Second column :
Since :
Third column :
The shortcut fails when (division by zero). But is orthogonal, so its columns are mutually perpendicular. Find as the vector perpendicular to and using the cross product:
Compute:
Check the norm: . It is already a unit vector.
Sign convention note. The source said "U3 = U2 × U1". Computing gives . Both are valid since singular vectors are unique only up to sign. The product is unchanged if you flip the sign of both and together. In this course, use for consistency with the right-hand rule.
The full SVD of is:
Sense check: Multiply the three matrices. rotates, scales and pads, rotates back. The product recovers exactly — and indeed . The rank is 2, matching the two non-zero singular values and .
8.6.7 Symbol Registry
- — right singular vectors (eigenvectors of ) — , unit length.
- — left singular vectors (eigenvectors of ) — , unit length, mutually orthogonal.
- — singular values — scalars, ordered descending.
- — eigenvalues of — scalars.
- — identity matrix (here 2 × 2) — .
8.6.8 Assumptions and Scope
Scope. This worked example shows the standard SVD path for a tall matrix ( ). Compute , find its eigenvalues and eigenvectors, and set . Then recover from . The cross-product trick for the zero-singular-value column works in . It does not generalize to higher dimensions. There you need Gram-Schmidt or the full eigendecomposition of .
When eigenvalues are negative. is always positive semidefinite, so eigenvalues are always theoretically. Numerical errors can produce tiny negative values. Treat them as zero.
8.6.9 Visual Intuition
The matrix maps into . Draw the unit circle in the input plane. sends that circle to an ellipse lying in a 2D subspace of . The semi-major axis of that ellipse has length and points along . The semi-minor axis has length 1 and points along . The ellipse is perfectly flat — the third direction gets zero stretch. That is why A has rank 2: the output lives on a 2D plane inside 3D space.
8.6.10 Pitfalls
- Starting from the larger square. Computing (3 × 3) first wastes time. Always pick — compute the smaller of and .
- Forgetting to normalize eigenvectors. Unnormalized eigenvectors produce unnormalized singular vectors. The decomposition still works algebraically, but the orthogonality property () fails, which breaks downstream uses.
- Dividing by zero for . When a singular value is zero, fails. Use orthogonality (cross product, Gram-Schmidt) to find the missing column instead.
- Using the wrong cross product order. and differ by a sign. Either is fine as long as you are consistent. The exam will accept either direction.
8.6.11 Recap and Bridge
The SVD recipe for a tall matrix: compute , then find and . Set , and recover . Fill zero-singular-value columns via cross product. This same recipe generalizes to any rectangular matrix.
8.6.12 Student Questions and Answers
Q: Can you explain how to calculate again from scratch?
A: Take the eigenvalues of (3 and 1). Take the square root of each ( and 1). Arrange them along the diagonal of a matrix the same shape as (3 × 2), descending. Fill remaining slots with zeros.
Q: What if eigenvalues come out negative?
A: The square root would be imaginary. But is positive semidefinite, so eigenvalues are always . If you get a negative eigenvalue, it is a rounding error — treat it as 0.
Q: What if there is only one eigenvalue?
A: Then is 1 × 1 and has only one column. is 1 × 1, gets one non-zero entry, and the remaining singular value slots are zero. SVD still works.
Q: How do you compute ?
A: The formula breaks when . Since must be orthogonal, its columns are mutually perpendicular. Compute (the cross product) and normalize if needed.
Q: Why are we doing ?
A: From the identity , each column . But division by is undefined. The columns of are perpendicular by definition of SVD, so the cross product of the first two gives the third direction directly.
Q: Why normalize eigenvectors? Can we leave them unnormalized?
A: You can, but the solution is not unique — your is someone else's . Only unit vectors in an eigenvector's direction give a canonical decomposition. Normalize to get and orthogonal, which is required for the SVD to satisfy and .
8.6.13 Exam Notes
Exam note: A numerical SVD problem is highly likely on the mid-semester exam. Practice the full walkthrough. Compute , find eigenvalues and eigenvectors, and build . Recover via , and use the cross product for zero-singular-value columns. Always start from the smaller square.
8.7 Low Rank Approximation by Truncating Singular Values
8.7.1 The Truncated Sum
Hook. A 3 × 2 matrix takes 6 numbers to store. Its rank-1 approximation takes only 5 numbers — and in many datasets, it captures 90% of the information. That is the power of truncation.
Intuition. Imagine you are packing for a trip. Your suitcase (the original matrix) is overstuffed. You decide to only bring the three heaviest items — they account for most of the weight anyway. Truncating singular values is the same idea. Keep the terms with the biggest (heavy items) and drop the rest. The bag is lighter and still has everything that matters.
Any matrix factorized by SVD can be rewritten as a sum of rank-1 pieces:
where is the rank of (the number of non-zero singular values). Each term is a rank-1 matrix. Every row is a scalar multiple of , and every column is a scalar multiple of . A rank- approximation keeps the first terms and discards the rest.
8.7.2 Worked Example — Rank-1 Approximation
Keep only the first (largest) singular value. Drop everything else:
Computing the outer product entry by entry. For row 1, column 1:
Row 1, column 2: same computation, gives .
Row 2, column 1:
Row 2, column 2: same, gives .
Row 3, column 1 and 2: identical to row 1 — both are .
The full rank-1 approximation is:
Compare with the original:
The rank-1 approximation captures the dominant pattern: the middle row is twice the outer rows, and both columns have similar values. But it misses the asymmetry. The original has zeros in opposite corners (top-right and bottom-left), which the rank-1 approximation smears into uniform halves. That information lives in the dropped term.
Sense check: adding back should recover the original exactly. Compute :
Add to :
The reconstruction is exact — exactly as the sum formula guarantees.
8.7.3 When Truncation Is Safe
When the first singular value dominates, the second term barely changes the matrix. Say sits in the hundreds while lands in tenths. Dropping the second term loses almost no information. The classic case: two columns are near-exact copies (extreme multicollinearity). Then is huge and is near 0, so a rank-1 cut keeps nearly all the data.
When and are comparable, dropping hurts. Here versus — similar magnitude — so accuracy suffers visibly. The rank-1 approximation here is a poor one, as the worked example shows.
The singular value spectrum — the list of in descending order — tells you how much information each term carries. If , truncation is safe. If all are similar, truncation is destructive.
8.7.4 Assumptions and Scope
Scope. Low rank approximation via SVD truncation is exact when keeping all terms. It is optimal in the Frobenius norm for any fixed (Eckart-Young theorem). This means no other rank- matrix gets closer to .
When it fails. If singular values decay slowly, truncation is poor. If the data has no redundancy (each column is independent), rank reduction loses real signal, not just noise.
8.7.5 Visual Intuition
Picture the original matrix as a 2D grid of colored squares — 3 rows, 2 columns. The rank-1 approximation replaces that grid with one where row 1 and row 3 are identical light gray, and row 2 is a darker gray. The pattern is simpler but the original's distinctive zero entries are gone. Now add the rank-2 term back — the zeros pop into place. Each singular value adds one more layer of detail, like a printer adding one more color pass to a photo.
8.7.6 Pitfalls
- Treating truncation as always safe. Only safe when the dropped singular values are negligible. Blindly truncating a matrix with a flat spectrum ruins the data.
- Forgetting that rank-k approximation IS a matrix of rank k. Each term adds one more rank. Keep k terms, get exactly rank k. The rank of the approximation equals the number of singular values you keep.
- Confusing the rank-1 term with the whole SVD. The sum of ALL r terms reconstructs A exactly. Truncation is optional — you only drop terms when you want compression or denoising.
8.7.7 Recap and Bridge
Truncating singular values gives the best rank- approximation of any matrix. The sum of rank-1 pieces reconstructs the original exactly when you keep all terms. Remove terms from the tail — the ones with the smallest — and you compress without losing the dominant structure.
8.7.8 Real-World: Image Compression
The SVD truncation is the engine behind image compression. A 1920 × 1080 grayscale photo is a 1920 × 1080 matrix. Its SVD ranks the singular values — typically a steep drop after the first few hundred. Keep the top ~30% of singular values and the image looks nearly identical. The storage drops dramatically, from 1920×1080 numbers to numbers. WhatsApp and similar apps use this to send photos that are kilobytes instead of megabytes, with no visible quality loss.
8.7.9 Student Questions and Answers
Q: Here and — comparable, not 1000 vs 2. So dropping is risky here, right?
A: Yes — for this example truncating would noticeably hurt, because and are not far apart. The truncation intuition is strongest when features are highly correlated. Then dominates hugely and is tiny, so the second term is nearly noise. That is the case you meet in principal component analysis.
Q: Reducing dimensions doesn't affect accuracy — that holds always?
A: Only when the dropped directions carry redundant or low-variance information. If the dropped singular value is comparable to the kept ones, accuracy degrades. The approximation trades accuracy for size. The singular value spectrum tells you how much you can safely trade.
8.8 Derivatives of Univariate Functions
8.8.1 Setup — A Single Variable Predicts Another
Hook. You know your salary at age 30 and at age 50. But what matters most is what happens between those ages — at exactly 32, does your salary jump or crawl? The derivative answers that.
Intuition. A speedometer shows your speed right now — not your average speed over the trip. A car that averages 50 km/h may have been doing 120 km/h when the camera flashed. The derivative is the speedometer of mathematics. It tells you the rate of change at one exact instant, not over a stretch.
The professor's own analogy: "You started your bike from A, reached B. Your average speed was 50 km/h. How can I get the challan? The traffic police did not care about your average speed. They only cared about your instantaneous speed when crossing that point."
A univariate function has one input. Think salary as a function of age: , with as age and as salary. Fit a curve through the data. At any point , you can ask two things. What is the salary there? And how fast does salary change as age nudges around 32?
The answer to "how fast" is the derivative. It is the rate of change of one variable with respect to another, measured exactly at a point.
8.8.2 The Formal Limit Definition
For , nudge by a tiny amount . The function changes by . Divide by to get the average rate over that nudge. Then shrink to zero for the instantaneous rate:
That quotient is the derivative. The numerator is the change in the function. The denominator is the change in the input. The limit takes the change over an infinitely small nudge. It collapses the average rate into the instantaneous rate. The notation is read "the derivative of y with respect to x."
8.8.3 Worked Example — at
Apply the limit definition:
At , the derivative of is 6. That means a tiny nudge upward in (say from 3 to 3.001) increases by about . And indeed: . The derivative gave the right rate.
Sense check: The slope gets steeper as grows — is a parabola, and at the tangent slope should be 6. The power rule () confirms .
8.8.4 Visual Intuition — The Tangent Line
Picture a hiker climbing a mountain whose height is and whose horizontal position is . The curve traces the mountain's profile. The derivative at any point is the slope of the tangent line to the curve right there.
- A steep uphill tangent means is large and positive — height increases fast as grows.
- A flat tangent means — the top (or bottom) of a hill.
- A downhill tangent means is negative.
So is the slope of the curve at a single point. Slide along and watch the tangent line sweep along the curve — that moving slope is the derivative function.
8.8.5 Assumptions and Scope
Scope. The derivative exists at only if the limit exists — meaning the left-hand and right-hand limits agree. A sharp corner (like at ) has no derivative.
Differentiability. If a function is differentiable at a point, it is also continuous there. But continuity does not guarantee differentiability — is continuous at 0 but not differentiable.
8.8.6 Pitfalls
- Confusing average rate with instantaneous rate. The difference quotient without the limit gives average rate. You need for instantaneous rate.
- Thinking is a fraction. It is a single symbol — the limit of a fraction. You can manipulate it like a fraction in the chain rule, but it is not literally a number divided by another number.
- Forgetting the limit. Plugging in directly gives — meaningless. The limit is essential.
8.8.7 Recap and Bridge
The derivative is the instantaneous rate of change — the speedometer reading. It is defined as the limit of the difference quotient as . Next, the power rule gives a shortcut for computing derivatives of without the limit.
8.8.8 Symbol Registry
- — the input variable — scalar, real.
- — the output (function value) — scalar.
- — the small nudge in — scalar, tends to 0.
- — the derivative — instantaneous rate of change — scalar.
8.9 The Power Rule — Derivation
8.9.1 The Rule
Hook. Typing every time you need a derivative is exhausting. The power rule is a one-step shortcut for the most common function family in mathematics. No limits needed — just multiply and drop.
Intuition. Think of as a stack of blocks. The derivative asks: when grows, how fast does the total volume grow? Each of the blocks contributes independently, and each block's contribution scales like . So the derivative is — exactly copies of the smaller block.
The heuristic: "bring the exponent down as a multiplier, then reduce the exponent by one." In symbols: becomes .
For ,
That is the power rule. Multiply by the exponent, then drop the exponent by one.
8.9.2 Proof via the Binomial Theorem
Start with the limit definition on :
Expand by the binomial theorem:
The binomial coefficient:
Plug in for the first two coefficients:
Now substitute the expansion back into the limit:
The and cancel. Factor out of every remaining term:
Now take . Every surviving term has at least one factor of except the first:
That is the power rule, derived.
8.9.3 Worked Example —
Apply the power rule directly:
Check at . The derivative says . Using the limit definition for sanity: , so . The power rule gives the right answer.
For at , the power rule gives . A tiny nudge of produces a function change of about , which matches the direct calculation. The power rule works.
8.9.4 Assumptions and Scope
Scope. This derivation assumes is a positive integer. The power rule also holds for negative integers. It holds for fractions and real exponents too. But the proofs differ. The binomial theorem proof works only for positive integer .
When it fails. The function must actually be a pure power of . If , the derivative is still (constants vanish). But if , you need the chain rule, not the pure power rule.
8.9.5 Pitfalls
- Forgetting to drop the exponent. of is , not . The exponent decreases by exactly one.
- Applying the power rule to the wrong base. The power rule works when is the base and is constant. For (exponential), the rule is different — do not use the power rule.
- Mixing up power rule and chain rule. is not alone — you also need the derivative of the inside (). The pure power rule applies only to .
8.9.6 Recap and Bridge
The power rule — bring down the exponent, reduce by one — is the workhorse of differentiation. It was derived from the limit definition by expanding and letting . Next, the product rule handles the derivative of two functions multiplied together.
8.9.7 Symbol Registry
- — the input variable — scalar, real.
- — the function — scalar.
- — the exponent — scalar, a positive integer in this derivation.
- — the small nudge in — scalar, tends to 0.
- — binomial coefficient — scalar.
- — the derivative (instantaneous rate of change) — scalar.
8.10 Product Rule
8.10.1 The Rule
Hook. A single function is easy to differentiate. But what about ? Two functions tangled together. The product rule untangles them.
Intuition. Two roommates share an apartment. When the rent goes up, both feel it — but in different ways. The product of two functions is like that apartment. If changes, both and adjust. The total change is the sum of two pieces. First: ('s change) × ('s current value). Second: ('s change) × ('s current value). You decorate one at a time while the other stays put.
When you differentiate a product of two functions of , say , differentiate each factor in turn and combine:
Take the derivative of one factor, keep the other as is. Then swap the two. Add the results.
8.10.2 Worked Example —
Set and . Apply the product rule:
Compute each piece:
Substitute:
The derivative of is .
Sense check at : . The function is flat at the origin (it touches the x-axis). The derivative should vanish there — and it does.
8.10.3 Extension — Product Rule with Chain Rule
A function like follows the same pattern. Set , . The product rule gives:
But the derivative of itself needs the chain rule (next section). Reach for the product rule first, then the chain rule on the inner piece. Rules compose — apply them in the right order.
8.10.4 Assumptions and Scope
Scope. The product rule holds wherever both and are differentiable. It extends to three or more factors: .
Not limited to scalars. The product rule generalizes to inner products of vector-valued functions. It also covers matrix products and the cross product. You must take care with non-commutativity in the last two cases.
8.10.5 Pitfalls
- Adding instead of summing with the right pairing. The formula is , not and not . Each derivative pairs with the other function, not its own.
- Forgetting that factors can be composite. If , then requires the chain rule first. The product rule is only step one — decompose fully.
- Swapping the order unnecessarily. For scalar functions, . Order does not matter. But for matrix products, order matters — so always write in the exact order stated.
8.10.6 Recap and Bridge
The product rule — — handles derivatives of multiplied functions by treating one factor at a time. Next, the chain rule handles nested functions like .
8.10.7 Symbol Registry
- — a product of two functions of — scalar.
- — the two factor functions — scalar.
- , — their derivatives — scalars.
- — the derivative of the product — scalar.
8.11 Chain Rule
8.11.1 The Rule
Hook. How does changing affect a function buried two layers deep — like ? You cannot just use the power rule alone. You need to follow the chain of dependencies.
Intuition. You control a thermostat (). The thermostat sets the furnace temperature (). The furnace heats the room (). To know how much turning the dial warms the room, you first ask: "how much does a 1° furnace increase warm the room?" (). Then: "how much does turning the dial change the furnace?" (). Multiply these two effects to get the total: .
Each link in the chain is a simple derivative. The chain rule says: multiply the links.
A function can be built by composing two others. Let and . The derivative of with respect to is the product of the derivatives along the chain:
depends on , and depends on . To know how moves with , first measure how moves with . Then multiply by how moves with . You follow the dependency chain link by link.
8.11.2 Worked Example
Take a composite power:
Identify the layers. The inner function is . The outer function is .
Apply the chain rule:
Outer derivative (power rule on ):
Inner derivative (power rule + constant, on ):
Multiply and substitute back :
The derivative of is .
Sense check at : If , then . The derivative there is . The function is flat at the origin because factor vanishes — the input is a critical point. ✓
Sense check at : , . The derivative is . ✓
8.11.3 Extending — Three or More Layers
The chain rule extends to any depth. For , , :
Each link multiplies. Real neural networks chain hundreds of layers this way — that is backpropagation.
8.11.4 Assumptions and Scope
Scope. The chain rule applies wherever each inner function is differentiable. It holds for scalar, vector, and matrix inputs/outputs (generalizing to Jacobians in the multivariable case).
Notation danger. means "derivative of with respect to its immediate argument ," not with respect to . Always identify which variable goes in the denominator.
8.11.5 Pitfalls
- Forgetting to multiply by the inner derivative. differentiated as alone is wrong. The factor is mandatory.
- Applying the chain rule when the function is not composite. needs only the power rule. needs the chain rule. Know the difference.
- Stopping after one layer when there are more. has three layers: of of . Differentiate all three: .
8.11.6 Recap and Bridge
The chain rule — — lets you differentiate nested functions by peeling layers from the outside in. It is the foundation of backpropagation in neural networks. Next: partial derivatives extend differentiation to functions of multiple variables.
8.11.7 Real-World and Domain Connection
The chain rule powers every neural network on the planet. In a 100-layer deep network, the derivative of the loss with respect to the first layer's weights is a product of 99 local derivatives. That is exactly the chain rule applied 99 times. Backpropagation is the chain rule computed efficiently on a computation graph. The whole field of deep learning runs on this one rule.
8.11.8 Symbol Registry
- — outer function output — scalar.
- — inner function of — scalar.
- — derivative of outer w.r.t. — scalar.
- — derivative of inner w.r.t. — scalar.
- — the full chain-rule derivative w.r.t. — scalar.
8.12 Partial Derivatives
8.12.1 Definition
Hook. A function of two variables — like temperature depending on both latitude and longitude — changes differently along each axis. A single cannot capture both. You need partial derivatives.
Intuition. You are hiking in rolling hills. Your elevation depends on your east-west position and your north-south position . If you walk due east (fixing ), the slope under your feet is . If you walk due north (fixing ), the slope is . A partial derivative measures the slope along one direction while all other directions are frozen in place.
The analogy maps: hiking position → function , eastward slope → , northward slope → . The analogy breaks because in reality you can walk diagonal — but the partial derivative only measures cardinal directions. The gradient (next section) handles arbitrary directions.
When depends on two variables, , you cannot write . You ask instead: how does change when only one input moves, holding the other fixed?
Write that as a partial derivative:
The curly signals "differentiate with respect to one variable, treating every other variable as a constant." The computation is the same as ordinary differentiation. You just treat all other variables as fixed numbers.
8.12.2 Worked Example
Take .
Partial with respect to : hold constant. The derivative of any constant is 0, so the term vanishes. The power rule applies to :
Partial with respect to : hold constant. Now the term vanishes:
For :
- (treat as constant)
- (treat as constant)
At the point : , . Along , the function rises at rate 2 per unit. Along , it rises twice as fast at rate 4 per unit. The bowl is steeper in the direction at this point.
8.12.3 Visual Intuition
A function lives in three dimensions — two inputs plus the output. Fixing slices the surface with a vertical plane parallel to the – axes. The intersection is a single 2D curve. The partial derivative is the slope of that curve — the slope you would measure walking along the direction only.
The classic "Pringles chip" saddle-shaped surface shows this well. Along (fix ), the curve is a U-shape opening upward — (positive for positive ). Along (fix ), the curve is an upside-down U — (negative for positive ). Same point, two different slopes, because the surface tilts differently in each direction.
8.12.4 Assumptions and Scope
Scope. Partial derivatives exist at a point where the function is differentiable in each variable individually. They extend to any number of variables: for , there are partial derivatives .
Higher-order partials. You can take partial derivatives of partial derivatives — . For well-behaved functions (), the order does not matter: .
Notation warning. is a single symbol, not a fraction. You cannot "cancel" the 's.
8.12.5 Pitfalls
- Forgetting to hold other variables constant. Differentiating with respect to treats as a constant, so the derivative is — NOT . The chain/product rules only apply when the "constant" variable is actually constant.
- Writing partial where ordinary is needed. If depends on only one variable, write , not . Partial derivatives imply multiple inputs.
- Mixing up and . The curly is a convention. On exams, using the wrong symbol is technically a notation error even if the computation is right.
8.12.6 Recap and Bridge
Partial derivatives measure how a function changes along one input direction while all others are frozen. They are the building blocks of the gradient, which packages them into a single vector pointing toward steepest increase.
8.12.7 Symbol Registry
- — a function of two inputs — scalar.
- — the two input variables — scalars, real.
- , — partial derivatives — scalars.
- — the partial-derivative operator — holds other variables constant.
8.13 Gradients
8.13.1 Definition
Hook. Partial derivatives give you slopes along each axis. But which direction should you walk to climb the hill fastest? You need all the slopes packaged together into one arrow. That arrow is the gradient.
Intuition. Picture a blindfolded hiker on a mountain. She cannot see the peak. But she can feel the ground slope under her feet. If she takes one step east, she goes up 2 meters. If she steps north, she goes up 3 meters. The gradient is the arrow pointing (2 east, 3 north) — the combined direction of steepest uphill. If she wants to go uphill fastest, she follows that arrow. If she wants to go downhill fastest, she walks exactly opposite.
The professor used this analogy: the gradient is the green arrow on a loss landscape, pointing toward increasing height. To descend (which is what we want in ML), you step against the arrow.
The gradient stacks every partial derivative of a function into a single vector. For :
It is a vector — one entry per input. Each entry says how fast the function changes along that input's direction. The symbol is pronounced "nabla" or "del."
8.13.2 Geometric Meaning — Direction of Increase
Gradients are the multi-variable generalization of the single-variable derivative. With one input, is a slope — a single number. With two inputs, you need a direction, and a direction needs a vector. The gradient is that vector.
Take the running example . Its gradient is:
At the point , the gradient evaluates to:
The gradient of at is . This vector points away from the origin toward where grows fastest. Since is a bowl opening upward, the steepest increase is radially outward from the center. The vector indeed points radially outward from the origin through .
Sense check: Walk one small step from in the direction , i.e., toward . The function becomes . The rate of change is . Walking in any other direction gives a smaller increase — confirming is indeed the direction of steepest ascent.
8.13.3 Gradient Descent Intuition
The gradient always points in the direction of steepest increase. To minimize a function — the whole point of training a machine learning model — you step in the opposite direction.
Gradient descent update rule (conceptual):
where (eta) is the step size, also called the learning rate. Bigger means faster descent but risks overshooting the minimum. Smaller is safer but slower. This trade-off drives all of optimization-based ML.
8.13.4 Visual Intuition
Draw a 3D bowl-shaped surface: . The bottom of the bowl is at , where . At any point on the bowl, the gradient points radially outward — directly away from the minimum. To reach the bottom, you always walk directly toward the origin, which is exactly opposite the gradient.
Now picture the gradient vector field: every point gets a little arrow pointing outward. These arrows get longer as you move away from the center (because and grow). The field tells you, everywhere, which way is "uphill." Gradient descent follows the negative of that field. It flows downhill to the bowl's bottom.
8.13.5 Assumptions and Scope
Scope. The gradient is defined for any scalar-valued differentiable function of multiple variables. It generalizes to inputs: , with .
Direction of steepest ascent is proven. Among all unit-length directions , the directional derivative is maximized when points along (by Cauchy-Schwarz).
When it fails. The gradient points toward steepest ascent, not necessarily toward the global maximum — only the local one. On a bumpy loss surface, the gradient takes you to the nearest peak, which might be a tiny hill, not the mountain.
8.13.6 Pitfalls
- Thinking the gradient points toward the minimum. It points toward the maximum. Gradient descent steps in the opposite direction. The sign convention matters everywhere in ML.
- Assuming the gradient is always positive. The gradient has a direction, not a sign. Its components can be negative. A component of means "the function decreases as you move in the direction." That in turn means the function increases as you move in the direction.
- Confusing (scalar) with (vector). With one input, the derivative is a number. With multiple inputs, the derivative is a gradient vector. Same concept, different dimension.
8.13.7 Recap and Bridge
The gradient is the vector of partial derivatives, pointing toward steepest increase. Gradient descent steps opposite the gradient: . This single update rule trains every neural network.
8.13.8 Real-World and Domain Connection
Every training run of every neural network — from a 3-layer perceptron to GPT-5 — uses gradient descent. The algorithm is the same. Compute the gradient of the loss with respect to every parameter. Backpropagation does this: it is the chain rule applied to a computation graph. Then nudge each parameter slightly against its gradient. The learning rate is the most tuned hyperparameter in deep learning.
Gradients also drive reinforcement learning and computer vision. They power physics simulations and economics. In economics, marginal rates of substitution are literally partial derivatives in disguise.
8.13.9 Student Questions and Answers
Q: Is the gradient always positive?
A: No. You can stand anywhere on the surface. The gradient's direction points toward where the function increases. Its components can be negative. If the function rises as you move , that component is positive. If it rises as you move , that component is negative. The gradient is about direction of increase, not a sign constraint.
Q: So even when the value is negative, the gradient points toward a positive direction of increase?
A: Yes — it is ascending toward larger function values. "Negative" describes the individual component value, not the goal. The gradient always points uphill — toward higher function values than the current point. If you are at , the gradient points toward , which is "more positive" (less negative).
8.13.10 Exam Notes
Exam note: Vector calculus (derivatives, partial derivatives, gradients, chain rule) is the most scoring block on the mid-semester. Students historically score better here than on linear algebra. The questions are more direct — compute the gradient, apply the chain rule, find partial derivatives.
Exam note: Principal component analysis (PCA) arrives in lecture ~11 and ties directly back to SVD. The "first singular value dominates when columns are correlated" rule from SVD becomes the "first principal component captures max variance" rule in PCA.
Exam note: Gradients of vector-valued functions (Jacobians) are deferred to the next session and will finish before the exam.
8.13.11 Symbol Registry
- — scalar-valued function of two inputs — scalar, .
- — input variables — scalars, real.
- , — partial derivatives — scalars.
- — the gradient vector — .
- — learning rate (step size) — scalar, .
- — a unit vector giving a direction — , .
Exam Guidance Summary
This is a consolidation of all exam-relevant guidance from Lecture 8. Use it as a study checklist for the mid-semester exam.
Mid-Semester Scope
- Syllabus: Slides from lecture 1 through lecture 8. Lecture 8 is the final lecture in the mid-semester syllabus.
- Gram-Schmidt process: Orthonormal basis computation () is in scope. It will be reviewed in the final review lecture (~lecture 14) and the next extended session. Question 12 in the example solutions covers it — confirm it is in scope.
- Slides: Uploaded to the course files section (lectures 1 through 8).
SVD — High Exam Priority
Exam note: A numerical SVD problem is highly likely. The professor explicitly told students to expect one.
What to practice:
- Compute for a given rectangular matrix .
- Find eigenvalues from .
- Find eigenvectors and normalize them to get columns of .
- Take square roots of eigenvalues to get singular values: .
- Build as a rectangular diagonal matrix matching 's shape.
- Recover column by column: .
- For zero singular values, use cross product (in ) or orthogonality to get the remaining columns of .
Key strategy rule:
- Long-format (): compute first (the smaller square).
- Wide-format (): compute first.
- Always pick the smaller of the two. You can derive the larger from it.
Vector Calculus — Most Scoring Block
Exam note: Vector calculus is historically the best-scoring section. Students find it more approachable than linear algebra, and questions are more direct.
Key topics to master:
- Limit definition of the derivative: .
- Power rule: .
- Product rule: .
- Chain rule: .
- Partial derivatives: treat all but one variable as constant.
- Gradient: vector of partial derivatives, pointing toward steepest increase.
- Gradient descent: .
What Comes Next
- Gradients of vector-valued functions (Jacobians) — deferred to next session, will finish before the exam.
- Principal Component Analysis (PCA) — arrives in lecture ~11. Ties back to SVD: principal components = right singular vectors, variance captured = squared singular values.
- Consolidated topic list — will be shared by the professor around the final review lecture (~14th).
The remaining calculus topics plus PCA will be covered with practice time before the exam. Focus your study on the SVD numerical and the five calculus rules (power, product, chain, partials, gradient).
Key Industry Applications
Large Language Model Fine-Tuning (LoRA / PEFT)
Low-Rank Adaptation (LoRA) decomposes giant language model weight matrices — think Gemini-class models with billions of parameters — into low-rank forms. Instead of updating the full weight matrix during fine-tuning, LoRA freezes . It inserts a trainable low-rank product . Here and , with (e.g., for a matrix). The effective update is:
This reduces trainable parameters from to . That is a reduction of orders of magnitude. It still matches full fine-tuning accuracy. Every article on "parameter-efficient fine-tuning" for LLMs applies the SVD principle. Most weight updates live in a low-dimensional subspace, so you can represent them with a small-rank product.
Image Compression (WhatsApp-style)
Sending a 1920 × 1080 photo as a raw matrix takes ~6 MB. WhatsApp-style compression decomposes the pixel matrix via SVD. It keeps the top singular values (typically the first few hundred out of 1080), and reconstructs from those. The image looks nearly identical because the small singular values correspond to imperceptible high-frequency noise. The storage drops from numbers to numbers — a 10× to 100× reduction.
Recommendation Systems (Netflix-style)
A user-movie rating matrix with millions of users and thousands of movies is typically rank-50 or lower. That means only ~50 underlying "taste factors" explain all ratings. SVD identifies these factors. Columns of are user-taste profiles, and columns of are movie-taste profiles. weights each factor's importance. The Netflix Prize was won using matrix factorization built on SVD.
NLP and Text Analysis
Tweet and document-term matrices are long-format (millions of documents, thousands of terms) — exactly the SVD regime. Latent Semantic Analysis (LSA) decomposes a term-document matrix via SVD. It projects both terms and documents into a lower-dimensional "semantic space." Terms that co-occur in similar contexts end up with similar vectors. For example, "car" and "automobile" land close together. That enables synonym-aware search without manual thesauri.
Computer Vision and Image Processing
Every pixel-level image manipulation — rotation, scaling, compression, denoising — decomposes the image matrix. SVD separates structure (large singular values) from noise (small singular values). Removing the noise terms and reconstructing gives denoised images. Game engines also use SVD's polar decomposition to separate rotation from deformation in physics simulations.
Principal Component Analysis (PCA)
PCA is SVD applied to centered data. Given a data matrix where each column is mean-centered, compute the SVD . The principal components are the columns of . The variance along each component is . The low-dimensional projection is where keeps only the first columns. When features are highly correlated, dominates and PCA captures nearly all variance in a single component. This is the same "age ≈ experience" effect you saw in section 8.2.
MFML Lecture 08 notes · Singular Value Decomposition and Vector Calculus
Sections Breakdown
Why eigen decomposition fails on non-square matrices and what SVD is.
Rank as independent directions, capped at min(m, n), and how correlation reduces it.
SVD as the sum of rank-1 pieces and the Eckart-Young optimality of truncation.
A = U Sigma V^T with the dimensions of each factor and the geometric roles.
The rotate-scale-rotate story and alignment to the direction of maximum variance.
Full numerical SVD: A^T A, eigenvalues, eigenvectors, Sigma, and U via AV = U Sigma.
Rank-k truncation, the safe-truncation condition, and image compression.
The derivative as the limit of the difference quotient, with the x^2 example.
d/dx x^n = n x^{n-1} derived from the binomial theorem.
Differentiating a product: (uv)' = u'v + v'u, with the x sin x example.
Differentiating composite functions by multiplying derivatives along the chain.
Slopes along one input while holding others constant, for multi-variable functions.
The gradient vector and gradient descent for minimizing a function.
Consolidated mid-semester exam strategy for SVD and vector calculus.
LoRA, image compression, recommender systems, NLP, PCA, and computer vision.
Exam Revision Notes
Below is the distilled, exam-ready core of this lecture. Every entry is built from the full textbook notes above. Use this section for rapid review — but if something doesn't make sense, go back to the full explanation in the main content.
Singular Value Decomposition — Definition and Dimensions
Must-know: Any real matrix splits into , where (size ) and (size ) are orthogonal and (size ) holds the singular values on its leading diagonal. SVD is the tool eigen decomposition cannot be: it works on rectangles.
⚠️ Top pitfall: Forgetting that is rectangular — it has the exact shape of , and only the first diagonal entries can be non-zero.
Self-check: For a 1000 × 2 matrix, what are the dimensions of , , and ?
Connects to: Rank, SVD worked computation, geometric intuition, low rank approximation.
Rank and Maximum Possible Rank
Must-know: Rank is the number of linearly independent rows or columns — the number of truly independent directions in your data. It is capped at . Linear correlation among columns (like age ≈ experience) drops the actual rank below the maximum.
⚠️ Top pitfall: Counting rows instead of independent directions — a 1000 × 2 matrix has rank at most 2, never 1000.
Self-check: If two columns are exact linear copies, what is the rank of a 1000 × 2 matrix?
Connects to: SVD, low rank approximation, truncation safety.
Low Rank Approximation (Eckart–Young)
Must-know: Rewriting as a sum of rank-1 outer products lets you keep the first terms (largest ) and drop the rest. The Eckart–Young theorem says this is the best rank- approximation in the Frobenius norm — nothing else gets closer.
⚠️ Top pitfall: Truncating when singular values are comparable — if the spectrum is flat, dropping terms destroys signal. Truncation is only safe when the tail are tiny.
Self-check: When is it safe to keep only the top singular value, and when is it destructive?
Connects to: Rank, SVD definition, image compression, LoRA.
Geometric Intuition — Rotate, Scale, Rotate
Must-know: Every linear map is rotate → scale → rotate. aligns the data to its axes of greatest variance, stretches/squishes along those axes, and rotates back to the output frame. A unit circle becomes an ellipse whose semi-axes are the singular values.
⚠️ Top pitfall: Thinking "scaling" means only stretching — a singular value of 0.01 squishes an axis to 1% of its size. Scaling includes shrinking.
Self-check: Why must you rotate before scaling, rather than scaling the original features directly?
Connects to: SVD definition, PCA, truncation.
SVD Worked Computation (the Recipe)
Must-know: For a tall matrix start from the smaller square . Eigen-decompose it for and , set , then recover . A numerical SVD problem is highly likely on the exam — practice the full walkthrough.
⚠️ Top pitfall: Dividing by for the leftover column. Use the cross product (in ) or orthogonality to fill it; also forgetting to normalize eigenvectors breaks .
Self-check: For the matrix , what are and ?
Connects to: SVD definition, eigen decomposition (L6/L7), rank.
Truncated SVD and Image Compression
Must-know: Keeping only the top singular values stores a 1920 × 1080 image with roughly numbers instead of ~2 million — a 10× to 100× shrink with no visible quality loss when the spectrum drops steeply.
⚠️ Top pitfall: Assuming truncation is always safe. In our worked 3 × 2 example and are comparable, so a rank-1 cut visibly smears the zeros in the corners.
Self-check: Why does a steep singular-value spectrum make compression nearly lossless?
Connects to: Low rank approximation, Eckart–Young, LoRA.
Derivative — Limit Definition
Must-know: The derivative is the instantaneous rate of change — the speedometer reading. It is the limit of the average rate as the nudge collapses to zero. Never plug in directly (that gives 0/0).
⚠️ Top pitfall: Treating as an ordinary fraction, or confusing the average rate (without the limit) with the instantaneous rate (with ).
Self-check: Using the limit, what is the derivative of at ?
Connects to: Power rule, partial derivatives, gradient.
Power Rule
Must-know: For , bring the exponent down as a multiplier and reduce it by one. This was derived from the limit definition using the binomial theorem (valid for positive integer ).
⚠️ Top pitfall: Forgetting to drop the exponent — , not . Also, the power rule needs the base to be and the exponent constant; for it does not apply.
Self-check: What is at ?
Connects to: Limit definition, chain rule, product rule.
Product Rule
Must-know: Differentiate one factor while holding the other, then swap and add. Each derivative pairs with the other function, not its own.
⚠️ Top pitfall: Writing or . Also, if a factor is composite (like ), you still need the chain rule on that factor first.
Self-check: Differentiate and check the result at .
Connects to: Power rule, chain rule.
Chain Rule
Must-know: For nested functions, multiply the derivative of the outer layer by the derivative of the inner layer. Each link is a simple derivative; you follow the dependency chain link by link. This is the backbone of backpropagation.
⚠️ Top pitfall: Dropping the inner derivative — is , never just . Stop only after differentiating every layer.
Self-check: Differentiate and verify the value at .
Connects to: Power rule, product rule, gradient descent in neural nets.
Partial Derivatives
Must-know: A partial derivative measures the slope along one input direction while freezing all others as constants. The computation is ordinary differentiation with the other variables treated as fixed numbers.
⚠️ Top pitfall: Forgetting to hold other variables constant — , not . Use for multi-input functions, for single-input.
Self-check: For , what are the two partials at ?
Connects to: Gradient, derivative, SVD variance intuition.
Gradients and Gradient Descent
Must-know: The gradient stacks all partial derivatives into one vector pointing toward steepest increase. To minimize a function you step opposite the gradient, scaled by the learning rate . This single rule trains every neural network.
⚠️ Top pitfall: Thinking the gradient points to the minimum — it points to the maximum. Gradient descent uses the opposite sign. Also, the gradient has a direction, not a fixed sign; its components can be negative.
Self-check: For , what is at and which way does descent step?
Connects to: Partial derivatives, chain rule, PCA via SVD.
Was this lecture useful?
BitsNotes AI Assistant
Subject Notes AssistantConfigure AI Chat
Choose how to access the chatbotSigned in as
Powered by BitsNotes — 20 messages per day. No API key needed. Want unlimited access? Use "Bring Your Own Key" mode.
Sign in to use AI Chat
Get 20 free AI messages per day to ask questions about your lecture notes. Sign in with Google or GitHub — it takes 5 seconds.
Sign In to BitsNotesSwitch to "Bring Your Own Key" tab above for unlimited access with any OpenAI-compatible provider.