THE MATHS / LEARNING NOTES
Advanced exercises: make a prediction, then test it
Read Beyond XOR first. Use a new output directory for every run. Keep an experiment notebook with your settings, prediction, measured result, and explanation. There is no promised score to reproduce across every platform and dependency version.
Use validation results to choose settings. Inspecting and selecting repeatedly by test scores turns the test partition into development data.
Questions and experiments
1. Catch a preprocessing leak
The training values of one feature are
- Calculate the training mean and population standard deviation.
- Transform the value 100 using those training statistics.
- Explain what information leaks if you calculate the mean of all four values before splitting the data.
- Should the trained model's weights change if only the held-out value changes from 100 to 1000?
2. Count updates, not just epochs
With 600 balanced examples, a 60/20/20 split, and a training batch size of 32:
- How many training rows are there?
- How many optimizer updates occur in one complete epoch?
- How many rows does the final batch contain?
- After ten full epochs, what is Adam's update counter
?
Compare batch sizes 16 and 128 with all other options fixed:
python -m neural_math_lab experiment --batch-size 16 --seed 7 --output runs/batch-16
python -m neural_math_lab experiment --batch-size 128 --seed 7 --output runs/batch-128
Do equal epoch budgets also give equal update budgets? Record the actual stopping epochs before interpreting the curves.
3. Separate data loss from regularization
Consider weights
- Calculate the L2 penalty in this lab's objective.
- Give the extra gradient for each weight.
- Give the extra gradient for each bias.
- If the data cross-entropy is 0.4, what is the training objective? What loss would the validation plot show if validation cross-entropy were 0.5?
Then compare --l2 0 with --l2 0.05. Use the same dataset and seed. Predict how
the boundary and weight magnitudes might change, and report the actual outcome
without assuming validation must improve.
4. Explain an Adam step that follows the current gradient
Reproduce the two-step example from the guide:
- Compute both bias-corrected moment estimates at step 2.
- Why does the parameter decrease even though the current gradient is negative?
- What would two ordinary SGD updates do for that supplied gradient sequence?
- Is the Adam time counter reset to zero at every epoch?
As an experiment, compare --optimizer adam --learning-rate 0.01 with
--optimizer sgd --learning-rate 0.05. Treat this as two specified configurations,
not proof that one optimizer is always better. Give each a new output directory.
5. Read a confusion matrix and probability score
Suppose a held-out confusion matrix is
Calculate accuracy, precision, recall, and
6. Distinguish the best epoch from the final executed epoch
Imagine validation losses at epochs 0 through 6 are:
0.70, 0.55, 0.40, 0.42, 0.405, 0.41, 0.43
With patience 3 and min_delta=0, when should training stop, and which epoch's
parameters should be returned? If an implementation returns the last executed
weights instead, what selection rule has it violated?
Run one experiment with --patience 20 and another with --patience 100, keeping
everything else fixed. Check best_epoch and stopped_epoch; they need not be
equal. Do not assume larger patience always finds a better validation loss.
7. Investigate capacity and geometry
Run circles with two hidden neurons, then with 16:
python -m neural_math_lab experiment --dataset circles --hidden 2 --seed 7 --output runs/circles-small
python -m neural_math_lab experiment --dataset circles --hidden 16 --seed 7 --output runs/circles-wide
Compare the boundaries, training losses, validation losses, selected epochs, and logistic baseline. Count the trainable parameters in each neural network. Why can increasing width help represent curvature while also increasing the opportunity to fit incidental details? Is a better training score sufficient to select the wider model?
8. Design a result you could defend
Before running anything, choose three seeds, two hidden widths, and a fixed dataset/noise configuration. State your selection rule using validation loss.
Record every attempted configuration, including failures. Summarize variation across seeds rather than showing only the best run. Explain why different seeds can change both data generation and optimization, so they are repeated complete experiments rather than a clean measurement of initialization alone.
Once you have looked at all corresponding test scores, can you honestly describe the best score among them as an untouched final evaluation? What additional evaluation would you need for a stronger claim?
Answers and checks
1. Training statistics
The mean is 2; the population variance is
Using all four rows would make the mean 26.5, allowing the held-out example to change the representation on which training occurs. The correct training parameters must not change when only a test coordinate changes, because that coordinate does not participate in fitting or validation selection. Its final prediction and test metrics can change.
2. Update counts
There are 360 training rows. An epoch has
3. Penalty and gradients
The squared weight sum is
There is no fixed numerical answer for the experiment. Larger L2 encourages smaller weights, but the resulting nonlinear training path and validation score must be measured. Do not call an unobserved improvement a result.
4. Adam versus SGD
At step 2,
The counter advances at every update and is not reset at epoch boundaries. Resetting it while retaining the moment buffers would apply inconsistent bias corrections.
5. Metrics
- Accuracy:
. - Precision:
. - Recall:
. : .
The first pair's Brier score is
6. Checkpoint selection
The minimum occurs at epoch 2. Epochs 3, 4, and 5 provide three consecutive non-improvements, so training stops after epoch 5 and restores epoch 2's parameters. Epoch 6 would never be reached under this rule. Returning epoch 5 would report a model other than the one selected by lowest validation loss.
With positive min_delta, small improvements affect the patience rule; see
the exact distinction in the guide. Always inspect both the selected epoch and
the stopping epoch.
7. Capacity
With hidden width
8. Defensible reporting
Choose settings using validation performance and retain the complete experiment record. A final evaluation needs data not used directly or indirectly in those choices. After repeatedly inspecting test results and selecting the best, a fresh independently generated evaluation set would be needed to recover an untouched assessment for this synthetic task. Even that would support a claim about this data-generating process, not arbitrary real-world data.
Experiment record
| Dataset/noise | Seed | Width | Optimizer/rate | L2 | Batch | Best/stopped epoch | Validation loss | What changed? |
|---|---|---|---|---|---|---|---|---|
Keep the final test comparison in a separate section of your notes. Explain the observed difference from logistic regression and any remaining uncertainty.