1  Chasing Yarn Balls

Vectors, Matrices, Linear Algebra, SVD, PCA, Jacobians

🐾 Evergreen Chapter: Core mathematics and theory do not expire. Last verified: 2026-11-26

Prerequisites: Introduction & Baseline; basic Python fluency; high-school algebra.

Technical Keywords: Vectors, Matrices, Linear Algebra, Nullspace, Rank, Column Space, SVD, PCA, Jacobians


Imagine a kitten named Pixel sitting in the center of the living room. Suddenly, a beam of sunlight hits the carpet. Pixel wants to pounce on it. How does Pixel know where to jump?

Pixel’s brain is instinctively doing Linear Algebra — the mathematical language of space, movement, and transformation. Every piece of data in machine learning — whether it’s an image of a mouse, the price of cat food, or a word in a sentence — is eventually translated into this language. To an AI, the entire universe is just a collection of arrows, stretches, and rotations.

Notation Box

  • Data shape convention: X \in \mathbb{R}^{n \times d} where rows are samples and columns are features.
  • A: Generic matrix/transformation.
  • X: Data matrix.
  • \vec{v}: Single vector/sample.
  • w: Weight vector (linear models).
  • W: Neural-network weight matrix.
  • \theta: All trainable parameters as one bundle.
  • Learning rate notation: We use \eta; some papers use \alpha.

High-School Algebra Survival Guide

Throughout this book, you will see terrifying Greek letters. Do not panic. They are just shorthand for simple concepts:

  • \Sigma (Sigma): Just a giant “S” for “Sum.” It means “add all these things up.”
  • \Delta (Delta): Change. If the temperature goes from 70 to 75, \Delta is 5.
  • d or \partial (Derivative): The rate of change of a function with respect to its variable at a point.
  • \int (Integral): A smooth, continuous version of Sigma (\Sigma). It means “find the total area.”

If an equation feels unfamiliar on your first read, start with the kitten analogy and the Python code—then come back to the equation once the intuition clicks. The math isn’t optional, it just gets much easier once you see what it’s doing.


1.1 Vectors: Tiny Paws in Space

To reach the sunbeam, Pixel needs to know two things: how far to jump (magnitude) and which way to jump (direction). An arrow with a direction and a length is called a vector.

If the sunbeam is 3 paws forward and 4 paws sideways, Pixel’s jump is:

\vec{v} = \begin{bmatrix} 3 \\ 4 \end{bmatrix}

Math Box: The Transpose (T)

You might notice the little T at the end of [3, 4]^T. If you remember high-school math, you might think this means “to the power of T”. It does not. In linear algebra, T stands for Transpose. It means swapping rows and columns (reflecting entries across the main diagonal, so (A^T)_{ij} = A_{ji}): for a vector, a vertical column becomes a horizontal row and vice versa; for an m \times n matrix, row i becomes column i, yielding an n \times m matrix. We do this because matrix multiplication requires the shapes to line up perfectly, like snapping Lego bricks together.

The norm (length) of this vector is \|\vec{v}\| = \sqrt{3^2 + 4^2} = 5 paws.

Analogy

The vector is the jump. The norm is how far. The direction is where.

A kitten leaping with a vector arrow showing direction and magnitude

Pixel leaping toward the sunbeam — the arrow shows direction and magnitude.

Core operations we’ll use throughout the academy:

  • Addition: Combine two jumps into one.
  • Scalar multiplication: Stretch or shrink a jump.
  • Dot product: How much do two jump directions agree? (\vec{u} \cdot \vec{v} = \|\vec{u}\|\|\vec{v}\|\cos\theta)
  • Norm: How long is the jump? (\|\vec{v}\| = \sqrt{\sum_i v_i^2})

Rosetta Stone

Kitten World Math Python
“A jump of 3 forward, 4 sideways” \vec{v} = [3, 4]^T np.array([3, 4])
“How long is the jump?” \|\vec{v}\| = \sqrt{v_1^2 + v_2^2} np.linalg.norm(v)
“Do two jumps point the same way?” \vec{u} \cdot \vec{v} = \sum_i u_i v_i np.dot(u, v)

