THE MATHS / LEARNING NOTES
Exercises: predict, run, explain
Work through these after the mathematics guide. For each experiment, write your prediction before running the code. Then record what actually happened and explain any difference. Use different output directories for training runs so you can compare their artifacts.
Questions
1. Count the parameters
How many trainable values does a network with 2 inputs, 3 hidden neurons, and 1 output have? Give the shape of each parameter array. Are the four target labels parameters?
2. Read a matrix multiplication
With
calculate
3. Predict an update's direction
For one example with target 1 and predicted probability 0.25, what is
4. Average exactly once
Suppose you duplicate the complete four-row XOR batch, producing eight rows. Without changing the parameters, what should happen to the mean loss and the gradients? What bug would be exposed if the gradients doubled?
5. Compare learning rates
Keep the seed, width, and epoch count fixed. Compare learning rates 0.05, 0.5, and 5.0:
python -m neural_math_lab train --seed 7 --epochs 4000 --learning-rate 0.05 --output runs/rate-005
python -m neural_math_lab train --seed 7 --epochs 4000 --learning-rate 0.5 --output runs/rate-05
python -m neural_math_lab train --seed 7 --epochs 4000 --learning-rate 5.0 --output runs/rate-5
Record each final loss and the number of correctly classified XOR rows. Look at the curves, not just the last number. Does “ten times the learning rate” imply “ten times faster learning”? Must the loss decrease at every epoch?
6. Remove the hidden nonlinearity on paper
Replace
7. Start every parameter at zero
Set all four parameter arrays to zero and consider a full XOR batch. Calculate the hidden activations, output probabilities, and all gradients. What changes after one update? How does a balanced label count matter here?
You can check your answer directly:
from neural_math_lab.core import Network, xor_data
net = Network(hidden=4, seed=7)
for values in net.parameters.values():
values.fill(0.0)
X, y = xor_data()
print(net.forward(X))
print(net.gradients(X, y))
8. Study a saturated hidden neuron
Evaluate
9. Check a gradient independently
Reproduce the hand example in the guide. Perturb W1[0, 0] by net.gradients(X, y)["W1"][0, 0] before taking a training step.
10. Describe the result precisely
A run classifies all four XOR rows correctly. Write one accurate sentence
describing that result. Then explain why a prediction at
Answers and checks
1. Parameter count
W1 has shape (2, 3) and 6 values; b1 has (1, 3) and 3; W2 has
(3, 1) and 3; b2 has (1, 1) and 1. Total: 13. Targets are fixed data.
For hidden width
2. Matrix multiplication
3. Update direction
For a one-row batch,
4. Duplicated batch
The mean loss and all gradients are unchanged, up to floating point rounding. Both the sum of contributions and the number of rows double. Doubled gradients would suggest a sum loss or a missing division by the batch size. This check is particularly useful because the implementation is meant to use a mean loss.
5. Learning-rate experiment
There is no fixed numeric answer supplied for this experiment: report your actual run, including settings. A larger step follows only a local linear approximation and may overshoot, oscillate, or enter a different region of the loss surface. A small step can make slower progress. Large rates are not guaranteed to fail, and a loss curve is not guaranteed to be monotonic.
6. No hidden nonlinearity
This is still one affine map of the two inputs. Sigmoid is monotone and its 0.5 threshold corresponds to a zero logit. Therefore the classification boundary remains a straight line, regardless of hidden width, and cannot perfectly classify XOR.
7. All-zero initialization
db2 is zero. Because dW2 is zero. Because
For an unbalanced batch, db2 could move to reflect the class proportion, but
this all-zero construction would still not distinguish the input patterns.
More generally, identical hidden units with identical outgoing weights receive
identical gradients and remain identical. Random weight initialization breaks
that symmetry. Zero biases alone do not cause this problem.
8. Saturation
At zero,
For the combined output loss,
9. Gradient check
The derivative is approximately -0.2234265841 in the guide's hand example. Both the numerical and analytical calculations should be close to this value. If you get a different result, first check that you used a one-row batch, the specified weights, and parameters from before the update. Restore the perturbed parameter even when an assertion fails.
10. Honest reporting
For example: “With the recorded settings, this network correctly classifies all
four XOR training examples.” All four rows participated in optimization, so
this is not accuracy on held-out data. The Boolean XOR truth table defines no
label for
A short experiment log
Copy this table into your notes and fill it with actual runs:
| Seed | Hidden width | Learning rate | Epochs | Final loss | Correct XOR rows | What I learned |
|---|---|---|---|---|---|---|
| /4 |
Before calling an experiment finished, explain in your own words what
(p - y) / len(X) means, why W2.T appears in the backward pass, and why
training accuracy alone does not establish generalization.