5.6.3 · D3Machine Learning (Aerospace Applications)

Worked examples — Regularization — L1 (lasso), L2 (ridge), dropout

2,968 words13 min readBack to topic

This page is the practice arena for the parent topic. We already built the three tools — L2 (ridge), L1 (lasso), dropout — from first principles. Here we run them by hand through every situation you can meet: every sign, the tricky exactly-at-zero case, the two limits and , a real aerospace word problem, and an exam-style twist.

Nothing new is assumed. If a symbol shows up, it was defined in the parent note; but we re-state each one the moment we use it, so you can start reading from line one.

Two symbols we lean on constantly:

  • (eta) = learning rate, the size of one gradient step. Think "how big a stride."
  • (lambda) = regularization strength, how hard we penalize big weights. Think "how strict the teacher is."

The scenario matrix

Every cell below is a kind of situation the topic can throw at you. Each worked example is tagged with the cell(s) it covers, so by the end every cell is filled.

# Cell (case class) Tool Covered by
A Positive weight, gentle shrink L2 Ex 1
B Negative weight, sign handled L2 Ex 1
C Limit (no reg) L2/L1 Ex 2
D Limit (over-shrink / overshoot) L2 Ex 2
E Small weight → crosses zero (soft threshold) L1 Ex 3
F Large weight → shrinks but survives, both signs L1 Ex 3
G Degenerate input exactly (subgradient) L1 Ex 4
H Geometry: why L1 corner = sparsity L1 vs L2 Ex 5
I Dropout expectation / scaling both conventions Dropout Ex 6
J Real-world word problem (choose the tool) all Ex 7
K Exam twist (L1+L2 = elastic net, hidden trap) mixed Ex 8

Example 1 — L2 on a positive and a negative weight (cells A, B)

Forecast: guess before computing — the positive weight should get smaller (toward 0), the negative weight should get less negative (also toward 0). Regularization always pulls toward zero. Hold that prediction.

