With equally spaced design points xi = i/n, each coefficient of r in the cosine basis is estimated by an average, β̂j = n−1Σi Yiφj(xi), whose variance is exactly σ2/n. The highest quarter of the frequencies carry almost nothing but noise, so they estimate σ (21.26); the number of terms J minimises the risk estimate (21.27); and the band r̂(x) ± a(x) σ̂ χJ,α/√n of Theorem 21.11 covers the smoothed function rJ = Σj≤J βjφj, not r itself. Large J: little bias, wide band. Small J: narrow band around the wrong curve.
The noise is drawn from a seeded generator: the same settings give the same data, and "New noise" moves to the next seed. The basis is counted from 1: φ1 = 1 and φj(x) = √2 cos((j − 1)πx). The glass data (Exercise 21.7) are sorted by aluminium content and placed at xi = i/n, as the exercise suggests; the fit is drawn against aluminium. The true risk uses the exact coefficients of the test function.
code/ch21_orthogonal_functions.py (reg_series, reg_fit, reg_band, reg_true_risk, doppler_data).