Regularization
正则化
Compare explicit penalties, constraints and early stopping through exact solutions; distinguish training-loss guarantees from generalization and optimizer-dependent weight decay.
regularizationA good fit still leaves choices
Suppose a model can explain the training observations with several very different functions. Which one should it use on new inputs? Training loss alone may not decide. Regularization changes the preference among fits: it may discourage large weights, restrict a function’s shape, impose a useful invariance, or stop a training process before it fits every fluctuation.
The word does not name one algorithm. Deep Learning, Chapter 7 groups several ways of influencing generalization under it. Whether a particular choice helps depends on whether its preference suits the task. Pulling a coefficient toward zero helps some problems and hurts others; bias and variance gives a small experiment where this can be calculated exactly.
We will compare three precise choices on one two-coordinate problem: a quadratic penalty, an absolute-value penalty, and early stopping. This makes it possible to see what changes, without treating every method as a synonym for “make the model smaller.”
Separate the data loss from the preference
A common explicit objective is
L measures fit to training data; R defines the preference; λ sets its strength in the units of L. Two usual penalties are and . Neither convention decides whether an intercept is included. State that separately. Converting a summed data loss to its mean requires dividing λ by n to preserve the same minimizers. See ridge regression and Lasso for full fitted-data derivations.
For a transparent example, let
The unregularized optimum is z; h tells us how quickly training loss rises in each coordinate. Each coordinate can be solved independently. For L2, setting gives . For L1, use derivative +λ when w is positive, −λ when negative, and the interval [−λ,λ] at zero. Combining the three cases gives
At z=(3,1), h=(1,4), λ=1, L2 gives (3/2,4/5), whereas L1 gives (2,3/4). At λ=4, L1 makes both zero. Positive L2 shrinkage does not set these nonzero coordinates exactly to zero at any finite λ. The general correlated-feature Lasso cannot be solved by independently applying this formula to the unregularized coefficients. Deep Learning, Sections 7.1.1–7.1.2
There is an exact monotonic fact, but it concerns training quantities. Suppose are global minimizers of the same L and R at , and all values are finite. Optimality in both directions gives
Adding shows , so the penalty value cannot increase. Substitution then shows training loss cannot decrease. No convexity is needed for this argument once global minima exist. It says nothing about monotonic test performance, and it need not hold for an incompletely optimized run.
A penalty also connects to a constraint. A global minimizer minimizes L among all w with : any feasible point with smaller L would also have smaller penalized objective. The reverse direction, starting from an arbitrary constraint radius and finding a finite λ, requires additional optimization conditions. There is no universal one-to-one λ-to-radius conversion. Deep Learning, Section 7.2
Compare penalties with stopping after two steps
Starting at zero, plain gradient descent on the unpenalized diagonal loss updates . For , repeated substitution yields
Directions with larger h approach their fitted targets sooner. At η=1/8 and t=2 in our example, the result is (45/64,3/4). It resembles shrinkage, but reproducing each coordinate by ridge would require two different penalties: 49/15 and 4/3. There is no single λ giving this two-coordinate point. A useful analogy between early stopping and L2 does not make them identical algorithms.
The complete program computes both exact penalized solutions and the actual gradient updates. It accepts only integer or Fraction inputs to keep the arithmetic exact. The problem has diagonal positive curvature; it is not a solver for arbitrary neural networks.
from fractions import Fraction as F
def exact(v):
if type(v) is not int and not isinstance(v,F):
raise ValueError("integer or Fraction required")
return F(v)
def diagonal_problem(center, curvature):
z, h = tuple(map(exact,center)), tuple(map(exact,curvature))
if not z or len(z)!=len(h) or any(v<=0 for v in h):
raise ValueError("paired nonempty vectors and positive curvature required")
return z,h
def penalized(center, curvature, penalty, kind):
z,h = diagonal_problem(center,curvature)
lam = exact(penalty)
if lam<0 or kind not in ("l1","l2"):
raise ValueError("nonnegative penalty and l1/l2 required")
if kind=="l2":
return tuple(c*v/(c+lam) for v,c in zip(z,h))
return tuple((1 if v>0 else -1 if v<0 else 0)*max(abs(v)-lam/c,0)
for v,c in zip(z,h))
def early_steps(center, curvature, rate, steps):
z,h = diagonal_problem(center,curvature)
eta = exact(rate)
if eta<=0 or eta*max(h)>1 or type(steps) is not int or steps<0:
raise ValueError("0 < rate <= 1/max(curvature), nonnegative integer steps")
w = [F(0)]*len(z)
for _ in range(steps):
w = [v-eta*c*(v-target) for v,target,c in zip(w,z,h)]
return tuple(w)
z,h = (3,1),(1,4)
assert penalized(z,h,1,"l2") == (F(3,2),F(4,5))
assert penalized(z,h,1,"l1") == (F(2),F(3,4))
assert penalized(z,h,4,"l1") == (0,0)
w = early_steps(z,h,F(1,8),2)
assert w == (F(45,64),F(3,4))
# Which ridge coefficient would separately reproduce EACH coordinate?
matched = tuple(c*(target/value-1) for target,c,value in zip(z,h,w))
assert matched == (F(49,15),F(4,3))
assert matched[0] != matched[1]
print("L2:",penalized(z,h,1,"l2"),"L1:",penalized(z,h,1,"l1"))
print("two steps:",w,"coordinate-specific matching penalties:",matched)
The explicit solutions cost O(d) arithmetic operations and O(d) storage. t gradient steps cost O(td), also using O(d) storage; exact fraction bit costs can grow. The chosen learning-rate range ensures nonoscillating coordinate shrinkage. Convergence for this quadratic also allows rates below , but the larger range can oscillate and is not the filter interpretation used here.
Early stopping in practice needs a selection rule. Save the parameters with the best validation score and restore that checkpoint, rather than simply returning the last iterate. The stopping time, patience and score are hyperparameters; repeatedly inspecting validation results is model selection. Deep Learning, Section 7.8 gives the checkpoint procedure. The two-step program above isolates its optimization mechanism; it does not implement validation-based checkpoint selection.
Equal names can hide different updates
With plain gradient descent and our L2 convention,
This is a uniform multiplicative decay plus the data-gradient step. If an optimizer instead rescales gradients by a matrix M, adding L2 produces the term , while separately applying decay produces . These need not match. For M=diag(1,2) and w=(1,1), even a single step shows the difference. Loshchilov and Hutter make this distinction explicit for adaptive optimization in their ICLR 2019 paper, Section 2. The reported experiments belong to that paper; we do not claim to reproduce them here.
Feature units and parameterization also define a penalty. A coefficient in centimeters and its equivalent in meters have different magnitudes. Copying a feature can change the effective penalty on its combined coefficient. An architecture with shared weights restricts functions differently from a norm penalty, and adding parameters does not by itself tell us which functions training will favor.
Other regularizers need their own assumptions. Data augmentation is sensible only when its transformations preserve or correctly transform the target; adding fabricated examples does not automatically add independent information. Dropout changes the training computation with random masks, and its inference rule depends on the defined model. These methods require separate experiments rather than being counted as interchangeable copies of L2.
A large λ can suppress useful signal. A small train/validation gap can coexist with poor predictions, so reducing the gap alone is not the objective. Fit preprocessing within the training split, compare a simple baseline, choose hyperparameters using validation, and reserve the final test for evaluation. Do not choose λ by minimizing training loss: among exact global fits of a fixed penalty family, the monotonic argument explains why that tends toward the weakest penalty. Cornell Lecture 11, model selection
Check the units and the mechanism
- A sum-loss objective uses λ=12 on four observations. What λ preserves it when the data loss becomes a mean? Answer: three. Divide the entire objective by four, not just the data term.
- For z=(3,1), h=(1,4), λ=4, which penalty produces exact zeros? Answer: L1 gives (0,0). L2 gives (3/5,1/2).
- Does a larger λ guarantee lower test error? Answer: no. For global fits it lowers or preserves R and raises or preserves training L, but test risk depends on whether the imposed preference matches the target distribution.
- Can one ridge λ reproduce the two-step point in the program? Answer: no. The nonzero coordinates require 49/15 and 4/3 separately, so a common scalar cannot satisfy both.
Describe the preference well enough to reproduce it
A report should identify the data loss and reduction, the exact penalty or transformation, excluded parameters, feature scaling, optimizer update, initialization, tuning data and checkpoint rule. For an explicit penalty, separately report training fit and penalty value; their sum at different λ values is not a common test metric.
A prior can motivate a penalty through MAP under a specified likelihood. That does not turn the optimum into a full posterior distribution. Likewise, an optimizer’s preference among many interpolating solutions is often called implicit regularization or implicit bias, but it is a property to analyze under stated conditions. The minimum-norm selection used in Belkin et al., Section 2 provides one concrete case. A good next experiment changes one such choice at a time while holding the evaluation protocol fixed.
Make a prediction, then check
Across global optima of the same penalized objective family, what does increasing λ guarantee?
Learning objectives
- Compare exact L1,L2 and early-stopping effects and explain why a common penalty coefficient need not make them equivalent.
- Distinguish global-optimum training monotonicity from test performance, checking scale, intercept and optimizer conventions.
Prerequisites & connections
Explore related knowledge →References
- Deep Learning — Chapter 7: Regularization for Deep Learning
Ian Goodfellow; Yoshua Bengio; Aaron Courville · 2016 - Cornell CS4780 Spring 2024 — Lecture 11: Model Selection
Cornell University · 2024 - Decoupled Weight Decay Regularization
Ilya Loshchilov; Frank Hutter · 2019 - Reconciling modern machine learning practice and the bias-variance trade-off
Mikhail Belkin; Daniel Hsu; Siyuan Ma; Soumik Mandal · 2019
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-05 · Codex technical check: source locations, independent numerical verification and full bilingual rereading; some drafts by an agent reviewed by the parent; no independent human peer review.
- Verified30 exact3D L1/L2 solutions with KKT and multidirectional perturbations; independently checked penalty monotonicity and the constraint direction on nonconvex finite candidate sets.
- Stepwise updates match closed spectral filters; the two-step point requires distinct ridge coefficients49/15 and4/3. Also checked units, threshold boundaries, invalid inputs and nonisotropic decay differences.
- The parent executed all19 independent learning-theory/neural tests. Structure checks compare bilingual anchors,display equations,code and sources; parent reread four answers and arguments. Historical articles make no code-execution claim.
Source locations checked:
- Deep Learning — Chapter 7: Regularization for Deep Learning · Official HTML text retrieved directly after reader size limit; §§7.1.1–7.1.2,7.2,7.4,7.8, including checkpoint algorithm and quadratic filters. Own loss includes1/2 consistently; did not copy the factor mismatch between7.15 and7.17. No universal converse penalty/constraint claim.
- Cornell CS4780 Spring 2024 — Lecture 11: Model Selection · Lecture11, tuning split and early stopping sections. Replaced informal by-hand hyperparameter language with explicit validation selection; no exact bias/variance diagnosis from two loss numbers.
- Decoupled Weight Decay Regularization · v3 Section2, equations/algorithms1–2 and appendix proof7–8. Checked simple nonisotropic preconditioning counterexample; no adoption/performance extrapolation or paper-training replication.
- Reconciling modern machine learning practice and the bias-variance trade-off · v2 Section2: among multiple random-feature ERM solutions use minimum coefficient norm; cited as one specified implicit-selection example.
Related topics