Unit 11, lesson 53

Linear Algebra Review with Fitting and Reconstruction

How to tell an overdetermined fit from an underdetermined reconstruction, check residuals, choose the minimum-norm reconstruction, judge an added measurement, and separate agreement with data from a validated model.

  • Video 53
  • Fitting and Reconstruction

Three measured points refuse to lie on one straight line. In a second experiment, three hidden inputs can change while two measured totals stay exactly the same. Both problems have the form Ax=bA\mathbf{x} = \mathbf{b}, yet the first has no exact solution and the second has infinitely many, so they call for different methods and different defenses. This review classifies such problems by rank and compatibility, solves each one under a stated criterion, checks the answer in the original problem, and asks what the result does and does not say about the hidden truth.

Key terms

Overdetermined system

Definition A linear system Ax=bA\mathbf{x} = \mathbf{b} with a real m×nm \times n matrix AA is overdetermined when it has more equations than unknowns, m>nm > n. The count alone decides neither existence nor uniqueness. The system has an exact solution exactly when b\mathbf{b} lies in Col⁡A\operatorname{Col} A, a subspace of dimension at most n<mn < m, which data with measurement errors usually miss. When there is no exact solution, ordinary least squares minimizes ∥b−Ax∥\lVert \mathbf{b} - A\mathbf{x} \rVert over all x\mathbf{x} in Rn\mathbb{R}^n. The minimizers always exist, and they are exactly the solutions of the normal equations

A⊤Ax^=A⊤b.A^{\top}A\hat{\mathbf{x}} = A^{\top}\mathbf{b}.

The minimizer is unique exactly when the columns of AA are independent, that is when rank⁡A=n\operatorname{rank} A = n. A QR factorization or an SVD solves the same problem without forming A⊤AA^{\top}A, and that is the safer route in floating-point arithmetic. When rank⁡A=n\operatorname{rank} A = n, the invertible matrix A⊤AA^{\top}A has condition number σ12/σn2\sigma_1^2/\sigma_n^2, where σ1\sigma_1 and σn\sigma_n are the largest and smallest singular values of AA, so forming it squares the ratio σ1/σn\sigma_1/\sigma_n of AA itself.

In plain words More equations than unknowns means more demands than adjustable numbers. When the demands conflict, a fit stops trying to meet each one exactly and makes the vector of misses as short as possible instead.

Example Tuples such as (1,2,4)(1, 2, 4) stand for column vectors on this page, except for data points written (ti,yi)(t_i, y_i). Fit the line y=a+bty = a + bt to the points (0,1)(0, 1), (1,2)(1, 2) and (2,4)(2, 4). The unknowns are c=(a,b)\mathbf{c} = (a, b), and the system Xc=yX\mathbf{c} = \mathbf{y} has

X=[101112],y=[124].X = \begin{bmatrix} 1 & 0 \\ 1 & 1 \\ 1 & 2 \end{bmatrix}, \qquad \mathbf{y} = \begin{bmatrix} 1 \\ 2 \\ 4 \end{bmatrix}.

The first two points force a=1a = 1 and b=1b = 1, and that line predicts 33 at t=2t = 2, not 44, so no exact fit exists. The normal equations are

[3335][ab]=[710].\begin{bmatrix} 3 & 3 \\ 3 & 5 \end{bmatrix} \begin{bmatrix} a \\ b \end{bmatrix} = \begin{bmatrix} 7 \\ 10 \end{bmatrix}.

Subtracting the first equation from the second gives 2b=32b = 3, so b=32b = \tfrac{3}{2}, and then 3a=7−92=523a = 7 - \tfrac{9}{2} = \tfrac{5}{2} gives a=56a = \tfrac{5}{6}. The columns of XX are independent, since α(1,1,1)+β(0,1,2)=0\alpha(1, 1, 1) + \beta(0, 1, 2) = \mathbf{0} forces α=0\alpha = 0 from the first entry and then β=0\beta = 0, so this least-squares line is the only one.

Underdetermined system

Definition A linear system Ax=bA\mathbf{x} = \mathbf{b} with a real m×nm \times n matrix AA is underdetermined when it has fewer equations than unknowns, m<nm < n. Then

