The Modern Mathematics of Deep Learningexplained for non-mathematicians

Batch normalization

Penguin learning project

The project uses 342 complete Palmer penguin records: 240 training-pool and 102 held-out rows. The selected training rows determine feature scaling and model parameters. Source CSV

This project trains weights with softmax, unlike the homepage lab, which uses nearest species averages. Same penguin measurements; different classification methods. Predictions can differ.

Batch normalization · Describe batch normalization and its derivatives.

The project uses a linear rule with two features. The fitted weights produce scores or normalized mass.

Consider this concept alongside the project; its source assumptions may differ. These observations do not prove a theorem.

Input: 12 × 2; Held-out evaluation: 102 · #58 · 40.6 mm, 193 mm. Known answer: Adélie; Prediction: Adélie · [≈0.7383, ≈0.2444, ≈0.01737].

Used in these source sections: 6.4 Adjusting the scale

Find the batch mean and standard deviation. Subtract the mean, divide by the standard deviation, then scale and shift.

Normalization changes the scale of a batch before later computation.

Source formula example

BNb(β,γ)(y)≔γ y−μbσb+β,y∈Rn,withμb=1m∑i=1my(i)andσb2=1m∑i=1m(y(i)−μb)2,\mathrm{BN}_{{b}}^{(\beta,\gamma)}(y)\coloneqq\gamma\,\frac{y-\mu_{b}}{\sigma_{b}}+\beta,\quad y\in{\mathbb{R}}^{n},\quad\text{with}\quad\mu_{b}=\frac{1}{m}\sum_{i=1}^{m}y^{(i)}\quad\text{and}\quad\sigma_{b}^{2}=\frac{1}{m}\sum_{i=1}^{m}(y^{(i)}-\mu_{b})^{2},

exact · The result is exact for these finite toy inputs, apart from ordinary computer rounding.

Symbols

μbμ_b
Mean of the batch.
σbσ_b
Standard deviation of the batch, nonzero for division.
β,γβ,γ
Real shift and scale.

Source formula example

This source example uses its own inputs and assumptions. Editing it does not change the project.

Edit a value or the code, then run the example. This is a finite demonstration, not a proof of the paper’s theorem.

This example’s data flow

You choose

  • input.gamma = 1
  • input.y = 2
  • input.beta = 0

Initial values in code

  • batch = [1, 2, 3]

Calculated here

Result expression: { mean, variance, standardDeviation, normalized: (input.gamma * (input.y - mean)) / standardDeviation + input.beta, }

  • mean = batch.reduce((a, b) => a + b, 0) / batch.length Uses: batch
  • variance = batch.reduce((a, y) => a + (y - mean) ** 2, 0) / batch.length Uses: batch, mean
  • standardDeviation = Math.sqrt(variance) Uses: variance

Returns

Example result
mean
2
variance
≈0.6667
standardDeviation
≈0.8165
normalized
0

Read numbers from input and return the result. JavaScript basics.

Result

Enable JavaScript to run this example.

Technical statement

This uses the source formula without an added epsilon. It rejects a zero standard deviation. The source also describes vector-valued batches; this toy shows one coordinate.

Source: Source expression