Unit 8 of 8 · about 3 hours · derive, measure

Residuals, tolerances and iterative-solver error

A solver stops because of a rule, not because mathematics declares the answer correct. Residual scaling and conditioning tell you what that rule actually certifies.

You'll be able to

  • Derive the relationship between a linear-system residual, solution error and conditioning.
  • Design norm-specific absolute and relative residual tests with meaningful scales.
  • Distinguish residual convergence, stagnation, non-finite failure and iteration-cap termination.

Covers

Residuals, tolerances and iterative-solver error
1

Read

In this order, only the parts listed

0 of 3 done

  1. Linear residuals and conditioningFundamentals of Numerical Computation

    Section 2.8.1, Theorem 2.8.1; Section 2.8.2, Residual and backward error, Definition 2.8.2 and equation 2.8.11

    Keep the normwise residual/error relationship. Do not reproduce the later least-squares solver comparison.

  2. Fixed-point errors versus iteration stoppingFundamentals of Numerical Computation

    Sections 4.2.1 to 4.2.3, equations 4.2.2 to 4.2.7, Theorem 4.2.1 and Corollary 4.2.1; then Section 4.3.2's newton stopping implementation

    Observation 4.2.1 says the iteration diverges for all initial values when ; read that as a local statement, since starting at stays at . Theorem 4.2.1 as printed allows any invariant interval, but existence needs completeness: maps into itself with no fixed point there. Read it with a closed interval, then finish the existence step yourself in the self-test. Read the scalar stopping loop on the Newton page, not its graphical demos.

  3. Objective certificates rather than tiny stepsConvex Optimization

    Section 5.5.1 (pp. 241 to 242) and Section 9.1.2, equations 9.9 to 9.10 (p. 460) and the strong convexity constants paragraph (p. 463)

    Read only primal-dual gap stopping and the strong-convexity gradient-to-suboptimality bound, including why an unknown m makes that bound a conceptual rather than practical stopping rule.

2

Focus on

  • For invertible , . Hence ; when and are nonzero, relative error .
  • A scale-aware residual test is . State the norm, units, and . The normalized residual is a useful normwise backward-error measure, not a forward-error certificate.
  • For a -strongly-convex differentiable unconstrained objective, bounds the objective gap. Constraints and nonsmooth penalties need KKT or proximal residuals instead; noisy gradients are not exact stationarity residuals.
  • Check finite values first, then residual convergence, then stagnation and the iteration limit. Small successive steps can reflect poor scaling or rounding. Report the reason for exit rather than labeling every exit converged.
Common mistakes · 3
  • Treating a tiny residual as a tiny solution error without checking the inverse sensitivity or condition number.
  • Using a relative-only tolerance when the target scale is zero, or comparing residuals in different units without rescaling atol.
  • Declaring convergence at maxiter or after a small update even though the residual test failed.
3

Try it yourself

Closed-book, before checking anything

Derive the residual-to-error bound by hand. In NumPy float64 set A=diag(1,1e-8), xstar=np.ones(2,dtype=np.float64), b=A@xstar and xhat=np.array([1,0],dtype=np.float64). Compute r=b-A@xhat: , relative residual=1e-8, relative solution error=0.7071067812, , and normalized residual=5e-9 using the denominator . Allow relative scalar tolerance 1e-9 for these displayed nonzero quantities. The relative-error bound is 1, so the large observed error does not contradict it. An absolute-only threshold 1e-7 accepts this poor answer. With and , the Euclidean residual test rejects it. Multiply both and by : the residual becomes 1 and the relative residual remains about 1e-8; the same combined test rejects it again. Take one correction xhat+=np.linalg.solve(A,r) using the original A and r. The measured final Euclidean error and residual are both 0; require rather than exact equality. Finally work the harmonic partial sums by hand: successive increments tend to zero although diverges. Use this to justify a stagnation status separate from residual convergence. No random draws are needed.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Which assumptions are used in the relative residual bound?Answer

    Invertibility gives . Consistent operator and vector norms give and . Combine them to get the relative bound; and must be nonzero to divide by their norms. No random or convergence assumption is needed.

  2. 2.Why does multiplying A and b by the same nonzero scalar leave relative residual unchanged?Answer

    Both and acquire the scalar's absolute magnitude. The solution is unchanged, but an absolute residual tolerance must be rescaled to preserve the same test exactly.

  3. 3.Why do vanishing harmonic increments not establish convergence?Answer

    tends to zero. But each block from through contributes at least , because it has terms each at least . Thus , including , and the sums diverge.

  4. 4.What does a primal-dual gap certify, and what must be checked first?Answer

    For primal-feasible and dual-feasible multipliers, weak duality bounds by . Check both feasibilities before interpreting the gap. Strong duality is needed to make arbitrarily tight such certificates possible, not for this lower-bound argument.

  5. 5.What makes the contraction-mapping existence guarantee valid?Answer

    A nonempty complete domain, such as a closed interval of , an invariant map contained in , and a global Lipschitz constant . Invariance keeps all iterates in ; the contraction bounds successive differences by a geometric sequence, hence the iterates are Cauchy. Completeness puts the limit in , and continuity gives . The contraction also proves uniqueness. An open interval alone does not provide completeness.