1.2 Matrices: Magical Paw Stamps

Now imagine the living room floor is made of a stretchy rubber sheet. Suddenly, something grabs the sheet and pulls it — stretching everything twice as far to the right, leaving the vertical dimension untouched. Every jump Pixel takes gets transformed by this stretch.

A rubber sheet being stretched to illustrate matrix transformation

The matrix as a rubber sheet transformation.

A matrix is that stretch. It is an operation — a function — that takes a vector and transforms it into a new vector by stretching, rotating, or squishing space.

A = \begin{bmatrix} 2 & 0 \\ 0 & 1 \end{bmatrix}

Apply this to Pixel’s jump [3, 4]^T:

A\vec{v} = \begin{bmatrix} 2 & 0 \\ 0 & 1 \end{bmatrix} \begin{bmatrix} 3 \\ 4 \end{bmatrix} = \begin{bmatrix} 6 \\ 4 \end{bmatrix}

The x-component doubled, the y-component stayed. Deep learning is essentially passing data through millions of these transformations — each one reshaping the information until it takes the form we want.

Catastrophic Failure: Matrix Multiplication is NOT Commutative

If you put your socks on, then your shoes, you get dressed. Reverse the order and you get a mess. Matrix multiplication is non-commutative in general: AB \neq BA (aside from special exceptions such as multiplying with the identity matrix, AI = IA, or two commuting diagonal/rotation matrices). Transforming space and then rotating Pixel is not the same as rotating Pixel and then transforming space. Swapping the order either fails outright when inner dimensions don’t match, or silently yields a different transformation when both matrices are square. Multiplication order must be chosen carefully because swapping it can produce a different transformation.

Rosetta Stone

Kitten World Math Python
“The stretch-and-squish stamp” Matrix A \in \mathbb{R}^{m \times n} np.array([[2,0],[0,1]])
“Apply the stamp to a jump” A\vec{v} A @ v
“Two stamps in sequence” AB (order matters!) A @ B
“The stamp that does nothing” I (identity matrix) np.eye(n)

1.3 Rank and Column Space: Where Can Kitty Reach?

Let’s say Pixel wants to explore the living room. He can combine two fundamental moves: forward and right. By mixing these freely, he can reach any point on the flat 2D floor. The entire set of reachable positions is called the column space (also called the range or image) of his moves.

Formally: rank = dimension of the column space = number of linearly independent columns.

\text{col}(A) = \{ A\vec{x} \mid \vec{x} \in \mathbb{R}^n \}

Analogy

Rank 2 means Pixel can reach anywhere on the floor. Rank 1 means he’s stuck pacing a single sunbeam line.


Advanced Track Notice (Sections 1.4 – 1.7)

The next few sections introduce concepts used heavily in advanced research (Nullspace, SVD, Jacobians). If the math feels overwhelming on your first read, focus purely on the kitten metaphors and skip to the chapter summary. You only need sections 1.1–1.3 for the Core Track.

1.4 Nullspace: Invisible Paw Paths

The nullspace (also called the kernel) is the set of all vectors that the matrix sends to zero:

\text{Null}(A) = \{ \vec{x} \mid A\vec{x} = \vec{0} \}

The Rank-Nullity Theorem is one of the most important results in linear algebra:

\text{rank}(A) + \text{nullity}(A) = n \quad \text{(number of columns)}

Analogy

Pixel jumps along invisible lines. The matrix stamp does nothing to these jumps — they vanish completely. If your data lives here, your model can’t see it.

Rosetta Stone

Kitten World Math Python
“The directions that disappear” \text{Null}(A) Vt[rank:].T (via SVD)
“How many dimensions survive?” \text{rank}(A) np.linalg.matrix_rank(A)
“How many vanish?” \text{nullity}(A) = n - \text{rank}(A) A.shape[1] - np.linalg.matrix_rank(A)

1.5 SVD: X-Ray Vision for Matrices

Singular Value Decomposition (SVD) decomposes any transformation into three clean steps:

A = U \Sigma V^T

  1. V^T: Rotate Pixel to face a new set of axes (the input directions).
  2. \Sigma: Stretch or squish Pixel’s jump along those new axes by amounts \sigma_1 \geq \sigma_2 \geq \dots \geq 0.
  3. U: Rotate again to land in the output space.

SVD decomposition diagram

SVD decomposition: three clean steps from any messy matrix.

Rosetta Stone

Kitten World Math Python
“X-ray the matrix” A = U\Sigma V^T U, s, Vt = np.linalg.svd(A)
“How much does direction i get stretched?” Singular value \sigma_i s[i]
“The most important directions” Columns of U (large \sigma) U[:, :k]
“The nullspace (via SVD)” Columns of V for \sigma \approx 0 Vt[rank:].T

1.6 PCA: Favorite Sunbeam Paths

Principal Component Analysis (PCA) finds the maximum-variance directions in a dataset and projects data onto them. While dropping low-variance directions often reduces measurement noise, low variance does not automatically mean irrelevant noise—subtle, low-variance features can still carry critical predictive signal.

Given a data matrix X, PCA:

  1. Centers the data: X \leftarrow X - \bar{X}.
  2. Computes the covariance matrix: C = \frac{1}{n-1}X^T X.
  3. Finds the eigenvectors of C (equivalently: the right singular vectors of X from SVD).
  4. Projects data onto the top-k eigenvectors.

Rosetta Stone

Kitten World Math Python
“Find the main directions of movement” Eigenvectors of C = \frac{1}{n-1}X_c^T X_c (X_c = X - \bar{X}) PCA(n_components=k)
“How much variance does component i explain?” \frac{\lambda_i}{\sum_j \lambda_j} pca.explained_variance_ratio_[i]
“Project onto top-k directions” \tilde{X} = X_c V_k (fit on train split first in predictive workflows) pca.fit_transform(X_train); pca.transform(X_test)

🔗 PCA ↔︎ SVD connection: PCA is just SVD applied to the centered data matrix. The principal components are the right singular vectors V.


1.7 Jacobians: How Sensitive Are Paws to Pokes?

If you lightly poke a sleeping Pixel, his ear might twitch. If you poke harder, he might jump. The question is: how sensitive is the kitten to the poke?

In high-school algebra, you learned “slope” is rise over run. If a 1-inch poke (run) causes a 2-inch ear twitch (rise), the slope is 2. In calculus, a derivative (\frac{df}{dx}) is just that exact same “rise over run,” but measured at one microscopic, specific moment in time.

But Pixel lives in a multi-dimensional world. He has many inputs (pokes, sounds, smells) and many outputs (ear twitch, tail flick, full leap). We can’t just calculate one slope. We need a whole grid of them—one for every possible input-output combination.

That grid of all partial derivatives is the Jacobian matrix:

J_{ij} = \frac{\partial f_i}{\partial x_j}

(Don’t let the curly \partial scare you. It just means “partial derivative”—the slope of one specific thing, assuming everything else in the room stays perfectly still).

The Jacobian tells you: “If I nudge input j slightly, how much does output i change?”

In deep learning, the Jacobian is everywhere. Backpropagation is essentially a chain of Jacobian multiplications. Understanding Jacobians is understanding how gradients flow through a network.

\vec{f}: \mathbb{R}^n \to \mathbb{R}^m \quad \Rightarrow \quad J \in \mathbb{R}^{m \times n}

Analogy

The Jacobian is a sensitivity map. Poke Pixel here → his ear moves this much. Poke him there → his tail swishes this much. Each entry in the Jacobian is one such poke-response pair.

Rosetta Stone

Kitten World Math Python (PyTorch)
“Sensitivity grid” J_{ij} = \partial f_i / \partial x_j torch.autograd.functional.jacobian(f, x)
“How gradients flow backward” Chain rule via Jacobians loss.backward()
“Single output, many inputs” Gradient \nabla f \in \mathbb{R}^n torch.autograd.grad(output, params)

