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.

Share this article

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 P:R3→R3P: \mathbb{R}^3\to\mathbb{R}^3 represented by

It preserves the first two coordinates and sets the third to zero. The kernel of a linear mapping T:V→WT:V\to W is the set of inputs in VV that map to the zero vector in WW. Its image is the set of outputs in WW 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 PP, an input reaches zero exactly when x=0x=0 and y=0y=0, while zz can be anything. So the kernel is the zz-axis:

ker⁡(P)={(0,0,z):z∈R}=span⁡{(0,0,1)}.\ker(P)=\{(0,0,z):z\in\mathbb{R}\} =\operatorname{span}\{(0,0,1)\}.

Every output has the form (x,y,0)(x,y,0), and each such vector is reachable by using the input (x,y,0)(x,y,0). Therefore the image is the xyxy-plane:

Im⁡(P)={(x,y,0):x,y∈R}=span⁡{(1,0,0),(0,1,0)}.\operatorname{Im}(P)=\{(x,y,0):x,y\in\mathbb{R}\} =\operatorname{span}\{(1,0,0),(0,1,0)\}.

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.

One map, two different subspacesP(x, y, z) = (x, y, 0): changing z moves the input along the kernel, while every output stays in the xy-plane.

Input space ℝ³

Input space ℝ³The xy-plane is shaded. Two distinct input arrows end at points that differ only in height. A dashed vertical segment between them is labeled k = (0, 0, 2), a kernel direction.x₁x₂x₃xy-planexx + kk
  • x = (2, 1, 0)
  • x + k = (2, 1, 2)
  • k = (0, 0, 2)

Reachable outputs: Im(P)

Reachable outputs: Im(P)The reachable output plane is z = 0. Both inputs map to the same point (2, 1, 0), and the kernel direction maps to the zero vector.y₁y₂y₃z = 0

Every output has third coordinate 0

P(x) = P(x + k) = (2, 1, 0)

Kernel vectors explain which inputs collapse together

Take x=(2,1,0)x=(2,1,0) and add the kernel vector k=(0,0,2)k=(0,0,2). 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 PP 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:

dim⁡(ker⁡(P))⏟nullity 1+dim⁡(Im⁡(P))⏟rank 2=dim⁡(R3)⏟3.\underbrace{\dim(\ker(P))}_{\text{nullity }1} +\underbrace{\dim(\operatorname{Im}(P))}_{\text{rank }2} =\underbrace{\dim(\mathbb{R}^3)}_{3}.

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 m×nm\times n matrix acting on column vectors, the image is the span of its columns, the kernel solves Ax=0Ax=0, and rank plus nullity equals nn, the number of input coordinates.

That last number matters when reading shapes in code. NumPy’s @ operator is matrix multiplication: an m×nm\times n matrix times an nn-entry vector produces an mm-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, y=xAT+by=xA^\mathsf{T}+b, to row-oriented inputs; setting bias=False leaves the matrix map alone. In column-vector notation the same operation is Au+bAu+b. The weight map determines which input differences disappear: if A(u−v)=0A(u-v)=0, 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 b+Im⁡(A)b+\operatorname{Im}(A) (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 R3\mathbb{R}^3 to R2\mathbb{R}^2 can have a nontrivial kernel while reaching every point in its two-dimensional output space. Conversely, a map from R2\mathbb{R}^2 into R3\mathbb{R}^3 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 ker⁡(P)={(0,0,z):z∈R}=span⁡{(0,0,1)}\ker(P)=\{(0,0,z):z\in\mathbb{R}\}=\operatorname{span}\{(0,0,1)\}. Every output has third coordinate zero, and each (x,y,0)(x,y,0) is produced by the input (x,y,0)(x,y,0). Therefore Im⁡(P)={(x,y,0):x,y∈R}\operatorname{Im}(P)=\{(x,y,0):x,y\in\mathbb{R}\}, the xyxy-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: P(4,−2,5)=(4,−2,0)P(4,-2,5)=(4,-2,0). 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 (0,0,6)(0,0,6), which lies in the kernel because P(0,0,6)=(0,0,0)P(0,0,6)=(0,0,0). By linearity, P(2,1,6)=P((2,1,0)+(0,0,6))=P(2,1,0)+P(0,0,6)=(2,1,0)P(2,1,6)=P((2,1,0)+(0,0,6))=P(2,1,0)+P(0,0,6)=(2,1,0).

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 rank+nullity=dim⁡(V)\text{rank}+\text{nullity}=\dim(V). Substituting gives 2+nullity=32+\text{nullity}=3, so the nullity is 11. 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 (x,y,z)↦(x,y)(x,y,z)\mapsto(x,y) has kernel {(0,0,z):z∈R}\{(0,0,z):z\in\mathbb{R}\}, which is nonzero, and its image is all of R2\mathbb{R}^2 because any (a,b)(a,b) is reached from (a,b,0)(a,b,0). 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 F(x)=Ax+bF(x)=Ax+b, then F(u)−F(v)=(Au+b)−(Av+b)=A(u−v)F(u)-F(v)=(Au+b)-(Av+b)=A(u-v). The bias cancels, so F(u)=F(v)F(u)=F(v) exactly when u−vu-v lies in the kernel of the weight map AA. The set of possible outputs is shifted from Im⁡(A)\operatorname{Im}(A) to b+Im⁡(A)b+\operatorname{Im}(A).

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.

Sources

  1. Mathematics for Machine Learning book PDF, Section 2.7.3
  2. NumPy documentation: numpy.matmul
  3. PyTorch documentation: torch.nn.Linear