dim⁡Null⁡A=n−rank⁡A≥n−m>0,\begin{aligned} \dim \operatorname{Null} A &= n - \operatorname{rank} A \\[0.4em] &\ge n - m > 0, \end{aligned}

so the null space contains nonzero vectors. The system can still have no solution, when b\mathbf{b} is not in Col⁡A\operatorname{Col} A. If it has a solution xp\mathbf{x}_p, it has infinitely many, and they are exactly the vectors xp+z\mathbf{x}_p + \mathbf{z} with z\mathbf{z} in Null⁡A\operatorname{Null} A. Every one of them reproduces b\mathbf{b} exactly, so the data alone cannot tell them apart.

In plain words Fewer measurements than unknowns leave some input directions unseen. Moving the input along such a direction changes nothing that was measured.

Example Two totals of three inputs are measured, x1+x3=4x_1 + x_3 = 4 and x2+x3=3x_2 + x_3 = 3, so

A=[101011],b=[43].A = \begin{bmatrix} 1 & 0 & 1 \\ 0 & 1 & 1 \end{bmatrix}, \qquad \mathbf{b} = \begin{bmatrix} 4 \\ 3 \end{bmatrix}.

With x3=tx_3 = t free, every solution is

x=[4−t3−tt]=[430]+t[−1−11],\mathbf{x} = \begin{bmatrix} 4 - t \\ 3 - t \\ t \end{bmatrix} = \begin{bmatrix} 4 \\ 3 \\ 0 \end{bmatrix} + t\begin{bmatrix} -1 \\ -1 \\ 1 \end{bmatrix},

and Null⁡A\operatorname{Null} A is the line spanned by (−1,−1,1)(-1, -1, 1). The rank is 22, so every b\mathbf{b} in R2\mathbb{R}^2 is reachable. There is nothing to fit here, only a choice to make.

Residual check

Definition The residual of a candidate x^\hat{\mathbf{x}} for Ax=bA\mathbf{x} = \mathbf{b} is r=b−Ax^\mathbf{r} = \mathbf{b} - A\hat{\mathbf{x}}, computed from the original data and in the units of the measurements. A residual check recomputes r\mathbf{r} and tests the property the method promises. An exact solution needs r=0\mathbf{r} = \mathbf{0}. A least-squares solution needs

A⊤r=0,A^{\top}\mathbf{r} = \mathbf{0},

one dot product with each column of AA, which is the normal equations in another form. This test certifies the minimum, because when it holds, every x\mathbf{x} in Rn\mathbb{R}^n satisfies

∥b−Ax∥2=∥r∥2+∥A(x^−x)∥2.\lVert \mathbf{b} - A\mathbf{x} \rVert^2 = \lVert \mathbf{r} \rVert^2 + \lVert A(\hat{\mathbf{x}} - \mathbf{x}) \rVert^2.

The check ends with the null space. In both cases the solutions are exactly the vectors x^+z\hat{\mathbf{x}} + \mathbf{z} with z\mathbf{z} in Null⁡A\operatorname{Null} A, so the answer is unique exactly when Null⁡A={0}\operatorname{Null} A = \{\mathbf{0}\}.

In plain words Put the answer back into the problem that was asked. For a fit, the misses must be perpendicular to every change in prediction the model can make, otherwise some change would shrink them.

Example For the line with a=56a = \tfrac{5}{6} and b=32b = \tfrac{3}{2}, the predictions are (56,73,236)(\tfrac{5}{6}, \tfrac{7}{3}, \tfrac{23}{6}) and

r=y−Xc=[1/6−1/31/6].\mathbf{r} = \mathbf{y} - X\mathbf{c} = \begin{bmatrix} 1/6 \\ -1/3 \\ 1/6 \end{bmatrix}.

Its entries add to 16−13+16=0\tfrac{1}{6} - \tfrac{1}{3} + \tfrac{1}{6} = 0, and weighted by the inputs they give 0⋅16+1⋅(−13)+2⋅16=00 \cdot \tfrac{1}{6} + 1 \cdot (-\tfrac{1}{3}) + 2 \cdot \tfrac{1}{6} = 0, so X⊤r=0X^{\top}\mathbf{r} = \mathbf{0}. The squared error is 136+19+136=16\tfrac{1}{36} + \tfrac{1}{9} + \tfrac{1}{36} = \tfrac{1}{6}. This perpendicularity holds in the three-dimensional space of observations. In the scatter plot the residuals are vertical gaps at fixed inputs, and they need not meet the line at right angles.

