AI Wiki中文/EN

The pseudoinverse

伪逆

Solve inconsistent and underdetermined systems through minimum-norm least squares, with exact rank-one examples and numerical cutoffs.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

When inversion cannot answer the question

Suppose two measurements are modeled by x1+x2≈3x_1+x_2\approx3 and 2x1+2x2≈52x_1+2x_2\approx5. The equations conflict: doubling the first target would give six, not five. They also cannot distinguish the two unknowns individually. Ordinary inversion fails because A=[1122]A=\begin{bmatrix}1&1\\2&2\end{bmatrix} is singular.

The Moore–Penrose pseudoinverse makes the desired compromise precise. First minimize the Euclidean residual ∥Ax−b∥2\|Ax-b\|_2; among all minimizers, choose the one with smallest Euclidean norm. Here it gives x1=x2=1.3x_1=x_2=1.3, predictions (2.6,5.2)(2.6,5.2), and squared residual 0.20.2. These are statements about the chosen squared-error geometry, not proof that 1.3 is the physically true value of each unknown. Deep Learning, Section 2.9

A unique matrix defined by four identities

For a real m×n matrix AA, its pseudoinverse A+A^+ is n×m and uniquely satisfies

AA+A=A,A+AA+=A+,(AA+)⊤=AA+,(A+A)⊤=A+A.AA^+A=A,\qquad A^+AA^+=A^+,\qquad (AA^+)^\top=AA^+,\qquad (A^+A)^\top=A^+A.

These are the Moore–Penrose conditions. Every finite real matrix has such a pseudoinverse, including rectangular and zero matrices. If an ordinary inverse exists, the two coincide. For complex matrices, transpose becomes conjugate transpose. SciPy pinv, mathematical conditions

Using the compact rank-r SVD with positive singular values,

A=UrΣrVr⊤,A+=VrΣr−1Ur⊤=∑i=1r1σiviui⊤.A=U_r\Sigma_rV_r^\top,\qquad A^+=V_r\Sigma_r^{-1}U_r^\top=\sum_{i=1}^{r}\frac{1}{\sigma_i}v_i u_i^\top.

The formula inverts only directions that the original map preserves. In a full-factor representation, zero singular values remain zero in Σ+\Sigma^+ rather than being divided into one. The zero matrix’s pseudoinverse is the transposed-shape zero matrix.

To see why x∗=A+bx^*=A^+b solves the stated problem, express bb in the orthonormal output coordinates. For each positive singular direction, choose input coordinate (ui⊤b)/σi(u_i^\top b)/\sigma_i. Components of bb outside the column space cannot be matched and remain in the residual. Input null-space components do not change that residual, so setting them to zero minimizes the solution norm. Thus the least-squares solution can be nonunique, while the minimum-norm one is unique.

The products AA+AA^+ and A+AA^+A are orthogonal projectors onto the column space and row space respectively. They are not generally identity matrices. For full column rank, A+=(A⊤A)−1A⊤A^+=(A^\top A)^{-1}A^\top; for full row rank, A+=A⊤(AA⊤)−1A^+=A^\top(AA^\top)^{-1}. Their rank assumptions are essential, and these algebraic expressions are not a recommendation to form normal equations numerically.

An exact singular example

For nonzero vectors u,vu,v with A=uv⊤A=uv^\top, the only positive singular value is ∥u∥2∥v∥2\|u\|_2\|v\|_2. Substitution into the SVD formula gives

(uv⊤)+=vu⊤(u⊤u)(v⊤v).(uv^\top)^+=\frac{vu^\top}{(u^\top u)(v^\top v)}.

This standard-library example evaluates that rank-one formula exactly using rational arithmetic and checks all four identities. It also handles a zero factor. It is a complete program for this restricted family, not a general pinv implementation; the matrix helpers assume the compatible shapes used below.

from fractions import Fraction

def rank_one_pinv(u, v):
    if not u or not v or any(not isinstance(x,(int,Fraction)) for x in [*u,*v]):
        raise ValueError("nonempty integer or Fraction vectors required")
    u,v = list(map(Fraction,u)),list(map(Fraction,v))
    a = [[x*y for y in v] for x in u]
    denominator = sum(x*x for x in u)*sum(y*y for y in v)
    b = [[y*x/denominator if denominator else Fraction(0) for x in u] for y in v]
    return a,b

def matmul(a,b):
    return [[sum(x*y for x,y in zip(row,col)) for col in zip(*b)] for row in a]

