Skip to the lesson
FixTheRobot Explore Robotics / Linear Algebra / M5 Least Squares and Numerical Methods / M5-T7

Linear Algebra · Theory · M5

M5-T7 — Regularized Least Squares

When data cannot pin the unknowns down, a gentle preference for small answers turns an unstable problem into a stable one.

  • Lesson 7 of 8
  • Module 5: Least Squares and Numerical Methods
  • Least squares
  • About 8 minutes to read

Ill-posed problems are common in robotics: parameters that the data barely distinguish, Jacobians near a singularity, calibrations with almost redundant terms. Regularisation adds a small penalty on the size of the answer. The fit becomes unique and stable, and you can measure what it costs. The same idea, under the name damping, makes inverse kinematics usable near singular poses (Module 8).

Learning objectives

After this lesson, you should be able to:

  • Define ridge (Tikhonov) regularisation: minimise ‖Ax − b‖² + λ‖x‖² and derive (AᵀA + λI) x = Aᵀb.
  • Show that AᵀA + λI is always invertible for λ > 0 and describe the limits λ → 0 and λ → ∞.
  • Explain the bias-stability trade-off with a concrete example.
  • Recognise Levenberg-Marquardt damping and damped least-squares inverse kinematics as regularisation.

Introduction and motivation

Sometimes the data nearly fail to determine the unknowns. Two calibration parameters whose effects are almost identical, or a manipulator at a nearly singular pose: the exact answer exists but changes wildly with tiny changes in the data. Insisting on it means amplifying noise into huge, meaningless parameters. A principled alternative is to ask for a slightly different problem: fit the data well and keep the answer modest. That is regularisation, and it is how robot software survives ill-conditioned problems.

The intuition

Add a second term to the cost: ‖Ax − b‖² + λ‖x‖². The first term wants a good fit; the second wants small unknowns. The number λ says how much you care about the second. For λ = 0 you recover ordinary least squares. As λ grows, the answer shrinks toward zero.

Interactive figure. Six data points and a least-squares line with a penalty on the slope. Increasing the penalty flattens the line. The readout gives the fitted line, the weighted sum of squares and the normal equations including the penalty. This figure needs JavaScript to be interactive.

Raise the slope penalty λ. The fitted line flattens toward a horizontal line while the intercept compensates: the penalty prefers a smaller slope even though the fit gets slightly worse. Compare the residuals (orange) with λ = 0.
Regularisation trades accuracy for stabilityTwo nearly parallel measurement directions make the exact solution swing wildly when the data change by a thousandth. With a small penalty the answer stays near the truth. The penalty introduces a small bias but removes most of the sensitivity.A = [[1, 1], [1, 1.001]], true x = (1, 1), b = (2, 2.001) data changeexact solveridge, λ = 0.01 b = (2, 2.001)(1, 1)(0.998, 0.998) b = (2, 2.002) [+0.001](0, 2)(0.997, 0.998) b = (2, 2.003) [+0.002](−1, 3)(0.998, 0.998) A change of 0.001 in the data moves the exact answer by 1; ridge barely moves.
An ill-conditioned problem: a change of 0.001 in the data moves the exact solution by 1, while the regularised solution stays put.

Geometric and physical interpretation

Geometric view. The ordinary cost is a bowl; in an ill-conditioned problem it is a long, nearly flat valley whose bottom is hard to locate (a tiny tilt moves the lowest point a long way). Adding λ‖x‖² adds a round bowl centred at the origin, which makes the valley curved in every direction and pins the minimum. Physical view. A penalty on the size of the parameters is a prior belief that they are modest: a spring pulling each parameter toward zero. The data must pull harder than the spring to move a parameter, so parameters the data barely inform stay near zero instead of drifting to absurd values.

The mathematics

λ
the regularisation parameter (λ ≥ 0).
x̂λ
the regularised solution.
σi
singular values of A (Module 6).

The regularised problem

minimise  ‖A x − b‖² + λ ‖x‖²        ⇒        ( AᵀA + λ I ) x̂λ = Aᵀ b

What it means. The penalty adds λ to every diagonal entry of AᵀA. The matrix AᵀA + λI is always positive definite for λ > 0, so a unique answer exists even when the columns of A are dependent.

The limits

λ → 0:  x̂λ → the least-squares (minimum-norm) solution          λ → ∞:  x̂λ → 0

What it means. Small λ trusts the data; large λ trusts the prior preference for small x. The useful range is in between, chosen from the noise level.

