AI Wiki中文/EN

Orthogonal projection

正交投影

Find the closest approximation when data can use only one direction, and connect a perpendicular residual to least squares.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

Keep only one direction

Given x=(2,3)⊤x=(2,3)^\top, suppose we can represent it only as a multiple of u=(1,2)⊤u=(1,2)^\top. Candidates include (1,2)⊤(1,2)^\top, (2,4)⊤(2,4)^\top, and points between or beyond them. Which is closest to the original data point xx? The distance being minimized is between the data and its approximation, not between the data and the coordinate origin.

Geometrically, drop a perpendicular from xx onto the line through the coordinate origin. Its foot is the orthogonal projection. Here the result is p=(1.6,3.2)⊤p=(1.6,3.2)^\top, with residual r=(0.4,−0.2)⊤r=(0.4,-0.2)^\top. Checking r⊤u=0r^\top u=0 confirms that the residual is perpendicular to the allowed direction.

Projection retains the part expressible along the direction and discards the perpendicular part. It solves a constrained approximation problem but does not establish that the discarded part is noise. If the task depends on that direction, projection can harm prediction.

Prove closeness without calculus

Let u≠0u\ne0, use Euclidean distance, and represent a candidate as auau. Requiring the residual to be orthogonal to uu gives:

u⊤(x−a∗u)=0⟹a∗=u⊤xu⊤u,p=uu⊤u⊤ux.u^\top(x-a_*u)=0\quad\Longrightarrow\quad a_* = \frac{u^\top x}{u^\top u},\qquad p=\frac{uu^\top}{u^\top u}x.

Finding a perpendicular residual is not yet a proof of optimality. Set r=x−a∗ur=x-a_*u. For any coefficient aa, the cross term vanishes because r⊤u=0r^\top u=0:

∥x−au∥22=∥r+(a∗−a)u∥22=∥r∥22+(a−a∗)2∥u∥22.\|x-au\|_2^2=\|r+(a_*-a)u\|_2^2=\|r\|_2^2+(a-a_*)^2\|u\|_2^2.

The last term is nonnegative and vanishes only at a=a∗a=a_*, proving a unique optimum. In the example, u⊤x=8u^\top x=8 and u⊤u=5u^\top u=5, so the coefficient is 8/58/5. No differentiation is needed for this derivation. MML, Section 3.8

Writing P=uu⊤/(u⊤u)P=uu^\top/(u^\top u) gives P⊤=PP^\top=P and P2=PP^2=P. Symmetry relates to Euclidean orthogonality; idempotence means that projecting an already projected point changes nothing. Idempotence alone is insufficient: an oblique projection can be idempotent without returning the Euclidean closest point.

For a subspace spanned by the linearly independent columns of AA, the least-squares orthogonality condition becomes:

A⊤(x−Ac)=0,c=(A⊤A)−1A⊤x,p=Ac.A^\top(x-Ac)=0,\qquad c=(A^\top A)^{-1}A^\top x,\qquad p=Ac.

This expression assumes full column rank and does not recommend explicitly inverting a matrix in numerical code. Practical solvers commonly use QR or SVD. Dependent columns require handling nonunique coefficients; the pseudoinverse provides a more general expression. Deep Learning, Section 2.9

Check the residual and the distance

This complete program projects onto a one-dimensional subspace. A zero direction cannot define a one-dimensional line and is rejected. The zero subspace itself still has a projection, but representing it requires a different input convention.

import math

def dot(x, y):
    if len(x) != len(y):
        raise ValueError("dimension mismatch")
    return math.fsum(a * b for a, b in zip(x, y))

def project_line(x, u):
    denominator = dot(u, u)
    if denominator == 0:
        raise ValueError("a line needs a nonzero direction")
    coefficient = dot(u, x) / denominator
    return [coefficient * value for value in u]

x, u = [2.0, 3.0], [1.0, 2.0]
p = project_line(x, u)
r = [a - b for a, b in zip(x, p)]
assert all(abs(a - b) < 1e-12 for a, b in zip(p, [1.6, 3.2]))
assert abs(dot(r, u)) < 1e-12
assert abs(dot(x, x) - dot(p, p) - dot(r, r)) < 1e-12
assert all(abs(a - b) < 1e-12 for a, b in zip(project_line(p, u), p))
for a in [-2, 0, 1, 1.6, 2, 4]:
    error = [v - a * direction for v, direction in zip(x, u)]
    assert dot(error, error) >= dot(r, r) - 1e-12

For vectors of length dd, line projection takes O(d)O(d) time and O(d)O(d) output space without constructing a d×dd\times d matrix. The final trial coefficients check the implementation. Optimality over the continuous range follows from the square expansion above.

Lines, affine sets, and numerical error

The line in this article passes through the coordinate origin. For an affine set b+aub+au, first shift the input to x−bx-b, project it, and add bb back. Omitting that offset solves a different problem.

“Closest” also depends on the distance. Reweighting coordinates or using L1 distance can change the optimum. The Euclidean orthogonal-projection proof cannot simply be transferred to every loss function.

When AA contains nearly parallel directions, coefficients can be sensitive to small perturbations, and forming A⊤AA^\top A worsens conditioning. Numerical stability matters even when the expression exists algebraically. A residual being orthogonal to the retained subspace also does not establish statistical independence.

Change the direction and constraint

  1. Does replacing uu with (−3,−6)⊤(-3,-6)^\top change the projection point? Answer: no; it spans the same line, although the coefficient changes.
  2. Project (2,3)⊤(2,3)^\top onto the horizontal axis. Answer: (2,0)⊤(2,0)^\top, with residual (0,3)⊤(0,3)^\top.
  3. Project onto the affine line (1,0)⊤+a(0,1)⊤(1,0)^\top+a(0,1)^\top. Answer: (1,3)⊤(1,3)^\top. Subtract the anchor point before projecting.
  4. Is [1100]\begin{bmatrix}1&1\\0&0\end{bmatrix} an orthogonal projection matrix? Answer: no. It is idempotent but not symmetric. For example, it sends (0,1)⊤(0,1)^\top to (1,0)⊤(1,0)^\top, although the closest horizontal-axis point is (0,0)⊤(0,0)^\top.

The shared structure of least squares and dimension reduction

Linear regression restricts predictions to the design matrix’s column space, producing the least-squares orthogonality condition. PCA additionally selects a retained subspace from data. Projecting onto a given subspace and choosing the subspace are different steps. Separating them clarifies what dimension reduction optimizes and why preserving variance need not preserve task-relevant information.

Make a prediction, then check

Replace a line direction u with -3u. What happens to its orthogonal projection point?

Choose one answer

Learning objectives

  • Prove optimality of Euclidean line projection without calculus.
  • Distinguish orthogonal projection, oblique projection, and affine sets.

Prerequisites & connections

Explore related knowledge →

References

  1. Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft)
    Marc Peter Deisenroth; A. Aldo Faisal; Cheng Soon Ong · 2020
  2. 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 unique optimal coefficient by expanding a square; recomputed 8/5, projection (1.6,3.2), and the perpendicular residual.
  • Checked the idempotent nonsymmetric counterexample, affine translation, and full-column-rank assumption; distinguished an inverse formula from numerical-solver advice.
  • 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

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.