Minimum-norm reconstruction

Definition Let Ax=bA\mathbf{x} = \mathbf{b} be consistent, with AA a real m×nm \times n matrix. Among all its solutions exactly one has the smallest Euclidean norm. It is called the minimum-norm reconstruction and written x+\mathbf{x}^{+}. It is the only solution that lies in Row⁡A\operatorname{Row} A, which means it is orthogonal to every vector of Null⁡A\operatorname{Null} A, and it equals A+bA^{+}\mathbf{b}, where A+A^{+} is the pseudoinverse. Every other solution is x++z\mathbf{x}^{+} + \mathbf{z} with a nonzero z\mathbf{z} in Null⁡A\operatorname{Null} A, and

∥x++z∥2=∥x+∥2+∥z∥2.\lVert \mathbf{x}^{+} + \mathbf{z} \rVert^2 = \lVert \mathbf{x}^{+} \rVert^2 + \lVert \mathbf{z} \rVert^2.

When AA has full row rank, rank⁡A=m\operatorname{rank} A = m, the pseudoinverse is A+=A⊤(AA⊤)−1A^{+} = A^{\top}(AA^{\top})^{-1}. For inconsistent data, A+bA^{+}\mathbf{b} is the least-squares solution of smallest norm. Length is measured in the given coordinates, so a change of units for the inputs can change which solution is shortest.

In plain words When the data leave a whole family of exact answers, pick the shortest one. It has no component in the unseen directions, so it adds nothing the measurements did not ask for. It is a stated choice, not a discovery of the hidden input.

Example For the two totals above,

AA⊤=[2112],A+=13[2−1−1211],\begin{aligned} AA^{\top} &= \begin{bmatrix} 2 & 1 \\ 1 & 2 \end{bmatrix}, \\[0.4em] A^{+} &= \frac{1}{3}\begin{bmatrix} 2 & -1 \\ -1 & 2 \\ 1 & 1 \end{bmatrix}, \end{aligned}

so x+=A+(4,3)=(53,23,73)\mathbf{x}^{+} = A^{+}(4, 3) = (\tfrac{5}{3}, \tfrac{2}{3}, \tfrac{7}{3}), the member of the family with t=73t = \tfrac{7}{3}. Both measurements hold, since 53+73=4\tfrac{5}{3} + \tfrac{7}{3} = 4 and 23+73=3\tfrac{2}{3} + \tfrac{7}{3} = 3, and the kernel test gives −53−23+73=0-\tfrac{5}{3} - \tfrac{2}{3} + \tfrac{7}{3} = 0. The squared norm is 263\tfrac{26}{3}, and adding α(−1,−1,1)\alpha(-1, -1, 1) changes it to 263+3α2\tfrac{26}{3} + 3\alpha^2, which is larger whenever α≠0\alpha \ne 0. The data say nothing about the kernel component, so the hidden input could just as well be (4,3,0)(4, 3, 0) or (2,1,2)(2, 1, 2).

Effect of an added measurement

Definition Suppose Ax=bA\mathbf{x} = \mathbf{b} is consistent and a new exact measurement a⊤x=β\mathbf{a}^{\top}\mathbf{x} = \beta arrives, with a\mathbf{a} a nonzero vector in Rn\mathbb{R}^n. The new system appends the row a⊤\mathbf{a}^{\top} to AA and the entry β\beta to b\mathbf{b}, and its solutions are the old solutions that also satisfy the new equation. If a\mathbf{a} is not in Row⁡A\operatorname{Row} A, then a\mathbf{a} is not orthogonal to Null⁡A\operatorname{Null} A, the rank rises by one, the nullity drops by one, and the new system is still consistent. If a\mathbf{a} is in Row⁡A\operatorname{Row} A, say a=A⊤w\mathbf{a} = A^{\top}\mathbf{w}, then every old solution has a⊤x=w⊤Ax=w⊤b\mathbf{a}^{\top}\mathbf{x} = \mathbf{w}^{\top}A\mathbf{x} = \mathbf{w}^{\top}\mathbf{b}. The measurement is then redundant when β=w⊤b\beta = \mathbf{w}^{\top}\mathbf{b}, and when β≠w⊤b\beta \ne \mathbf{w}^{\top}\mathbf{b} it contradicts the old data and the combined system has no exact solution. Any answer chosen for the old problem, the minimum-norm one included, must be checked against the new equation and recomputed if it fails. If the new measurement is uncertain rather than exact, imposing it as an equation is itself a modeling choice, and a fit with stated weights is one alternative.