Stability and bias

in the SVD basis:   component i of x̂λ = ( σi / (σi² + λ) ) · (ui · b)          instead of   (1/σi)(ui · b)

What it means. For large singular values the factor is nearly 1/σ (the data are trusted); for tiny ones it is about σ/λ, which is small, so noise in poorly determined directions is suppressed instead of amplified by 1/σ.

Regularisation: minimise ‖Ax − b‖² + λ‖x‖², solve (AᵀA + λI)x = Aᵀb. Always solvable, stable, at the price of a bias that grows with λ.

Step-by-step derivation: the regularised normal equations and the filter factors

The equations. The cost is f(x) = ‖Ax − b‖² + λ‖x‖² = xᵀ(AᵀA + λI)x − 2bᵀAx + bᵀb.

  1. Gradient: ∇f = 2(AᵀA + λI)x − 2Aᵀb.
  2. Set to zero: (AᵀA + λI)x̂ = Aᵀb.
  3. Invertibility. For any x ≠ 0, xᵀ(AᵀA + λI)x = ‖Ax‖² + λ‖x‖² ≥ λ‖x‖² > 0. So the matrix is positive definite, hence invertible, for every λ > 0 even when A is rank-deficient.

A stacked view. Regularised least squares is ordinary least squares on the augmented system [A; √λ I] x ≈ [b; 0]: extra rows saying “x should be about zero”. This is how it is implemented with QR (no need to form AᵀA).

The filter factors. Use the SVD A = UΣVᵀ (Module 6). Then AᵀA + λI = V(Σ² + λI)Vᵀ and Aᵀb = VΣUᵀb, so x̂λ = V(Σ² + λI)⁻¹ΣUᵀb, whose i-th component along vi is σi/(σi² + λ) · (ui·b). Ordinary least squares has 1/σi instead. Where σi ≫ √λ they agree; where σi ≪ √λ the regularised factor ≈ σi/λ is tiny, whereas 1/σi would be huge.

The cost: bias. The regularised answer is not the data-optimal one; it is pulled toward zero by an amount that grows with λ. In the example below, the penalty moves the noise-free answer from (1, 1) to (0.998, 0.998): a small, known bias in exchange for removing a 1000-fold amplification of noise.

A worked example: an ill-conditioned pair of parameters

Let A = [[1, 1], [1, 1.001]], whose columns are nearly parallel (κ = 4002). The noise-free data b = (2, 2.001) correspond to x = (1, 1).

  1. Exact solve with a tiny data change. With b′ = (2, 2.002) (a change of 0.001 in one entry) the equations x₁ + x₂ = 2, x₁ + 1.001x₂ = 2.002 give 0.001x₂ = 0.002, so x = (0, 2): the answer moved by 1 for a data change of 0.001, an amplification of about 1000. With b″ = (2, 2.003) it becomes (−1, 3).
  2. Ridge with λ = 0.01. Solve (AᵀA + 0.01 I)x = Aᵀb′: x = (0.997, 0.998) for the noisy b′, and (0.998, 0.998) for the clean b. The noise barely matters.
  3. Price. For the clean data the ridge answer is (0.998, 0.998) rather than (1, 1): a bias of about 0.002.
  4. A line fit. On the points (1, 1), (2, 2), (3, 2), penalising only the slope with λ = 0, 1, 10 gives slopes 0.5, 0.333, 0.083 and intercepts 0.667, 1.0, 1.5: the line flattens as the penalty grows.

Robotics application

Damped inverse kinematics. Near a singular pose the Jacobian J has a tiny singular value, and its (pseudo)inverse gives enormous joint speeds. The damped least-squares inverse Jᵀ(JJᵀ + λ²I)⁻¹ is exactly ridge regularisation, bounding the speeds at the cost of a small tracking error; Module 8 develops it (see the Buss survey in the reference list there).

Levenberg-Marquardt. The workhorse of nonlinear least squares in SLAM and calibration adds λI (or λ diag(JᵀJ)) to the Gauss-Newton equations: with large λ it takes cautious gradient-like steps, with small λ near-Gauss-Newton steps. The nonlinear least squares lesson describes the trust-region behaviour.

Calibration with redundant parameters. When two calibration constants have nearly identical effects on the data, ridge keeps them from taking huge opposite values that merely cancel.