def transpose(a):
    return [list(row) for row in zip(*a)]

a,b = rank_one_pinv([1,2],[1,1])
assert b == [[Fraction(1,10),Fraction(1,5)]]*2
assert matmul(matmul(a,b),a) == a
assert matmul(matmul(b,a),b) == b
assert transpose(matmul(a,b)) == matmul(a,b)
assert transpose(matmul(b,a)) == matmul(b,a)
solution = matmul(b,[[3],[5]])
assert solution == [[Fraction(13,10)],[Fraction(13,10)]]
residual = [[p[0]-y] for p,y in zip(matmul(a,solution),[3,5])]
assert sum(row[0]**2 for row in residual) == Fraction(1,5)
assert matmul(transpose(a),residual) == [[0],[0]]
assert rank_one_pinv([0,0],[1,2,3])[1] == [[0,0],[0,0],[0,0]]
# The general solver is SVD-based; this function covers rank at most one only.

Constructing the two matrices requires O(mn)O(mn) rational operations and storage, plus the vector norm sums. The verification multiplications add work; rational bit lengths also affect actual runtime. A general algorithm uses SVD and a specified policy for deciding which singular values count as nonzero.

Tiny singular values magnify noise

For A=diag⁡(1,10−8)A=\operatorname{diag}(1,10^{-8}) and b=(1,10−4)b=(1,10^{-4}), the exact inverse gives x=(1,104)x=(1,10^4). A small second measurement produced a large coefficient because its direction was divided by 10−810^{-8}. Existence and uniqueness do not guarantee a useful numerical or statistical estimate.

Truncated SVD discards sufficiently small singular directions. Ridge regularization instead replaces the reciprocal factor with σi/(σi2+λ)\sigma_i/(\sigma_i^2+\lambda) for λ>0\lambda>0. Both alter the solution; report the threshold or regularization parameter and evaluate its effect. A truncated numerical pseudoinverse is the exact pseudoinverse of the correspondingly truncated matrix, and need not satisfy AA+A=AAA^+A=A exactly for the original matrix. SciPy documents an absolute-plus-relative cutoff tied to the largest singular value. SciPy threshold definition

Minimum norm also depends on units. Rescaling an input coordinate changes which coefficient vector has the smallest norm. The pseudoinverse resolves an algebraic ambiguity through a metric; it does not establish identifiability from missing information.

Separate fit from solution norm

  1. For A=[1  1]A=[1\;1] and target two, what is the minimum-norm exact solution? Answer: (1,1)(1,1); (0,2)(0,2) also fits, but has larger norm.
  2. In the opening example, would (2.3,0.3)(2.3,0.3) fit equally well? Answer: yes, its sum is still 2.6, but it has larger norm than (1.3,1.3)(1.3,1.3).
  3. Is AA+AA^+ always identity? Answer: no; it projects onto the column space and leaves out unmatched output directions.
  4. What happens to the tiny-direction example if that singular direction is truncated? Answer: the solution becomes (1,0)(1,0), sacrificing the second measurement’s fit to avoid its amplification.

What the algebra leaves to the modeler

Least squares, rank-deficient regression, and inverse problems repeatedly use this construction. The SVD article explains the retained directions; orthogonal projection explains the fitted output. Regularization and validation decide whether fitting those directions is helpful. Keep the mathematical solution, numerical implementation, and empirical generalization claim separate.

Make a prediction, then check

Which solution of x₁+x₂=2 has minimum Euclidean norm?

Choose one answer

Learning objectives

  • Construct the pseudoinverse using SVD and verify the four Moore–Penrose conditions.
  • Distinguish minimum residual, minimum norm, and changes caused by numerical truncation.

Prerequisites & connections

Explore related knowledge →

References

  1. Deep Learning — Chapter 2: Linear Algebra
    Ian Goodfellow; Yoshua Bengio; Aaron Courville · 2016
  2. SciPy — scipy.linalg.pinv
    SciPy developers

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-05 · Codex technical check: cited-source comparison, derivation and numerical checks, bilingual argument comparison, and executed Python assertions; no independent human peer review.

  • Exactly checked all four conditions, residual orthogonality and applicable null-space norm comparisons for 100 rational rank-at-most-one inputs.
  • Recomputed (1.3,1.3), predictions (2.6,5.2) and squared residual 0.2; a truncated pseudoinverse is not presented as the original matrix’s exact inverse.
  • Compared claims, assumptions, examples, exercises and citations across languages; structural validation additionally compares display equations, code and source lists.

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.