In plain words A new exact measurement can only remove possibilities. It removes freedom only when it looks along a direction the old measurements could not see. A measurement that repeats old information either agrees with it or exposes a conflict.

Example Add the exact measurement x3=2x_3 = 2 to the two totals. Its vector a=(0,0,1)\mathbf{a} = (0, 0, 1) has dot product 11 with the kernel direction (−1,−1,1)(-1, -1, 1), so it sees the missing direction. In the family it sets t=2t = 2, and the only solution left is (2,1,2)(2, 1, 2). The new matrix

[101011001]\begin{bmatrix} 1 & 0 & 1 \\ 0 & 1 & 1 \\ 0 & 0 & 1 \end{bmatrix}

is upper triangular with ones on the diagonal, hence invertible. The old answer (53,23,73)(\tfrac{5}{3}, \tfrac{2}{3}, \tfrac{7}{3}) has x3=73x_3 = \tfrac{7}{3}, so it is not even a solution of the new problem. By contrast, a measurement x1−x2=1x_1 - x_2 = 1 would add nothing, because its row is row 1 minus row 2 of AA and 4−3=14 - 3 = 1, while a reading x1−x2=2x_1 - x_2 = 2 would contradict the two totals.

Agreement with data versus a validated model

Definition A model agrees with the data when its residual on the observations used to build it is zero or small under the stated error criterion. A model is validated only when further evidence supports it. Its predictions match observations that were not used to fit it, within their measurement uncertainty and over the range where the model will be used, and its assumptions are justified, such as which inputs are fixed, which measurements are exact, the weights and the units. Agreement is one part of evaluating a model and is never sufficient on its own. If the design matrix is square and invertible, as when a polynomial of degree m−1m - 1 is fitted to mm points with distinct inputs, the residual is zero for any data. Every member of an underdetermined solution family reproduces the data exactly. A small residual can also come with a large error in the solution when AA shrinks some input direction strongly.

In plain words A good fit to the points you have is evidence about those points. Whether the model describes the process behind them is a separate question, answered by new data and by checking assumptions, not by a smaller residual.

Example The quadratic y=1+12t+12t2y = 1 + \tfrac{1}{2}t + \tfrac{1}{2}t^2 passes exactly through (0,1)(0, 1), (1,2)(1, 2) and (2,4)(2, 4), so its residual is 0\mathbf{0}, while the least-squares line has squared error 16\tfrac{1}{6}. That alone does not make the quadratic the better model, since three coefficients can match any three readings at distinct inputs. At t=3t = 3 the quadratic predicts 77 and the line predicts 56+92=163\tfrac{5}{6} + \tfrac{9}{2} = \tfrac{16}{3}. Only new measurements, such as one at t=3t = 3, or knowledge of the process that produced the data, can decide between them.

Check yourself

  1. Count equations and unknowns in each system, then decide whether it has no solution, exactly one or infinitely many. The first system is x+y=2x + y = 2, 2x+2y=42x + 2y = 4, x−y=0x - y = 0, and the second is x+y+z=1x + y + z = 1, 2x+2y+2z=32x + 2y + 2z = 3.
Show the answer

The first system has three equations in two unknowns, so it is overdetermined, yet it has exactly one solution. The second equation is twice the first, and the first and third give x=y=1x = y = 1, which satisfies all three. The coefficient rows (1,1)(1, 1) and (1,−1)(1, -1) are independent, so the rank is 22 and the solution is unique. The second system has two equations in three unknowns, so it is underdetermined, yet it has no solution, because twice the first equation reads 2x+2y+2z=22x + 2y + 2z = 2, not 33. Counting alone decides neither question. The rank and the right-hand side decide both.

  1. Fit y=a+bty = a + bt by least squares to the points (0,3)(0, 3), (1,1)(1, 1) and (2,2)(2, 2). Check the residual and say whether the coefficients are unique. Someone proposes the line y=3−ty = 3 - t instead, because it passes through the first point and its residuals add to zero. Does it pass the residual check?