Priors in estimation. A penalty is a Gaussian prior with variance σ²/λ on each parameter: a Kalman filter's initial covariance plays the same role, a link to Module 9.

Engineering implications and limitations

Practical rules

  • Choose λ from the noise, not by hand-waving. A rule of thumb is λ comparable to σnoise² relative to the data scale; cross-validation or the discrepancy principle (choose λ so the residual matches the noise level) are standard.
  • Standardise the unknowns first. A single λ penalises all unknowns equally; parameters in different units (metres vs radians) need scaling, or a diagonal penalty matrix.
  • Do not penalise what you want to be large. Do not regularise the intercept or a parameter that should be non-zero; use a penalty matrix that omits it.
  • Implement with the stacked system and QR instead of forming AᵀA + λI, to retain accuracy.
  • Report the bias. A regularised result should come with the λ used; comparing fits across different λ values is not comparing like with like.

Limits

Regularisation hides, rather than repairs, a lack of information. If the data truly do not determine a parameter, the regularised answer just returns the prior (near zero). It is the right tool when you know that, and the wrong one if you hoped it would create information.

Common misconceptions

“Regularisation is a trick to avoid solving the real problem.”

It solves a different, better-posed problem that reflects the fact that the data cannot determine the parameters precisely. It is statistically a prior.

“A bigger λ always gives a safer answer.”

A huge λ ignores the data and returns near zero. The safe value balances noise suppression against bias.

“Adding a small number to the diagonal is harmless numerical hygiene.”

It changes the answer (a bias) and silently chooses which directions to trust. Know what it assumes.

“Regularised least squares needs a special solver.”

It is ordinary least squares with extra rows [√λ I | 0]; any least-squares routine solves it.

Engineering takeaways

  1. Ridge regularisation minimises ‖Ax − b‖² + λ‖x‖² and solves (AᵀA + λI)x = Aᵀb.
  2. AᵀA + λI is positive definite for λ > 0, so a unique, stable answer exists even for dependent columns.
  3. In the SVD basis the factor 1/σi becomes σi/(σi² + λ): poorly determined directions are damped, not amplified.
  4. The price is a bias toward zero that grows with λ; choose λ from the noise level.
  5. Levenberg-Marquardt damping and damped least-squares inverse kinematics are regularisation.

References and further reading

Primary papers and authoritative documentation.

Knowledge check

Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.

Question 1

Show that A = [[1, 1], [1, 1]] (singular) with b = (2, 2) has no unique least-squares solution, but ridge with λ = 1 does. Find it.

Explanation

The columns are identical, so every x with x₁ + x₂ = 1 fits exactly: infinitely many solutions. With ridge: AᵀA = [[2, 2], [2, 2]], Aᵀb = (4, 4); (AᵀA + I)x = [[3, 2], [2, 3]]x = (4, 4) gives x = (0.8, 0.8). The penalty picks the member of the family with the smallest norm (the minimum-norm solution is (1, 1) as λ → 0), shrunk slightly toward zero by λ = 1.

Question 2

Using the filter factors, what happens to the component of the answer along a direction with σ = 0.001 for λ = 0.01, compared with ordinary least squares?

Explanation

Ordinary least squares multiplies (u·b) by 1/σ = 1000, so noise in that direction is amplified a thousand-fold. Ridge multiplies it by σ/(σ² + λ) = 0.001/(10⁻⁶ + 0.01) ≈ 0.1: a reduction by a factor of about 10,000 relative to least squares. For a direction with σ = 1 the two factors are 1 and 1/(1.01) ≈ 0.99, almost the same.

Question 3

Why does damped least-squares inverse kinematics keep joint speeds bounded near a singularity, and what error does it accept in return?

Explanation

Near the singularity one singular value σ of the Jacobian is tiny; the ordinary inverse multiplies the demanded hand motion in that direction by 1/σ, giving huge joint speeds. The damped inverse uses σ/(σ² + λ²), which is at most 1/(2λ): speeds are bounded. The cost is that the hand no longer follows the demanded motion exactly in that direction (a tracking error), which is the physically honest outcome since the arm cannot produce that motion anyway.

What’s next

The last lesson of the module gathers the numerical lessons into a single idea, the condition number, which predicts how much a problem magnifies errors, and separates a bad problem from a bad algorithm.

Next lesson

M5-T8 — Numerical Conditioning and Stability

Use the condition number to predict how much error a problem amplifies, and tell a bad problem from a bad algorithm.

Nothing below is required to finish this lesson.