The recipe (from the parent's L2 formula):

Step 1 — compute the shrink factor . Why this step? This single number is the whole soul of L2: before we even look at the data, every weight is scaled to of itself. That is "weight decay."

Step 2 — apply it to . So . Why this step? The shrink () is proportional — a big weight loses a big chunk. Then the data gradient nudges it down a touch more.

Step 3 — apply it to . So . Why this step? Notice the sign is handled automatically — the shrink factor multiplies whatever sign the weight has, so becomes (closer to zero, not further). No special case needed for negatives in L2.

Verify: Both moved toward zero: and . Matches the forecast. The bigger weight decayed by , the smaller by — proportional, as promised. Units: weights are dimensionless model coefficients, so all terms are dimensionless. ✓


Example 2 — the two L2 limits (cells C, D)

Forecast: With nothing should move. As grows the weight is dragged harder toward zero. But is there a so big it overshoots? Guess yes — and think about what would signal that.

Since the data gradient is , the update is purely .

Step 1 — (cell C). Why this step? With no regularizer the model is untouched — this is the baseline the parent warned overfits.

Step 2 — . Why this step? A healthy shrink: of the weight survives each step, so over many steps it decays smoothly toward .

Step 3 — (cell D, the danger zone). Why this step? The shrink factor went negative. The weight didn't shrink — it flipped sign and stayed size ! With an even larger the factor and the weight explodes. This is the practical meaning of "": the update becomes unstable unless .

Verify: The stability rule is , i.e. . Check: (edge, no motion), ✓ inside, exactly on the unstable edge, giving the sign flip we saw. The parent's claim " weights shrink to zero" is the ideal fixed point — but only reachable if is small enough to keep . ✓


Example 3 — L1 soft-thresholding, small vs large, both signs (cells E, F)

Forecast: L1 subtracts a fixed amount toward zero. Guess which weights survive: a weight smaller than can't survive; one much larger will just get shaved off.

The parent's soft-threshold formula:

Step 1 — (cell E, exactly at the threshold). Why this step? Its magnitude equals the step, so it lands exactly on zero and is selected out. This is L1's automatic feature selection in action.

Step 2 — (cell E, negative, below threshold). Why this step? Without the guard the weight would flip to positive — a bogus overshoot. The clamps it to exactly zero. The correctly handled the negative input.

Step 3 — (cell F, large, survives). Why this step? A big informative weight just loses the fixed — it survives and keeps doing its job. Contrast with L2, which would have taken a proportional () off it.

Verify: Two of three weights hit exactly zero (sparsity!), the large one shrank by exactly . Sanity: sum of absolute weights fell from to , a drop of , and (can't drop more than the total available step). ✓


Example 4 — the degenerate case exactly (cell G)

Forecast: The parent noted is undefined at (the diamond has a sharp corner there). So what do we plug in? Guess: the penalty should "resist" the data gradient rather than push a definite direction.

Step 1 — recall the subgradient at zero. At the slope of isn't a single number; it's any value in the interval . This set is called the subgradient. Why this step? Because the corner has many tangent lines, not one — we must reason with the whole interval, not a point.

Step 2 — check whether the data gradient can escape the penalty. The weight leaves zero only if the data gradient is strong enough to beat the maximum penalty pull . Here . Why this step? Inside the interval the penalty can exactly cancel the data gradient by choosing subgradient … — more simply, since , some subgradient value makes the total gradient zero.

Step 3 — conclude the weight stays put. Why this step? A weight already zeroed by L1 stays zeroed unless its data signal exceeds . This is exactly why L1 gives stable sparsity — features don't flicker back on for weak signals.

Verify: Threshold check: needs to activate; false, so weight stays . If instead the data gradient were , one step would give , i.e. the weight would finally leave zero. ✓


Example 5 — geometry: why the L1 diamond makes zeros (cell H)

Forecast: Picture the ellipse growing outward until it first touches the budget region. Where does it touch a circle vs a diamond? Guess the diamond gets touched at a pointy corner.

Figure — Regularization — L1 (lasso), L2 (ridge), dropout

Step 1 — read the L2 (circle) side, left panel. The budget is the round region. The expanding ellipse (data loss) touches it on a smooth arc, at a point where both and are nonzero. Why this step? A smooth boundary has no preferred direction, so the tangency lands wherever the ellipse leans — generically off-axis. Result: all weights small, none exactly zero.

Step 2 — read the L1 (diamond) side, right panel. The budget is the diamond. Its corners lie on the axes (where one coordinate is zero). The ellipse, expanding, very often first bumps a corner. Why this step? Corners stick out toward the ellipse and cover a whole range of ellipse orientations, so tangency at a corner is likely. At that corner one coordinate is exactly zero → sparsity.

Step 3 — connect to the update rule. This geometry is the same story as Example 3's soft-threshold: the constant push is what drives a coordinate all the way onto the axis.

Verify: Corner of the diamond on the -axis is — one coordinate exactly . For a circle the only axis points are isolated; a generic tangent line touches off-axis. ✓ (algebraic check in VERIFY)


Example 6 — dropout expectation, both scaling conventions (cell I)

Forecast: "Keep probability" is . Guess the expected surviving signal is for classic dropout, and that inverted dropout is engineered to give back the full .

Step 1 — classic dropout, training expectation. Why this step? On average of forward passes keep the neuron; the mean signal is scaled down to .

Step 2 — classic dropout, test time correction. At test we keep the neuron always, so to match training's expected we scale by : Why this step? Test must see the same average magnitude the next layer was trained on, or every activation would be too big.

Step 3 — inverted dropout, training scaling. When kept, divide by : Why this step? By pre-inflating during training, the expectation is already the full , so test time needs no scaling — which is why modern frameworks use it.

Verify: Classic: train mean , test output — matched ✓. Inverted: train mean , test output — matched ✓. Both conventions give identical test behaviour ( effective vs full is a re-parameterization; the ratio to downstream weights is consistent). ✓


Example 7 — real-world: pick the right tool (cell J)

Forecast: Sparsity + interpretability screams one tool; overfitting in the deep net screams another. Guess: L1 on the sensor-selection linear layer, dropout inside the CNN.

Step 1 — sensor selection → L1. Why? From Ex 3, L1 zeroes weak weights exactly, so the 45 useless sensors get coefficient and drop out of the model. This gives the interpretable "which 5 sensors" answer engineers asked for. Ties to Feature Engineering.

Step 2 — smooth stable coefficients on the survivors → optionally L2. Why? Among the surviving 5 sensors we don't want any single coefficient to blow up (Ex 1's proportional decay), so a light L2 keeps them well-conditioned.

Step 3 — deep CNN overfitting → dropout. Why? From Ex 6, dropout breaks co-adaptation so the CNN can't memorize training-flight noise. It behaves like averaging many sub-networks — related to Ensemble Methods.

Step 4 — pick / honestly. Why? Neither strength is known a priori; sweep them with Cross-Validation and watch the gap between train and test loss (Overfitting Detection).

Verify: Sanity on counts: L1 with a moderate that keeps 5 of 50 features means zeros — consistent with the parent's Example 2 vector having 45 zeros. Dropout on FC layers matches the parent's fault-detection CNN. ✓


Example 8 — exam twist: elastic net trap (cell K)

Forecast: Two forces at once — proportional L2 shrink and constant L1 push. Guess: apply the L2 factor first, then the L1 soft-threshold on the result.

The combined update (data gradient ):

Step 1 — apply the L2 shrink factor. Why this step? L2 is proportional, so it acts multiplicatively first, giving .

Step 2 — apply the L1 soft-threshold to that result. Why this step? Now subtract the constant L1 step. Both pulls toward zero, but neither alone reached zero, so the weight survives at .

Step 3 — spot the trap. If you (wrongly) applied L1 first: , then . Different answer! The convention is L2 shrink then L1 threshold, giving . Why this step? Because the L1 is nonlinear, order matters — the classic exam gotcha.

Verify: Correct order gives ; wrong order gives ; they differ, confirming order-sensitivity. Both pull the weight down from (elastic net = "L1 sparsity flavor + L2 stability"). ✓


Recall Self-test (reveal after answering)

L2 step on , data grad , , gives what? ::: L1 step zeroes when equals what value? ::: For L2 stability, must stay below what? ::: Inverted dropout with : a kept neuron of value becomes? ::: Elastic-net order (which penalty first)? ::: L2 shrink, then L1 threshold

Related deep-dive links: Gradient Descent Variants (how interacts with these updates), Neural Network Architectures (where dropout layers sit), Bayesian Inference (L2 = Gaussian prior, L1 = Laplace prior — the probabilistic story).