MAP Estimation and Regularization
Page 903 ended on the one symptom of overfitting visible without a test set: “the magnitude of the parameter values becomes relatively large.” This page acts on it, twice — once as a prior (§9.2.3) and once as a penalty (§9.2.4) — and then shows they are the same estimator.
Chapter 8’s page 805 measured that equivalence in its own notation. Here it arrives with the chapter’s own algebra, and with a wrinkle: the book gives two different values of in adjacent paragraphs, and only one of them is the one you want.
What you’ll learn
Section titled “What you’ll learn”- Equations 9.24–9.31: Bayes on the parameters, and the closed form .
- Why the extra term rescues a singular problem: measured, it turns a smallest eigenvalue of exactly into , and makes the estimate exist at .
- Equations 9.32–9.34: regularized least squares, the data-fit and regularizer terms.
- The two- discrepancy. Eq 9.33’s text says ; Eq 9.34’s says . Measured across five settings, only the second reproduces Equation 9.31 — the first agrees in one accidental case.
- Example 9.6 reproduced: at the prior cuts test RMSE from to and from to .
- The book’s caveat, measured: MAP “is not a general solution” — at it is worse than MLE, and its best is no better than choosing the right degree.
- The -norm remark: measured, ridge sets zero coefficients to exactly zero at every ; LASSO sets , then of .
Intuition: an opinion about the directions the data cannot see
Section titled “Intuition: an opinion about the directions the data cannot see”Page 903 found that at the design matrix has a null space, and every parameter vector differing by a null direction fits the training data identically. The likelihood is flat along those directions — it has no opinion at all.
A prior does. says “closer to zero is more plausible,” which is a complete ordering of that flat subspace. So the estimate becomes unique — not because more data arrived, but because you supplied the missing preference.
Algebraically that is one line: add to every eigenvalue of . A zero eigenvalue is exactly a direction the data cannot see, and after the shift there are none.
The ratio is the whole story: noisy data or a confident prior means shrink harder. That is page 805’s reading of , arriving through different algebra.
flowchart TD A["Section 9.2.3: a PRIOR
p(theta) = N(0, b^2 I)"] B["Section 9.2.4: a PENALTY
||y - Phi theta||^2 + lambda ||theta||^2"] A -->|"Eq 9.31"| C["(Phi'Phi + sigma^2/b^2 I)^-1 Phi'y"] B -->|"Eq 9.34"| D["(Phi'Phi + lambda I)^-1 Phi'y"] C --> E["the SAME estimator
measured 0.00e+00, every setting"] D --> E E --> F["provided lambda = sigma^2 / b^2"] F -.->|"NOT 1/(2b^2), which Eq 9.33's
text names — it agrees only
when sigma^2 = 1/2"| G["measured 1.87e-01 off"] E --> H["every eigenvalue lifted by lambda
0 becomes 0.04, cond inf becomes finite"]
§9.2.3 Maximum a posteriori estimation
Section titled “§9.2.3 Maximum a posteriori estimation”The motivation, in the book’s own words: “we often observe that the magnitude of the parameter values becomes relatively large if we run into overfitting.” So place a prior “that explicitly encodes what parameter values are plausible (before having seen any data)” — and the book’s calibration is worth keeping: a prior on a single parameter “encodes that parameter values are expected [to] lie in the interval .”
Bayes’ theorem gives the posterior, Equation 9.24:
and taking logs gives Equation 9.25:
“the log-posterior … is the sum of the log-likelihood and the log-prior so that the MAP estimate will be a ‘compromise’ between the prior … and the data-dependent likelihood.”
So the objective (Equation 9.26) is to minimise , and its gradient (Equation 9.27) is just the sum of two gradients — the first being Equation 9.11c from page 902, unchanged.
The closed form
Section titled “The closed form”With , Equation 9.28 is
Setting the gradient (9.29) to zero and working through 9.30 gives Equation 9.31:
Comparing the MAP estimate in (9.31) with the maximum likelihood estimate in (9.19), we see that the only difference between both solutions is the additional term in the inverse matrix.
§9.2.4 MAP estimation as regularization
Section titled “§9.2.4 MAP estimation as regularization”The same effect “without placing a prior distribution” — penalise the amplitude directly. Regularized least squares, Equation 9.32:
The first term is the data-fit term (also “misfit term”), “proportional to the negative log-likelihood”. The second is the regularizer, and is the regularization parameter, which “controls the ‘strictness’ of the regularization.”
Minimising it gives Equation 9.34:
The two-lambda problem
Section titled “The two-lambda problem”The book connects the two in consecutive paragraphs, and names two different :
With a Gaussian prior , we obtain the negative log-Gaussian prior (9.33) so that for the regularization term and the negative log-Gaussian prior are identical.
[Equation 9.34] is identical to the MAP estimate in (9.31) for , where is the noise variance and the variance of the isotropic Gaussian prior.
Example 9.6, reproduced
Section titled “Example 9.6, reproduced”The book places , so and .
The book’s description holds in both halves:
The prior (regularizer) does not play a significant role for the low-degree polynomial, but keeps the function relatively smooth for higher-degree polynomials.
Although the MAP estimate can push the boundaries of overfitting, it is not a general solution to this problem, so we need a more principled approach.
The p-norm remark
Section titled “The p-norm remark”Instead of the Euclidean norm , we can choose any -norm in (9.32). In practice, smaller values for lead to sparser solutions. … For , the regularizer is called LASSO (least absolute shrinkage and selection operator).
Worked example by hand
Section titled “Worked example by hand”Derive Equation 9.31 in one dimension and read the shrinkage directly.
Model: , , prior .
Step 1: the negative log-posterior (Equation 9.28 with ):
Step 2: differentiate and set to zero (Equation 9.29 → 9.30):
Step 3: collect .
which is Equation 9.31 with and .
Step 4: compare with the MLE. Page 901’s worked example gave , so
always in — the estimate is the MLE shrunk toward zero, never past it and never away.
Step 5: read the three limits.
| limit | shrinkage factor | estimate | meaning |
|---|---|---|---|
| the MLE | a vague prior is no prior | ||
| a certain prior ignores the data | |||
| the MLE | enough data outvotes any prior | ||
| useless data, keep the prior |
Step 6: the degenerate case. If — every input is zero, so the data says nothing about — then is undefined, while
perfectly well defined. That is the one-dimensional version of the null-space rescue: where the likelihood is flat, the prior decides, and it decides on zero.
See it move
Section titled “See it move”From scratch
Section titled “From scratch”import numpy as np
SIG, NTR = 0.2, 10
def truth(x):
return -np.sin(x / 5) + np.cos(x)
def design(x, M):
return np.vander(np.asarray(x, float), M + 1, increasing=True)
rng = np.random.default_rng(4)
x = np.sort(rng.uniform(-5, 5, NTR))
y = truth(x) + SIG * rng.standard_normal(NTR)
xte = np.linspace(-5, 5, 200)
yte = truth(xte) + SIG * np.random.default_rng(1234).standard_normal(200)
def rmse(a, b):
return float(np.sqrt(np.mean((a - b) ** 2)))
def map_est(P, b2, sig=SIG):
"""Equation 9.31."""
return np.linalg.solve(P.T @ P + (sig ** 2 / b2) * np.eye(P.shape[1]),
P.T @ y)
def rls(P, lam):
"""Equation 9.34."""
return np.linalg.solve(P.T @ P + lam * np.eye(P.shape[1]), P.T @ y)
# --- 1. the book names two lambdas; only one works ----------------------
print("=== 1. the book names TWO lambdas. Only one of them works. ===")
P = design(x, 6)
print(f"{'sigma':>7} {'b^2':>7} {'sigma^2/b^2':>13} {'1/(2b^2)':>11} "
f"{'|RLS-MAP| at s2/b2':>20} {'at 1/(2b2)':>13}")
for sig, b2 in ((0.2, 1.0), (0.2, 4.0), (1.0, 1.0),
(np.sqrt(0.5), 1.0), (0.5, 0.25)):
m = np.linalg.solve(P.T @ P + (sig**2 / b2) * np.eye(P.shape[1]),
P.T @ y)
a = float(np.abs(rls(P, sig**2 / b2) - m).max())
c = float(np.abs(rls(P, 1.0 / (2*b2)) - m).max())
print(f"{sig:>7.4f} {b2:>7.2f} {sig**2/b2:>13.6f} {1/(2*b2):>11.6f} "
f"{a:>20.2e} {c:>13.2e}")
print("\nlambda = sigma^2/b^2 reproduces Eq 9.31 EXACTLY, every row.")
print("lambda = 1/(2b^2) agrees only in row 4, where sigma^2 = 1/2.")
# --- 2. why the extra term rescues a singular problem -------------------
print("\n=== 2. the extra term lifts every eigenvalue ===")
print(f"{'M':>4} {'rk(Phi)':>8} {'K':>4} {'min eig(Phi^T Phi)':>20} "
f"{'+ sigma^2/b^2':>15} {'cond before':>13} {'cond after':>12}")
for M in (4, 9, 10, 12):
Pm = design(x, M)
Km = Pm.shape[1]
s = np.linalg.svd(Pm, compute_uv=False)
ev = np.zeros(Km)
ev[:len(s)] = s ** 2 # eigenvalues of Phi^T Phi, never negative
ev = np.sort(ev)
ev2 = ev + SIG ** 2
cb = (ev.max() / ev.min()) if ev.min() > 0 else float("inf")
print(f"{M:>4} {int(np.linalg.matrix_rank(Pm)):>8} {Km:>4} "
f"{ev.min():>20.6e} {ev2.min():>15.6e} {cb:>13.3e} "
f"{ev2.max()/ev2.min():>12.3e}")
print("at M >= 10 the smallest eigenvalue is exactly 0 and the condition")
print("number is infinite. Adding sigma^2/b^2 makes it sigma^2/b^2.")
P12 = design(x, 12)
tm = map_est(P12, 1.0)
ns = np.linalg.svd(P12)[2][int(np.linalg.matrix_rank(P12)):]
def map_obj(t):
r = y - P12 @ t
return float(r @ r / (2 * SIG ** 2) + (t @ t) / 2.0)
print(f"\nat M = 12 (K = 13 > N = 10): ||theta_MAP|| = "
f"{np.linalg.norm(tm):.6f}")
print(f" MAP objective at theta_MAP : {map_obj(tm):.6f}")
for c in (0.1, 1.0, 10.0):
print(f" ... + {c:>4} x old null vector : "
f"{map_obj(tm + c * ns[0]):.6f}")
print(" every perturbation raises it. Under maximum likelihood these were")
print(" all tied; under MAP exactly one wins.")
# --- 3. Example 9.6 -----------------------------------------------------
print("\n=== 3. Example 9.6: MLE against MAP, prior N(0, I) so b^2 = 1 ===")
print(f"{'M':>4} {'||theta_ML||':>14} {'||theta_MAP||':>15} "
f"{'train MLE':>11} {'train MAP':>11} {'test MLE':>12} {'test MAP':>11}")
for M in (0, 2, 4, 6, 8, 9):
Pm = design(x, M)
tl = np.linalg.lstsq(Pm, y, rcond=None)[0]
tmm = map_est(Pm, 1.0)
print(f"{M:>4} {np.linalg.norm(tl):>14.4f} {np.linalg.norm(tmm):>15.4f} "
f"{rmse(y, Pm @ tl):>11.4f} {rmse(y, Pm @ tmm):>11.4f} "
f"{rmse(yte, design(xte, M) @ tl):>12.4f} "
f"{rmse(yte, design(xte, M) @ tmm):>11.4f}")
# --- 4. the prior barely moves a low-degree fit -------------------------
print("\n=== 4. how much the prior actually moves the estimate ===")
print(f"{'M':>4} {'max |theta_ML - theta_MAP|':>28} "
f"{'relative to ||theta_ML||':>26}")
for M in range(10):
Pm = design(x, M)
tl = np.linalg.lstsq(Pm, y, rcond=None)[0]
d = float(np.abs(tl - map_est(Pm, 1.0)).max())
print(f"{M:>4} {d:>28.6e} {d/np.linalg.norm(tl):>26.6f}")
print("tiny at low degree, large at high degree -- the prior only bites")
print("when the likelihood wants large coefficients.")
# --- 5. 'not a general solution' ---------------------------------------
print("\n=== 5. test RMSE, MLE against MAP, all degrees ===")
print(f"{'M':>4} {'test MLE':>13} {'test MAP':>13} {'MAP / MLE':>12}")
tl_, tm_ = [], []
for M in range(10):
Pm = design(x, M)
a = rmse(yte, design(xte, M) @ np.linalg.lstsq(Pm, y, rcond=None)[0])
b = rmse(yte, design(xte, M) @ map_est(Pm, 1.0))
tl_.append(a); tm_.append(b)
print(f"{M:>4} {a:>13.4f} {b:>13.4f} {b/a:>12.4f}")
tl_, tm_ = np.array(tl_), np.array(tm_)
print(f"\nbest MLE: M = {int(np.argmin(tl_))} at {tl_.min():.6f}")
print(f"best MAP: M = {int(np.argmin(tm_))} at {tm_.min():.6f}")
print(f"at M = 9, MAP is {tl_[9]/tm_[9]:.1f}x better than MLE -- and still")
print(f"{tm_[9]/tm_.min():.0f}x worse than its own best. At M = 7 MAP is")
print(f"WORSE than MLE, by {tm_[7]/tl_[7]:.4f}x.")
print("The book: 'it is not a general solution to this problem'.")
# --- 6. the p-norm remark -----------------------------------------------
print("\n=== 6. smaller p gives sparser solutions ===")
r5 = np.random.default_rng(21)
n, d = 60, 30
A = r5.standard_normal((n, d))
th_true = np.zeros(d)
th_true[[0, 5, 11]] = [2.0, -1.5, 1.0] # only 3 of 30 matter
yy = A @ th_true + 0.3 * r5.standard_normal(n)
Ate = r5.standard_normal((4000, d))
yte2 = Ate @ th_true + 0.3 * r5.standard_normal(4000)
def lasso(A, yv, lam, iters=6000):
"""coordinate descent for 0.5||y - A t||^2 + lam ||t||_1"""
t = np.zeros(A.shape[1])
col = (A ** 2).sum(0)
r = yv - A @ t
for _ in range(iters):
for j in range(A.shape[1]):
r += A[:, j] * t[j]
rho = A[:, j] @ r
t[j] = np.sign(rho) * max(abs(rho) - lam, 0.0) / col[j]
r -= A[:, j] * t[j]
return t
print(f"the truth has {int(np.sum(th_true != 0))} nonzero coefficients of {d}")
print(f"\n{'penalty':>14} {'lambda':>8} {'exact zeros':>13} {'test RMSE':>12}")
for lam in (2.0, 8.0, 20.0):
t2 = np.linalg.solve(A.T @ A + lam * np.eye(d), A.T @ yy)
print(f"{'p = 2 (ridge)':>14} {lam:>8.1f} "
f"{int(np.sum(t2 == 0.0)):>13} {rmse(yte2, Ate @ t2):>12.6f}")
for lam in (2.0, 8.0, 20.0):
t1 = lasso(A, yy, lam)
print(f"{'p = 1 (LASSO)':>14} {lam:>8.1f} "
f"{int(np.sum(t1 == 0.0)):>13} {rmse(yte2, Ate @ t1):>12.6f}")
print("\nridge sets NOTHING to exactly zero at any lambda; LASSO does.")
print("That is the 'variable selection' the book mentions.")=== 1. the book names TWO lambdas. Only one of them works. ===
sigma b^2 sigma^2/b^2 1/(2b^2) |RLS-MAP| at s2/b2 at 1/(2b2)
0.2000 1.00 0.040000 0.500000 0.00e+00 1.87e-01
0.2000 4.00 0.010000 0.125000 0.00e+00 5.60e-02
1.0000 1.00 1.000000 0.500000 0.00e+00 1.38e-01
0.7071 1.00 0.500000 0.500000 0.00e+00 0.00e+00
0.5000 0.25 1.000000 2.000000 0.00e+00 1.73e-01
lambda = sigma^2/b^2 reproduces Eq 9.31 EXACTLY, every row.
lambda = 1/(2b^2) agrees only in row 4, where sigma^2 = 1/2.
=== 2. the extra term lifts every eigenvalue ===
M rk(Phi) K min eig(Phi^T Phi) + sigma^2/b^2 cond before cond after
4 5 5 3.170370e+00 3.210370e+00 1.817e+05 1.794e+05
9 10 10 1.057570e-02 5.057570e-02 2.155e+14 4.506e+13
10 10 11 0.000000e+00 4.000000e-02 inf 1.234e+15
12 10 13 0.000000e+00 4.000000e-02 inf 5.910e+17
at M >= 10 the smallest eigenvalue is exactly 0 and the condition
number is infinite. Adding sigma^2/b^2 makes it sigma^2/b^2.
at M = 12 (K = 13 > N = 10): ||theta_MAP|| = 1.298908
MAP objective at theta_MAP : 1.487441
... + 0.1 x old null vector : 1.492440
... + 1.0 x old null vector : 1.987435
... + 10.0 x old null vector : 51.487388
every perturbation raises it. Under maximum likelihood these were
all tied; under MAP exactly one wins.
=== 3. Example 9.6: MLE against MAP, prior N(0, I) so b^2 = 1 ===
M ||theta_ML|| ||theta_MAP|| train MLE train MAP test MLE test MAP
0 0.2135 0.2126 0.9780 0.9780 0.8937 0.8937
2 0.5211 0.5167 0.5900 0.5900 0.6885 0.6875
4 0.9904 0.9786 0.2706 0.2707 0.3249 0.3237
6 1.1985 1.1747 0.2076 0.2079 0.4734 0.4652
8 1.1314 1.0674 0.1609 0.1617 7.4206 6.5830
9 4.2030 1.2062 0.0000 0.1060 100.8506 29.9717
=== 4. how much the prior actually moves the estimate ===
M max |theta_ML - theta_MAP| relative to ||theta_ML||
0 8.505296e-04 0.003984
1 8.703216e-05 0.000405
2 4.673534e-03 0.008968
3 6.974884e-03 0.009197
4 1.180136e-02 0.011915
5 1.409246e-02 0.013995
6 2.040807e-02 0.017028
7 3.402187e-02 0.034825
8 7.580307e-02 0.066998
9 2.292865e+00 0.545531
tiny at low degree, large at high degree -- the prior only bites
when the likelihood wants large coefficients.
=== 5. test RMSE, MLE against MAP, all degrees ===
M test MLE test MAP MAP / MLE
0 0.8937 0.8937 1.0000
1 0.7451 0.7451 1.0000
2 0.6885 0.6875 0.9986
3 0.7854 0.7821 0.9958
4 0.3249 0.3237 0.9963
5 0.3331 0.3295 0.9892
6 0.4734 0.4652 0.9826
7 0.6645 0.7743 1.1652
8 7.4206 6.5830 0.8871
9 100.8506 29.9717 0.2972
best MLE: M = 4 at 0.324947
best MAP: M = 4 at 0.323740
at M = 9, MAP is 3.4x better than MLE -- and still
93x worse than its own best. At M = 7 MAP is
WORSE than MLE, by 1.1652x.
The book: 'it is not a general solution to this problem'.
=== 6. smaller p gives sparser solutions ===
the truth has 3 nonzero coefficients of 30
penalty lambda exact zeros test RMSE
p = 2 (ridge) 2.0 0 0.443029
p = 2 (ridge) 8.0 0 0.744189
p = 2 (ridge) 20.0 0 1.066952
p = 1 (LASSO) 2.0 17 0.331454
p = 1 (LASSO) 8.0 27 0.389052
p = 1 (LASSO) 20.0 27 0.616809
ridge sets NOTHING to exactly zero at any lambda; LASSO does.
That is the 'variable selection' the book mentions.On real data
Section titled “On real data”Reading the plot
Section titled “Reading the plot”The first figure is about a discrepancy in the text, and the left panel settles it. Each curve is as sweeps, for three different settings. Each plunges to machine zero at its own dotted line, and each dotted line sits at . The red dashed line is — a single position, since in two of the three cases — and it misses.
Both of the book’s sentences are correct; they are answering different questions. Equation 9.33’s compares the two penalty terms in isolation: against , which of course matches at . Equation 9.34’s compares the two estimators, which requires the data-fit terms to have been put on the same footing first — and Equation 9.32’s has no , so the whole MAP objective must be scaled by , turning into .
A reader who takes the first sentence as the recipe gets an estimate that is off by on this data. The rule worth keeping: a is meaningless without the objective it belongs to — which is also why Chapter 8’s page 805 reported for the same idea, differing again by the in Equation 8.12.
The second figure shows what the extra term is for, and it is not conditioning. The left panel plots the eigenvalue spectrum of before and after the shift. At the three smallest eigenvalues are exactly zero — columns, rank — so the condition number is infinite and Equation 9.19 has no unique answer at all. After the shift the smallest is .
Note what the shift does not do. At the condition number goes from to — essentially unchanged. The prior is not a numerical preconditioner; it is a statement that gets applied uniformly to every direction and matters only where the data supplied nothing.
The right panel makes that concrete. Along an old null direction, the negative log-likelihood is flat — every point on that line explains the training data identically well, which is page 903’s “infinitely many estimators” seen edge-on. The negative log-posterior is a parabola with one minimum. Measured: at the optimum, rising to ten steps out. The prior did not add information about the data; it added a preference among answers the data could not distinguish.
The third figure is Example 9.6, and its three panels sort the book’s claim into its two halves. At degree 6 the MLE and MAP curves are nearly on top of each other — measured, the parameters differ by of the norm. At degree 8 they separate. At degree 9 (right panel, off the end) the MLE reaches a test RMSE of and MAP .
The right panel is where the honesty lives. MAP is below MLE at almost every degree — and above it at , by . Shrinkage is a bet that the truth is small, and at on this draw the bet loses. More importantly, the two minima are and : the prior improves the best available answer by .
That is the precise content of “it is not a general solution to this problem.” A prior converts a catastrophic choice into a survivable one — a improvement at — while leaving the good choice essentially untouched. You still have to choose, and §9.3’s marginal likelihood is what finally does the choosing without a held-out set.
The fourth figure is the -norm remark, and the blue line flat on zero is the whole result. Ridge sets no coefficient to exactly zero, at , or . It shrinks all thirty toward the origin and stops short of it every time.
The reason is calculus. , which is zero at the origin — a quadratic penalty exerts no force on a coefficient that is already tiny, so there is nothing to push it the last step. : a constant force, right up to the kink. That kink is a reason to stop exactly at zero, and it is why LASSO produces the “variable selection” the book names.
Measured, LASSO finds zeros at and the truth has . Its test RMSE at is against ridge’s best of — better at every tried here, because the truth genuinely is sparse and is the assumption that says so. On a dense truth the ranking would reverse, and the book’s “in practice” is doing real work in that sentence.
Compare
Section titled “Compare”| MLE, Eq 9.19 | MAP, Eq 9.31 | RLS, Eq 9.34 | |
|---|---|---|---|
| matrix inverted | |||
| exists when | no | yes | yes |
| unique | only if | always | always |
| needs | no | yes | no |
| derived from | a likelihood | a posterior | a penalised loss |
| identical to MAP when | — | ||
| measured at , test | same as MAP |
| where the comes from | objective | |
|---|---|---|
| Eq 9.33, penalty terms alone | vs | |
| Eq 9.34, the estimators | ||
| Chapter 8, Eq 8.12 |
| , ridge | , LASSO | |
|---|---|---|
| penalty gradient at | (a kink) | |
| exact zeros produced | none, at any | , then of |
| prior it corresponds to | Gaussian | Laplace |
| closed form | yes, Eq 9.34 | no — needs an iterative solve |
| best when | the truth is dense | the truth is sparse |
| measured test RMSE here | best | best |
-
The book gives lambda = 1/(2b squared) near Equation 9.33 and lambda = sigma squared over b squared near Equation 9.34. Which one makes theta-RLS equal theta-MAP?
Both statements are true about different comparisons. Equation 9.33's matches the two penalty TERMS in isolation; Equation 9.34's matches the two ESTIMATORS, which requires first putting the data-fit terms on the same footing — and Equation 9.32's has no 1/(2 sigma squared), so the whole MAP objective must be scaled by 2 sigma squared.
pch.quizShowAnswer
B — sigma squared over b squared — measured at exactly 0.00e+00 in all five settings tried — Both statements are true about different comparisons. Equation 9.33's matches the two penalty TERMS in isolation; Equation 9.34's matches the two ESTIMATORS, which requires first putting the data-fit terms on the same footing — and Equation 9.32's has no 1/(2 sigma squared), so the whole MAP objective must be scaled by 2 sigma squared.
-
What does the extra term in Equation 9.31 actually do to the spectrum of Phi-transpose-Phi?
That is why the book's margin note says the inverse exists: a zero eigenvalue is a direction the data cannot see, and after the shift there are none. Measured at M = 12 with K = 13 and rank 10, the three smallest eigenvalues are exactly zero and the condition number is infinite before the shift.
pch.quizShowAnswer
B — It adds sigma squared over b squared to every eigenvalue, so a smallest eigenvalue of exactly 0 becomes 0.04 — That is why the book's margin note says the inverse exists: a zero eigenvalue is a direction the data cannot see, and after the shift there are none. Measured at M = 12 with K = 13 and rank 10, the three smallest eigenvalues are exactly zero and the condition number is infinite before the shift.
-
At M = 12 with N = 10, maximum likelihood has infinitely many tied answers. What does the MAP objective do along one of those tied directions?
The prior did not add information about the data — the likelihood really is flat there. It added a preference among answers the data could not distinguish, and 'closer to zero is more plausible' is a complete ordering of that flat subspace.
pch.quizShowAnswer
B — It is a parabola with exactly one minimum — measured 1.487441 at the optimum, rising to 51.487388 ten steps out — The prior did not add information about the data — the likelihood really is flat there. It added a preference among answers the data could not distinguish, and 'closer to zero is more plausible' is a complete ordering of that flat subspace.
-
The book says MAP 'is not a general solution to this problem'. What does the measurement show?
Best MAP is 0.323740 against best MLE's 0.324947. A prior converts a catastrophic choice into a survivable one while leaving a good choice essentially untouched — so you still have to choose. Section 9.3's marginal likelihood is what finally does the choosing without a held-out set.
pch.quizShowAnswer
B — MAP improves M = 9 by 3.4x but its best is only 0.4 percent better than MLE's best, and at M = 7 it is actively worse — Best MAP is 0.323740 against best MLE's 0.324947. A prior converts a catastrophic choice into a survivable one while leaving a good choice essentially untouched — so you still have to choose. Section 9.3's marginal likelihood is what finally does the choosing without a held-out set.
-
Measured on 30 candidate features with 3 real ones, how many coefficients does ridge set to exactly zero?
A quadratic penalty has derivative 2 theta, which is zero at the origin — so it exerts no force on a coefficient that is already tiny and never pushes it the last step. The absolute-value penalty has derivative plus or minus one right up to the kink, and that kink is a reason to stop exactly at zero. LASSO found 27 zeros at lambda = 8.
pch.quizShowAnswer
B — Zero, at every lambda tried — it shrinks everything and zeroes nothing — A quadratic penalty has derivative 2 theta, which is zero at the origin — so it exerts no force on a coefficient that is already tiny and never pushes it the last step. The absolute-value penalty has derivative plus or minus one right up to the kink, and that kink is a reason to stop exactly at zero. LASSO found 27 zeros at lambda = 8.
-
How much does the prior move the estimate at degree 1 versus degree 9?
The prior is applied uniformly to every direction but only bites where the likelihood wants large coefficients — which is exactly the overfitting regime page 903 identified. That is the book's 'the prior does not play a significant role for the low-degree polynomial', measured.
pch.quizShowAnswer
B — By 0.04 percent of the norm at degree 1 and 54.6 percent at degree 9 — The prior is applied uniformly to every direction but only bites where the likelihood wants large coefficients — which is exactly the overfitting regime page 903 identified. That is the book's 'the prior does not play a significant role for the low-degree polynomial', measured.
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – Which lambda?
Section titled “Exercise 1 – Which lambda?”Exercise 2 – The prior fills the null space
Section titled “Exercise 2 – The prior fills the null space”Exercise 3 – Example 9.6
Section titled “Exercise 3 – Example 9.6”Exercise 4 – MAP is not a general solution
Section titled “Exercise 4 – MAP is not a general solution”Exercise 5 – Shrinkage or selection
Section titled “Exercise 5 – Shrinkage or selection”Pitfalls
Section titled “Pitfalls”Recall card
Section titled “Recall card”- Equation 9.25: the log-posterior is the log-likelihood plus the log-prior, so the MAP estimate is a compromise between them. Its gradient, Equation 9.27, is just the sum of two gradients.
- Equation 9.31: theta-MAP is the Gram matrix plus sigma squared over b squared times the identity, inverted, times Phi-transpose y. The only difference from Equation 9.19 is that added term.
- The added term lifts every eigenvalue of the Gram matrix by the same amount. Measured at M = 12: a smallest eigenvalue of exactly 0 becomes 0.04, and an infinite condition number becomes finite.
- So the MAP estimate exists and is unique where maximum likelihood is not. Along an old null direction the likelihood is flat and the posterior is a parabola — measured 1.487441 at the optimum, 51.487388 ten steps out.
- The prior does not add information about the data. It adds a preference among answers the data could not distinguish.
- Equation 9.32 is regularized least squares: a data-fit term plus lambda times the squared norm. Equation 9.34 solves it, and it equals Equation 9.31 when lambda = sigma squared over b squared.
- The book names a second lambda, 1/(2b squared), two paragraphs earlier. Measured, it reproduces Equation 9.31 only when sigma squared equals one half. The difference is a factor of 2 sigma squared, because Equation 9.32’s data-fit term carries no 1/(2 sigma squared).
- Chapter 8 gives a third: sigma squared over N tau squared, because Equation 8.12 normalises the data-fit term by N. A lambda is meaningless without its objective.
- Example 9.6 measured: at M = 9 the prior cuts the parameter norm from 4.2030 to 1.2062 and the test RMSE from 100.8506 to 29.9717, a factor of 3.4.
- The prior barely moves a low-degree fit. Measured: 0.04 percent of the norm at M = 1, 54.6 percent at M = 9. It only bites when the likelihood wants large coefficients.
- But it is not a general solution. Best MAP is 0.323740 against best MLE’s 0.324947 — 0.4 percent — and at M = 7 MAP is worse by a factor of 1.1652. Shrinkage is a bet that can lose.
- Smaller p gives sparser solutions. Measured on 30 features with 3 real ones: ridge produces zero exact zeros at every lambda; LASSO produces 17 then 27, and the truth has 27.
- The reason is the gradient at the origin. A quadratic penalty has derivative zero there and never pushes a small coefficient the last step; the absolute value has a kink, which is a reason to stop exactly at zero.
- In one dimension the MAP estimate is the MLE times the sum of x squared over that sum plus sigma squared over b squared — always in the open interval from zero to one, so shrinkage toward zero and never past it.
Next: stop keeping only the peak. Bayesian Linear Regression
pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading