[MML]
Linear Algebra with MML 1: Vector Spaces and Subspaces
When you first learn linear algebra, you treat a vector as an "arrow" and a matrix as a "table of numbers" and move on. But once you start handling data, weights, and embeddings in machine learning, you need a fundamental agreement about why these objects can be freely added and scaled within a single space. That agreement is the vector space.
This post is based on Mathematics for Machine Learning (Deisenroth, Faisal, Ong), Chapter 2 Linear Algebra, Section 2.4 Vector Spaces — the standard textbook for the math of machine learning.
What you'll learn#
- Groups — the minimal rules a set and an operation must satisfy
- The definition of a vector space — two operations and eight axioms
- Why a vector isn't only an arrow — polynomials, matrices, and functions are vectors too
- Vector subspaces — a space within a space, and why it always contains the origin
- Linear combinations and span
Why do we need the abstraction "vector space"?#
Whether it's an arrow in , a cubic polynomial, or a image, we use the same two operations on all of them: addition and scalar multiplication.
Mathematics extracts this common structure and gives the name vector space to "a set with two such operations satisfying certain rules." Once the rules are fixed, a theorem proved for arrows applies unchanged to polynomials, matrices, and functions. That is exactly the payoff of abstraction.
Groups — the skeleton of a vector space#
To define a vector space, you first need the notion of a group. A set with an operation is a group if it satisfies these four axioms.
| Axiom | Meaning |
|---|---|
| Closure | |
| Associativity | |
| Identity | |
| Inverse |
If it additionally satisfies commutativity , it is an Abelian group.
Key point: Integer addition is an Abelian group, but integer multiplication is not a group — it has no inverses (e.g. the inverse of would be , which is not an integer).
Definition of a vector space#
A vector space is a set equipped with two operations.
- Vector addition
- Scalar multiplication
Then must be an Abelian group, and scalar multiplication must satisfy the following rules. Altogether that is eight axioms.
| Group | Axiom |
|---|---|
| Addition (Abelian group) | closure, associativity, identity (zero vector ), inverse (), commutativity |
| Distributivity 1 | |
| Distributivity 2 | |
| Scalar associativity | |
| Scalar identity |
An element satisfying these axioms is called a vector.
The most familiar vector space is the -dimensional real space , where a vector is the column vector you already know.
Note: The sum and the scalar multiple of vectors must again lie in (closure). But a "product" of two vectors () is not part of the definition of a vector space.
A vector isn't only an arrow#
Anything that satisfies the vector-space axioms is a "vector." An arrow is just one example.
| Set | What the vector is | Zero vector |
|---|---|---|
| column vector with coordinates | ||
| polynomials of degree | constant function | |
| matrices | all matrices | zero matrix |
| real functions | the function itself |
For instance, adding or scaling two polynomials still yields a polynomial, and all eight axioms hold.
So the set of polynomials is a bona fide vector space too.
In practice? In deep learning a single image is a matrix and simultaneously a 784-dimensional vector.
Because we view data as elements of a vector space, a single matrix operation can transform thousands of images at once.
Vector subspaces#
If a subset of a vector space is itself a vector space, then is a subspace of .
To check whether a subset is a subspace, you only need three things.
- , and in particular the zero vector
- closed under addition:
- closed under scalar multiplication:
The crucial point is that a subspace always passes through the origin. Substituting gives .
A line through the origin is a subspace of . A line that does not pass through the origin (e.g. ) does not contain and is therefore not a subspace.
Key point: "Does it pass through the origin?" is the first gate for a subspace. Relaxing this condition to handle planes and lines that miss the origin leads to the affine space, which comes next.
Linear combinations and span#
For vectors and scalars , a vector of the following form is a linear combination.
The set of all linear combinations you can build from a set of vectors is called its span, written .
A span is always a subspace of . For example, in the span of two distinct vectors is a plane through the origin.
In practice? The span is exactly "the range of data expressible as combinations of these features."
If the span fails to cover the whole original space, there remain directions that no amount of training can represent.
Vector spaces in machine learning#
Here is how the abstract definitions above actually show up in ML.
| Concept | Where it appears in ML |
|---|---|
| vector space | feature space — one data point = one vector |
| vector addition / scalar mult. | embedding-vector arithmetic (e.g. king - man + woman ≈ queen) |
| subspace | the low-dimensional space PCA projects data onto |
| span | the range of outputs a model can represent |
In other words, the data and parameters a model works with are all elements of some vector space, and training is the process of finding a good vector (weights) within that space.
Summary#
| Concept | Description |
|---|---|
| Group | set + operation satisfying closure, associativity, identity, inverse |
| Abelian group | a group that also satisfies commutativity |
| Vector space | is an Abelian group + scalar-multiplication axioms (eight in total) |
| Vector | an element of a vector space (not just arrows — polynomials, matrices, functions) |
| Subspace | a subset that is itself a vector space; must contain |
| Linear combination | a vector of the form |
| Span | the set of all linear combinations (always a subspace) |
Quiz#
Q1. Is (natural numbers under addition) a group? If not, which axiom fails?
Show answer
It is not a group. It satisfies closure, associativity, and identity (, if your definition of includes zero), but it lacks inverses. For example, the additive inverse of is , which is not a natural number, so the inverse axiom fails.
Q2. In , is the set a subspace?
Show answer
It is not a subspace. When we get , so this line does not pass through the origin . Since it does not contain the zero vector, it cannot be a subspace. (The line through the origin would be a subspace.)
Q3. What is the span of and ?
Show answer
Since can be any real numbers, the span is all of .
Q4. If the set of polynomials of degree is a vector space, what is its zero vector?
Show answer
The polynomial with all coefficients equal to , i.e. the constant function . Adding it to any polynomial gives , so it serves as the additive identity.
In the next post we'll look at how much the vectors of a vector space overlap with one another: linear independence, basis, dimension, and rank.