Linear transformations
线性变换
Why does knowing where basis vectors go determine every output? Understand superposition, information loss, and affine layers.
linear-transformationsMix first or process first?
Add two audio signals and pass them through an ideal fixed-gain amplifier. If processing the signals separately and adding afterward gives the same result, the amplifier preserves superposition. Saturation or clipping in a real device can break that property. This example separates a mathematical model from device behavior; it does not assume that every amplifier is linear.
A linear transformation preserves vector addition and scaling. Rotations, reflections through the origin, and some dimension-reduction operations can be linear. “Linear” does not mean merely moving a shape along a straight line, or independently scaling each coordinate. An output coordinate can combine many input coordinates.
One definition determines a matrix
A transformation between real vector spaces is linear if, for every input pair and every real ,
Setting both coefficients to zero gives . The converse fails: the one-dimensional function sends zero to zero but does not preserve addition. MML, Section 2.7
In , let be the standard basis vector with a 1 in coordinate and zeros elsewhere. Every input is a combination of these directions, so:
Column of the matrix is the image of basis vector . With input coordinates and output coordinates, the matrix is . Here the matrix represents a linear map in fixed coordinate systems, not just an arbitrary table of data. Deep Learning, Section 2.2
Consider . It maps to and maps to the same point. Their difference, , maps to zero. All inputs mapped to zero form the kernel; all possible outputs form the image. Outputs here vary only along the horizontal axis, so the transformation loses a direction of information and cannot be uniquely reversed.
Adding a fixed offset gives an affine transformation, . When , violates the strict linear definition. Composing two affine maps produces another affine map:
Thus a chain of affine layers without nonlinear activations can be combined into one affine map. A narrow intermediate layer can still constrain rank, and parameterization can affect optimization. The identity does not establish that such factorizations are useless in every task.
Reconstruct a map from basis vectors
This complete Python example checks matrix columns, superposition, and a direction in which information disappears. Inputs are rectangular matrices and compatible finite vectors.
def apply(a, x):
if any(len(row) != len(x) for row in a):
raise ValueError("dimension mismatch")
return [sum(v * w for v, w in zip(row, x)) for row in a]
def combine(a, x, b, y):
if len(x) != len(y):
raise ValueError("dimension mismatch")
return [a * u + b * v for u, v in zip(x, y)]
a = [[1, 1], [0, 0]]
x, y = [2, 3], [-1, 4]
assert apply(a, [1, 0]) == [1, 0]
assert apply(a, [0, 1]) == [1, 0]
assert apply(a, combine(2, x, -3, y)) == combine(2, apply(a, x), -3, apply(a, y))
assert apply(a, [1, -1]) == [0, 0]
square = lambda z: z * z
assert square(1 + 1) != square(1) + square(1)
Applying a general dense matrix takes time and output space. Structure can reduce the work: diagonal maps scale coordinates individually, and sparse maps mainly process nonzero entries. Some operators can be applied as functions without materializing a dense matrix at all.
Tests can refute, but a few examples cannot prove
For an unknown program, finding refutes linearity. Passing a few inputs does not prove linearity everywhere; the program may contain untested branches. For a known matrix map, the proof is algebraic, while numerical tests help catch implementation mistakes.
Exact mathematics and floating-point approximation also differ. Reordering additions may cause small numerical discrepancies, so bitwise equality is not an appropriate general test of a numerical implementation’s linear model. An excessively loose tolerance can conversely hide real nonlinearity.
A pipeline with clipping, thresholds, or input-dependent weights can contain linear steps without being linear overall. Clipping a matrix output to nonnegative values generally breaks superposition. Analyze the complete computational path.
Track directions and information
- Why are the images of the standard basis enough? Answer: every input is a linear combination of that basis, and linearity uses the same coefficients to combine the outputs.
- Is a one-dimensional linear transformation? Answer: it is affine, not strictly linear, because .
- Can the example matrix recover the two input entries separately? Answer: no. It retains only their sum, so infinitely many inputs produce the same output.
- Why is checking only insufficient? Answer: squaring passes that check, while inputs 1 and 1 already provide a counterexample to additivity.
Where does additional expressive power come from?
Linear models, convolution operators, principal component analysis, and local Jacobian analysis rely on linear mappings. Neural networks combine affine maps with nonlinearities to obtain functions that cannot simply collapse into one matrix. Rank, kernels, and singular values describe which input directions survive, which are compressed, and how strongly small perturbations are amplified.
Make a prediction, then check
Does observing T(0)=0 prove that T is linear?
Learning objectives
- Construct a linear-map matrix from images of the standard basis.
- Identify affine offsets, information lost in the kernel, and nonlinear counterexamples.
Prerequisites & connections
Explore related knowledge →References
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft)
Marc Peter Deisenroth; A. Aldo Faisal; Cheng Soon Ong · 2020 - Deep Learning — Chapter 2: Linear Algebra
Ian Goodfellow; Yoshua Bengio; Aaron Courville · 2016
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-05 · Codex technical check: cited-source comparison, re-derivation and recalculation, bilingual argument comparison, and executed Python assertions; no independent human peer review.
- Rederived the matrix-column representation from the standard basis and checked affine composition.
- Recomputed kernel direction (1,−1) and the squaring counterexample; finite tests are not claimed to prove arbitrary functions linear.
- Compared the main arguments, numerical examples, exercises, and answers across languages; structural checks additionally compare display equations, source lists, and code.
- Reviewed the answer-label rendering fix: only Markdown emphasis markers changed to strong tags; normalized text and all code are identical.
Source locations checked:
Related topics