The Modern Mathematics of Deep Learningexplained for non-mathematicians

Squared loss

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.

Classification predicts three species; Ridge predicts body mass in grams using the same observations. These are separate models. Training predictions feed the objective; 102 separate test predictions never update the weights.

Individual losses · Give one observed example a loss score.

Project predictions and known answers produce losses. Classification uses cross-entropy and α/2 times squared non-bias weights; Ridge uses normalized-mass MSE and α times all squared coefficients, including the intercept.

Loss

Input
Training: 12 Prediction
Output
[≈0.005482, ≈1.012, ≈0.1422] … (12 entries) · Mean training loss: ≈0.228 (cross-entropy)

Project operation

The project calculation uses these records; the source formula and example follow below. Code edits run locally; project settings travel between pages.

Prediction → Loss → Mean training loss

Project input

Showing first three entries; the operation receives the complete array. Rounded preview; the operation uses full precision.

input.task · Project settings or constant
classification
input.predictions · Prediction
[Species: Adélie · Probabilities: [≈0.9945, ≈0.005412, ≈0.00005477], Species: Adélie · Probabilities: [≈0.6338, ≈0.3635, ≈0.002677], Species: Gentoo · Probabilities: [≈0.1023, ≈0.03028, ≈0.8674]] … (12 entries)
input.targets · Observations
[0, 1, 2] … (12 entries)

Result

[≈0.005482, ≈1.012, ≈0.1422] … (12 entries)

Used in these source sections: 1.2 Learning from examples · 2.1 A view through similarity

Subtract the target from the prediction, then square the difference.

Loss measures how far a prediction is from a target.

Source formula example

ℓ(y^,y)=(y^−y)2\ell(\hat{y},y)=(\hat{y}-y)^{2}

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

Symbols

y^\hat y
A real prediction.
yy
A real target.

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.prediction = 3
  • input.target = 1

Calculated here

Result expression: { error, loss: error ** 2 }

  • error = input.prediction - input.target Uses: input.prediction, input.target

Returns

Example result
error
2
loss
4

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

Result

Enable JavaScript to run this example.

Technical statement

Change the input and run the same code again. The displayed result uses the values shown above.

Source: Source expression