1.8 How It All Connects

Concept What It Tells You Where You’ll See It Again
Vector Direction + magnitude of data Everywhere
Matrix Transformation of space Every layer of a neural network
Column Space What outputs are reachable Model expressivity
Nullspace What inputs are invisible Adversarial examples, blind spots
Rank Information richness Low-rank approximations, attention
SVD X-ray decomposition of any matrix PCA, embedding analysis
PCA Variance-preserving dimensionality reduction Feature selection, visualization
Jacobian Sensitivity grid of any function Backpropagation, adversarial robustness

Micro-notebook (optional): micro-notebooks/phase01_ch01_svd_pca_intuition.ipynb
Time: ~20 minutes. Goal: visualize principal directions with SVD/PCA on tiny 2D synthetic data.


1.9 Removing the Training Wheels

The Real Engineering

In this chapter, we used kittens jumping and magic paw stamps to explain Vectors and Matrices. In the real world, an image is flattened into a massive vector of raw pixel intensities, and a neural network layer is literally just a giant matrix multiplication A @ x. The ‘nullspace’ isn’t an invisible path; it’s a mathematical subspace where feature information is irreversibly crushed to zero during this multiplication. You also have to distinguish incompatible dimensions from non-commutativity: multiplying an m \times n matrix by a p \times q matrix with n \neq p crashes immediately with a shape mismatch, whereas on square matrices (where both orders have matching shapes) A @ B != B @ A in general runs without error yet can silently produce the wrong mathematical result.

1.10 Paws and Reflect: Chapter Quiz

Work through these conceptually before revealing the answers.

  1. Pixel’s image of a mouse has 10,000 pixels, but most of them are blank wall. Which technique lets us compress this image while keeping the parts that vary most?

  2. A neural network layer applies a matrix to your data. Three features in your input completely vanish — the output gives them zero weight no matter what. What “space” did those features fall into?

  3. You have a 4 \times 4 matrix of rank 2. What is its nullity? What does that mean geometrically?

  4. True or False: A Jacobian matrix tells you how likely a cat is to get a treat.

  5. Why does a rank-1 matrix have a lower-dimensional column space, and why might that be a problem for a machine learning model?

Reveal answers
  1. PCA — it finds the directions of maximum variance.
  2. The nullspace of that layer’s weight matrix.
  3. Nullity = 4 − 2 = 2; two input directions are completely erased by the transformation.
  4. False — a Jacobian measures rate of change of outputs with respect to inputs.
  5. A rank-1 matrix projects all inputs onto a single line — it can only ever produce one direction of output, which severely limits expressivity.

1.11 Chapter 1 Summary

You’ve learned the geometric language of machine learning:

  • Vectors are directional data. Everything is a vector.
  • Matrices transform space. Every layer of a neural network is a matrix (plus a nonlinearity).
  • Rank and column space tell you what a matrix can express.
  • Nullspace tells you what a matrix is blind to.
  • SVD X-rays any matrix into its fundamental structure.
  • PCA finds the directions of maximum variance and compresses data intelligently.
  • Jacobians measure sensitivity — the foundation of backpropagation.

In Chapter 2, we add probability — and the world starts becoming uncertain. 🐈


AI Safety Thread: Chapter 1

Matrix nullspace (\text{Null}(A) = \{\vec{x} \mid A\vec{x} = \vec{0}\}) is a structural property of a linear transformation or layer A: any input perturbation \vec{\delta} \in \text{Null}(A) leaves A(\vec{x} + \vec{\delta}) = A\vec{x} unchanged, creating a blind spot where that layer cannot detect changes along those directions. Training-data distribution shift is a separate statistical problem (explored in Chapters 18 and 26) where live inputs differ from the training distribution—though in linear models, directions absent from the training data lie in the nullspace of the data matrix X, leaving weights along those directions unconstrained by the training loss. Always ask: what is this model structurally blind to, and how might live inputs fall outside what it learned?


Next: Chapter 2: Kitty Dice & Treat Probabilities →