2.7 Linear Mappings
The question
Two questions that both come down to what the word “linear” is actually claiming:
The questions (in substance):
- “Linear” in linear algebra doesn’t mean a straight line, does it?
- Not all functions are vectors — is that right?
The short answer to both is no, not in the everyday sense and right, but with a precise caveat. This note is about the precise version.
Answer
The two rules
A map is linear when it satisfies exactly two properties:
In words: adding inputs then mapping gives the same result as mapping then adding, and scaling the input scales the output by the same factor. A matrix map satisfies both by the distributivity of matrix multiplication, which is why matrices are the linear maps.
Homogeneity is also the answer to the §2.2 question about scaling production by 10×: the resource totals scale by exactly 10×, and that is the definition, not a property of the particular example.
Why “straight line” is the wrong picture
A line through the origin, , is linear. But so is a great deal that is not a line:
- — a flat plane in 3D. Doubling and doubles ; adding two points adds their values.
- A matrix that rotates, shears, reflects or stretches space. Grid lines stay straight and parallel; a square can become a parallelogram. Still linear.
- The production model : make twice as much, consume twice as much.
What is not linear:
That last one is affine, not linear. The test is immediate: a linear map must send zero to zero, because . Since , it fails. This is why the book is careful to separate linear mappings (§2.7) from affine mappings (§2.8) — and it is the same distinction, one dimension down, as “why doesn’t the straight line count”.
Are functions vectors?
The word “function” is doing two different jobs here, and separating them resolves the question:
| Sense | What it is | A vector? |
|---|---|---|
| A function as an object | a point in a function space, e.g. | Yes, if its set satisfies the vector-space axioms |
| A function as a transformation | an operation that acts on vectors, e.g. | No — it acts on the space rather than living in it |
Functions-as-objects can be added and scaled in the obvious way:
so the collection of such functions is a vector space and each individual function is a vector in it. A function is essentially a very long (often infinite) list of values. The caveat is that a set of functions is only a vector space if it satisfies the axioms: all continuous functions do, polynomials of degree do, but functions taking only positive values do not (no zero, no additive inverses). The axioms themselves are §2.4; the point here is only that “function” and “vector” are not mutually exclusive categories.
In practice
This is the distinction that machine learning runs on, and it is why the notation gets confusing:
- Data points are vectors — an image is a vector of pixel values.
- Model parameters are vectors — the weights you learn.
- A model is a function — it maps input vectors to output vectors.
Training searches a vector space of functions for the function that best maps inputs to outputs. So the model is simultaneously a point in a space (a vector) and a transformation (an operator), which is exactly the ambiguity above.
The concrete payoff is embeddings. Word and image embeddings live in spaces of hundreds to thousands of dimensions, and we cannot visualise them — but we can compute with them, because the rules are identical to the 2D case, just with more arithmetic. A learned embedding is in effect a rotation of the space: an orthogonal matrix, whose columns are mutually perpendicular and unit length, so relative distances and angles are preserved while the axes are chosen to make structure visible. That is the same change-of-basis idea as 2.2, scaled up — and it is why “the model learned a rotation” is often a more useful description than “the model learned weights”.
Worked example
Both rules hold for a matrix map. With , , , :
Failure modes, with numbers. For componentwise, at and :
so additivity fails. For the affine : , so it cannot be linear — homogeneity fails on the constant term.
A rotation is linear and preserves length. With ,
Both linearity rules hold, and lengths are preserved — a pure rotation with no stretching. The identical construction in 5D (a orthogonal matrix, 25 entries) also preserves the norm, which is the sense in which “rotation” still means something once you can no longer draw it.
All numbers are reproduced by scripts/explore_example_2_7.py.
References
- Deisenroth, Faisal & Ong, Mathematics for Machine Learning, Section 2.7 (“Linear Mappings”); the function-space axioms are §2.4 and affine mappings §2.8. See References for the full citation and link.
- Reproducibility script:
scripts/explore_example_2_7.py. - Related notes: 2.2 Matrices.