The course has multiplied matrices by vectors since the first lesson, and has described them as factorisations, projections and changes of basis. What it has not done is state what a matrix is as a mathematical object. This lesson establishes it: a matrix is the representation of a function, and of a very particular kind of function.
The definition
A map between vector spaces is linear if it respects the two operations that define a vector space:
Both are summarised in a single condition, which is the usual way of checking it:
The reading is that the order of the operations is immaterial: combining and then transforming produces the same result as transforming and then combining.
Φ(λx + y) = (0.30, 4.85) · λΦ(x) + Φ(y) = (0.30, 4.85)
Drag x or y in the left panel.
difference = 0e+0
The left panel shows , and the combination ; the right, their images. The highlighted arrow on the right is , and it coincides with for any position of the vectors and any value of .
From the definition it follows that , taking and . A map that shifts the origin is not linear, however much it sends lines to lines: the function with is affine, not linear.
Every linear map is a matrix
Let be linear and the canonical basis. Every vector is written , and applying linearity
The map is determined by the images . Placing them as the columns of a matrix , the expression above is exactly .
The correspondence is bijective: every matrix defines a linear map, and every linear map comes from a unique matrix. That equivalence is what justifies using the two languages interchangeably, as the course has been doing.
import numpy as np
A = np.array([[2., 0.],
[0., 3.]])
A @ np.array([1., 0.]) # array([2., 0.]) = first column
A @ np.array([0., 1.]) # array([0., 3.]) = second column
The matrix depends on the bases
The claim above presupposes the canonical basis at both ends. In general, the matrix of a linear map depends on the basis chosen in the domain and on the one chosen in the codomain.
Given bases of and of , the matrix is built by expressing the image of each vector of in coordinates of :
and then .
Changing basis changes the matrix without changing the map. If is the matrix with respect to other bases, the two are related by
with and the changes of basis in domain and codomain, in the sense described in the lesson on basis and dimension. When and the same basis is used at both ends, the relation reduces to , which is called similarity.
Hence a consequence the course has used without naming it: one map admits very different matrices, and choosing the basis well can make it trivial. A diagonal matrix is simply a map written in a basis where it does not mix directions.
Composition
The composition of two linear maps is linear, and its matrix is the product:
The order reads right to left, as in any composition of functions. The associativity of the matrix product, , is at bottom nothing but the associativity of function composition.
B = np.array([[0., -1.],
[1., 0.]]) # rotation by π/2
x = np.array([1., 2.])
np.allclose((B @ A) @ x, B @ (A @ x)) # True
Injective, surjective, bijective
Rank classifies the map completely. For with matrix of rank :
| Property | Condition | Reading |
|---|---|---|
| injective | : no direction collapses | |
| surjective | : the whole target is reached | |
| bijective | invertible |
The first row is the rank-nullity theorem of the lesson on particular and general solutions: , so the null space is trivial exactly when . An injective map preserves information; a non-injective one sends distinct vectors to the same destination, and that loss is irreversible.
A bijective linear map is called an isomorphism, and two spaces admitting one between them are indistinguishable from the point of view of linear algebra. The criterion is purely dimensional:
This is why every real vector space of dimension can be treated as : choosing a basis is exactly building that isomorphism. Polynomials of degree at most are indistinguishable from , and the list of coefficients is the isomorphism.
Application: why a network needs non-linearities
A dense layer computes , which is an affine map. Composing several layers with nothing between them gives
that is, another affine map with a single matrix. A stack of linear layers is one linear layer, regardless of its depth.
The bound on the rank of a product, established in the previous lesson, adds a further limitation:
W = W₄W₃W₂W₁ · rank(W) ≤ 8
the map is not injective: information is lost
A chain of linear layers, one of them narrow.
Without non-linearities the chain is one matrix, and the narrowest layer caps its rank.
The narrowest layer imposes a ceiling on what the whole chain can represent. With a layer of width among layers of width , the composition has rank at most however full-rank the others are, and the map stops being injective.
Non-linear activation functions placed between layers break this identity: the composition is no longer a linear map and the arguments above stop applying. Depth contributes expressive capacity only because that interruption exists.
The reasoning also has a constructive reading. When the bottleneck is deliberate, as in an autoencoder, the rank bound is the mechanism: forcing the representation through a narrow layer compels it to discard everything but the most informative directions, which is the low-rank approximation of the previous lesson applied to the weights.
Exercise. Check that with fails the linearity condition, by evaluating both sides of . Then build three matrices of shapes , and , and verify that the rank of their product does not exceed .