5

Practice

  • FNC Python: foil the successive-step stopping indicator

    Exercise 4.3.8

    The harmonic sums in Reproduce are one answer; find a different foiling sequence and prove both properties. Explain why a shrinking update alone is insufficient, then specify finite-value, residual, stagnation and iteration-cap statuses for your own loop.

You're done when

You can derive the conditioning bound, explain the small-residual counterexample, and defend a norm-and-scale-specific stopping rule that never labels stagnation or an iteration cap as residual convergence.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 9 more in the section
  • Convex OptimizationBoyd & Vandenberghe · required

    Read Chapters 1-5 and 9 with the course; use Chapter 10 only for equality-constrained Newton steps.

  • Fundamentals of Numerical ComputationDriscoll & Braun · required

    Study §§1.1-1.4, 2.7-2.8, 3.2-3.4 and 4.2-4.3 for floating point, conditioning, stability, least squares and iteration error, in the Python edition.

Also in this section

  • Stanford EE364a - Convex OptimizationStanford Engineering Everywhere · primary

    Follow lectures 1-9 and 15-16; use lecture 17 only for KKT systems. Leave full interior-point treatment for later.

  • D2L - Optimization AlgorithmsD2L authors · required

    Use the convexity, GD, SGD, minibatch, momentum, AdaGrad, RMSProp, Adam and scheduler sections for ML derivations and code.

  • CVXPY basic and DCP tutorialsCVXPY documentation · support

    Use as the solver oracle after deriving a constrained problem and its KKT conditions by hand.

  • Proximal AlgorithmsNeal Parikh and Stephen Boyd · reference

    Read Sections 1.1, 4.2 and the elementwise soft-thresholding formula in 6.5.2, then the lasso formulation on p. 196. Skip 7.1.1's penalty-scaling and Gram-rewrite errors on p. 197; derive the update from 4.2 and 6.5.2.

  • PyTorch optimizer and gradient-clipping contractsPyTorch · reference

    Use AdamW's algorithm and clip_grad_norm_'s parameters to locate weight decay and clipping precisely. Inspect state_dict for optimizer restart; no network training is assigned.

  • SciPy minimize: BFGSSciPy · reference

    Read the BFGS method description and gtol, maxiter, c1 and c2 options. Supply an analytic gradient and compare residuals and evaluation counts, not just iterations.

  • PyTorch numerical type informationPyTorch · reference

    Read torch.finfo's eps, max and smallest_normal fields and its subnormal note; inspect float64, float32, float16 and bfloat16 on CPU.

  • The Accuracy of Floating Point SummationNicholas J. Higham · reference

    Read Section 2's recursive-sum error bound and Section 3's pairwise and compensated summation algorithms. Leave the statistical error models and historical machine details aside.

  • Accurately computing running varianceJohn D. Cook · support

    Read the Welford mean and centered-sum recurrences. Prove the centered-sum invariant and translate the recurrence to NumPy; skip the C++ class.