Show the answer

The inputs are the same as in the examples, so X⊤XX^{\top}X is unchanged, and X⊤y=(3+1+2,0+1+4)=(6,5)X^{\top}\mathbf{y} = (3 + 1 + 2, 0 + 1 + 4) = (6, 5). The normal equations are

3a+3b=6,3a+5b=5.\begin{aligned} 3a + 3b &= 6, \\[0.4em] 3a + 5b &= 5. \end{aligned}

Subtracting gives 2b=−12b = -1, so b=−12b = -\tfrac{1}{2} and a=52a = \tfrac{5}{2}. The predictions are (52,2,32)(\tfrac{5}{2}, 2, \tfrac{3}{2}) and the residual is r=(12,−1,12)\mathbf{r} = (\tfrac{1}{2}, -1, \tfrac{1}{2}). Its entries add to 00 and its input-weighted sum is 0−1+1=00 - 1 + 1 = 0, so X⊤r=0X^{\top}\mathbf{r} = \mathbf{0}. The squared error is 14+1+14=32\tfrac{1}{4} + 1 + \tfrac{1}{4} = \tfrac{3}{2}, and the coefficients are unique because the columns of XX are independent. For y=3−ty = 3 - t the predictions are (3,2,1)(3, 2, 1) and the residual is (0,−1,1)(0, -1, 1). Its entries do add to 00, but its input-weighted sum is −1+2=1≠0-1 + 2 = 1 \ne 0, so it fails the check, and its squared error 22 is larger than 32\tfrac{3}{2}. A zero sum tests only the first column of XX, and the least-squares residual must be orthogonal to every column.

  1. Three survey markers have unknown heights x1,x2,x3x_1, x_2, x_3, and only differences are measured, x1−x2=1x_1 - x_2 = 1 and x2−x3=1x_2 - x_3 = 1. Find all solutions and the minimum-norm one, and verify it. Then decide what each of the extra exact measurements x1+x2+x3=3x_1 + x_2 + x_3 = 3 and x1−x3=2x_1 - x_3 = 2 would do.
Show the answer

With x3=tx_3 = t, the measurements give x2=1+tx_2 = 1 + t and x1=2+tx_1 = 2 + t, so

x=[210]+t[111],\mathbf{x} = \begin{bmatrix} 2 \\ 1 \\ 0 \end{bmatrix} + t\begin{bmatrix} 1 \\ 1 \\ 1 \end{bmatrix},

and the null space is spanned by (1,1,1)(1, 1, 1). Orthogonality to it requires (2+t)+(1+t)+t=3+3t=0(2 + t) + (1 + t) + t = 3 + 3t = 0, so t=−1t = -1 and x+=(1,0,−1)\mathbf{x}^{+} = (1, 0, -1). Check the measurements, 1−0=11 - 0 = 1 and 0−(−1)=10 - (-1) = 1, and the kernel, 1+0−1=01 + 0 - 1 = 0. The squared norm is 22, and adding α(1,1,1)\alpha(1, 1, 1) gives 2+3α22 + 3\alpha^2, so this solution is the unique shortest one. It sets the average height to zero, which is a convention. Differences cannot reveal the overall level, and true heights such as (102,101,100)(102, 101, 100) give the same data.

The measurement x1+x2+x3=3x_1 + x_2 + x_3 = 3 has vector (1,1,1)(1, 1, 1), exactly the unseen direction. In the family it gives 3+3t=33 + 3t = 3, so t=0t = 0 and the heights are uniquely (2,1,0)(2, 1, 0). The old answer has height sum 00 and fails the new measurement, so it must be replaced. The measurement x1−x3=2x_1 - x_3 = 2 has vector (1,0,−1)(1, 0, -1), which is row 1 plus row 2, and 1+1=21 + 1 = 2. Every old solution already satisfies it, so nothing changes. A reading x1−x3=3x_1 - x_3 = 3 would instead contradict the first two measurements.

How this lesson connects