Math for AI course · Lesson 36 of 180
Kernel and Image Show What a Linear Layer Loses and Can Reach
Use a matrix’s kernel and image to identify discarded input directions, reachable outputs, and rank limits in a learned projection.
A model’s projection can turn two different feature vectors into the same representation. Once that happens, no later layer can tell those inputs apart from that representation alone. Two ideas make the effect precise: the kernel identifies input changes a linear mapping erases, while the image describes the outputs it can produce.
By the end, you will be able to find both sets for a small matrix and explain what they reveal about information loss and representable outputs.
Learning outcome: Find simple null-space and image examples and interpret them.
This lesson connects the rank of a matrix from Lesson 033 with the matrix representation of a linear mapping from Lesson 035. Section 2.7.3 of Mathematics for Machine Learning introduces the image and kernel of a linear mapping. The projection, calculation, AI interpretation, visual, and questions below are original.
One projection can erase a direction and restrict its outputs
Consider the mapping represented by
It preserves the first two coordinates and sets the third to zero. The kernel of a linear mapping is the set of inputs in that map to the zero vector in . Its image is the set of outputs in that the mapping can produce from some input. These sets belong to different spaces: the kernel is about inputs; the image is about outputs.
Here, kernel means the null space of a linear map. Machine learning also uses “kernel” for functions that compare examples in kernel methods; that is a separate concept.
For , an input reaches zero exactly when and , while can be anything. So the kernel is the -axis:
Every output has the form , and each such vector is reachable by using the input . Therefore the image is the -plane:
The figure separates these two questions. The vertical kernel direction marks input variation that vanishes; the shaded image plane marks the outputs that remain available.
Input space ℝ³
- x = (2, 1, 0)
- x + k = (2, 1, 2)
- k = (0, 0, 2)
Reachable outputs: Im(P)
Every output has third coordinate 0
P(x) = P(x + k) = (2, 1, 0)
Kernel vectors explain which inputs collapse together
Take and add the kernel vector . The inputs differ, but their mapped values agree:
So the kernel is not a list of inputs the matrix ignores individually. It is the collection of directions along which an input can move without changing the result. If a model only receives the projected vector, it cannot recover where along those directions the original input started.
The image is a limit on what downstream code can receive
The same has rank two because its image has two independent directions. Its kernel also has dimension one. These numbers add to the dimension of the input space:
This is the rank-nullity theorem for a linear mapping from a finite dimensional input space. It connects the number of independent output directions to the number of independent input directions collapsed to zero. For an matrix acting on column vectors, the image is the span of its columns, the kernel solves , and rank plus nullity equals , the number of input coordinates.
That last number matters when reading shapes in code. NumPy’s @ operator is
matrix multiplication:
an matrix times an -entry vector produces an -entry vector.
For this projection, a short calculation confirms the shared output and the
vanishing kernel direction:
import numpy as np
P = np.diag([1, 1, 0])
x = np.array([2, 1, 2])
k = np.array([0, 0, 2])
print(P @ x) # [2 1 0]
print(P @ (x - k)) # [2 1 0]
print(P @ k) # [0 0 0]
The same distinction helps diagnose a learned projection
A learned weight matrix also maps one feature vector to another. PyTorch’s
torch.nn.Linear applies an affine map, , to row-oriented
inputs; setting bias=False leaves the matrix map alone. In column-vector
notation the same operation is . The weight map determines which input
differences disappear: if , then the two inputs produce the same
output because any shared bias cancels. The image of the weight map describes
output directions available from the weights; with a bias, the full output set
is the translated subspace
(PyTorch documentation).
Kernel and image answer separate debugging questions. A nonzero kernel means some distinct feature vectors become indistinguishable at this layer. A restricted image means some output feature combinations cannot be produced at all. A map from to can have a nontrivial kernel while reaching every point in its two-dimensional output space. Conversely, a map from into can preserve all input distinctions while its outputs lie in a plane. Neither question can be answered from the matrix’s output shape alone; rank and the actual subspaces tell you.
The next step is to ask which directions are redundant before compressing a representation. When that choice is learned rather than specified, inspecting the weight map’s rank, kernel, and image reveals what the downstream model can still distinguish and express.
Check your understanding
Question 1
What is the kernel of P(x, y, z) = (x, y, 0), and what is its image?
Show the step-by-step solution
For an input to map to zero, its first two coordinates must be zero, while its third coordinate can be any real number. Thus . Every output has third coordinate zero, and each is produced by the input . Therefore , the -plane.
Question 2
Compute P(4, −2, 5). Which information does the output keep and discard?
Show the step-by-step solution
Apply the matrix coordinate by coordinate: . The first and second coordinates remain, while the third coordinate is erased. Any two inputs with the same first two coordinates therefore share this output.
Question 3
Why do (2, 1, 0) and (2, 1, 6) have the same output under P?
Show the step-by-step solution
Their difference is , which lies in the kernel because . By linearity, .
Question 4
If a linear map has a three-dimensional input space and rank 2, what is its nullity?
Show the step-by-step solution
Rank-nullity says . Substituting gives , so the nullity is . There is one independent input direction that maps to zero.
Question 5
Can a map from ℝ³ to ℝ² have a nonzero kernel and still reach every output in ℝ²?
Show the step-by-step solution
Yes. The coordinate map has kernel , which is nonzero, and its image is all of because any is reached from . Input loss and output reachability are separate properties.
Question 6
Suppose a linear layer adds a fixed bias b. Does adding that bias change which input differences collapse to the same output?
Show the step-by-step solution
No. If , then . The bias cancels, so exactly when lies in the kernel of the weight map . The set of possible outputs is shifted from to .
Question 7
What does a rank-deficient weight map tell you about a model layer’s possible representations?
Show the step-by-step solution
Rank deficiency means the image has fewer independent directions than the output space’s dimension, so some output directions are unreachable. If the rank is also below the input dimension, rank-nullity shows the kernel is nonzero as well: some distinct inputs collapse. Check both dimensions before claiming both effects.