Explanation of the Neural Network Simulator — What the Coloring and the Line Thickness Compute
This page explains what the “Answer map,” the “line thickness,” and the “motion of the signal and the mistake” seen in the simulator correspond to in the language of neural networks, and by what formulas they are computed, in the order words → formulas → calculation procedure. The procedure for the detailed view, the conditions of the calculation, and questions for checking are also collected here.
The Neural Network Simulator is a device for watching how a small network with one hidden layer and one output looks at data and fixes its weights little by little. It covers the content of Chapter 14 (representations in neural networks) and Chapter 15 (backpropagation and learning).
The simulator has two views.
Simple view (the view shown when the page opens): In Scene A, you watch a network that colors red and blue points change the thickness of its lines as it learns, so that its coloring comes to match the colors of the points. In Scene B, for a single point, you watch, one stage at a time and with motion, a signal flow from the input to the output, the gap from the correct answer go back from the output toward the input, and the lines get fixed a little. No formulas are shown.
Detailed view: The view embedded in Chapters 14 and 15 of the text. In ① (following one step of a 2–2–1 network numerically), ② (watching training: regression and three kinds of classification, learning curves, outputs of the hidden units), and ③ (gradient checking), you check numbers and formulas. The procedures in “Simulator 14.1,” “14.2,” “15.1,” “15.2,” and “15.3” in the text are written for this view.
Scene A of the simple view performs the same calculation as the classification (concentric circles, two moons, XOR) in ② of the detailed view, and Scene B the same calculation as ① of the detailed view. We recommend reading in this order: try the simple view, check what it really shows in Section 2, read the formulas in Section 3, and operate the detailed view with the procedure in Section 4.
2. What the simple view really shows
The “lines” in the simple view are the weights of the network, and the “balls” are the units (neurons). The values of the input balls are multiplied by the weights of the lines and added (a weighted sum), and the result passed through the activation function becomes the value of the next ball (Sections 14.1 and 14.3 of the text). A line is drawn thicker the larger the absolute value |w| of its weight; positive weights are drawn as solid lines and negative weights as dotted (dashed) lines. This is the same convention as in the figure of ① in the detailed view. The “Answer (redness)” is the value ŷ of the sigmoid in the output layer and can be read as “the probability that this point is red (y = 1),” p(y = 1 | x).
“Learning” means moving all the weights little by little in the direction that makes the loss (the size of the mistakes) L on the training data smaller. “Mistake returns” means computing the partial derivatives (gradient) ∂L/∂w of the loss with respect to the weights in order from the output side, which is backpropagation (Section 3).
2.1 Scene A: Can a network separate points of two colors?
Red points (y = 1) and blue points (y = 0) placed on a plane are learned by a network with 2 inputs, H hidden units, and 1 output (2–H–1). The “Answer map” on the right shows, at each point x = (x1, x2) of the plane, the shading of the network output ŷ(x) (the same colors as in the classification figure of ② in the detailed view), and the black line is the contour ŷ = 0.5, that is, the decision boundary.
Table 1: Words on the screen in Scene A and the corresponding terms and symbols
Words on the screen
Term
Symbol or formula
(point position), Input, ↔ ↕
input (two-dimensional)
x = (x1, x2)
red points ● / blue points ▲
class (target value)
y = 1 / y = 0
How the points are arranged: Ring / Moons / Diagonal
synthetic data for teaching purposes: concentric circles / two moons / XOR
the same generating formulas as the tasks in ② of the detailed view (Section 5.1)
Lines, line thickness
weights, absolute value of a weight
, , |w|
solid / dotted line
positive weight / negative weight
w > 0 / w < 0
Middle balls, Number of middle balls (hidden units)
hidden units (activation function tanh), number of hidden units
zj = tanh a(1)j, H = 1, 3, 8
pattern in ball
the output of a hidden unit drawn on the input plane (light = close to −1, dark = close to +1)
zj(x)
Answer (redness), Answer map
output (sigmoid), its shading
ŷ(x) = σ(a(2))
black line = border
decision boundary
ŷ = 0.5, that is, a(2) = 0
gray dotted = before the press
the decision boundary before the button was pressed
—
Times learned (1 time)
epoch (using the 100 training data points once each; 13 updates with minibatches of 8)
⌈100/8⌉ = 13
Points colored correctly
accuracy on the training data (answers red if ŷ ≥ 0.5)
number correct out of 100
Correct on new points
accuracy on the validation data (200 points not used for learning)
number correct out of 200
Start over with other data
change the data seed and the random-number seed
both 20261112 + k
The output of middle ball j, on the input plane, has the form
tanh is a step that changes smoothly from −1 to +1, so zj(x) is a “ridge”-like function that approaches −1 on one side of the straight line wjTx + b(1)j = 0 and +1 on the other side (Section 14.5.2 of the text). The edge between light and dark in the pattern inside a ball is this straight line. The output is the value obtained by multiplying these by the weights W(2)j, adding them, and passing the sum through the sigmoid:
With one ball (H = 1), ŷ is a monotonic function of a(1)1 alone, so the set of points where ŷ = 0.5 is a straight line on which a(1)1 takes a constant value (when |b(2)/W(2)1| < 1; otherwise the whole plane becomes one color):
This is why the border stays straight no matter how much the network learns, and it is the same reason that a single neuron cannot separate XOR (Section 14.4.2 of the text). With two or more balls, several ridges with straight edges are added together, so curved borders and closed borders can be made.
Numbers for “Try it” (all under the conditions when the page opens: data seed and random-number seed 20261112, learning 300 times):
Right after opening (0 times learned, Ring, 3 balls): 37 % of the points colored correctly, 52 % on new points. This coloring is set by the random initial values and is not fitted to the colors of the points (depending on the arrangement and the seed, it may happen to match many points or color them almost the opposite way; for example, 10 % for Moons with seed 20261112).
After pressing “▶ Learn” once (300 times): 97 %, 96 % on new points.
With 1 ball?: 71 % for Ring (54 % on new points). The border is a straight line.
With 3 balls?: 97 % for Ring (96 % on new points).
Diagonal pairs?: for Diagonal (XOR), 73 % with 1 ball (72 % on new points) and 100 % with 3 balls (193/200 = 97 % on new points).
The state after learning 300 times with Ring and 3 balls is the same as the state after 300 epochs of training in ② of the detailed view with the task set to “Concentric circles” and everything else at the defaults (accuracy: training 97.0 % / validation 96.0 %). If learning is continued to 2000 times (the button in the simple view advances 300 times at a time, so exactly 2000 times can be checked in ② of the detailed view), the training data reach 100 %, but the new points fall to 92 % (the same calculation as the overfitting example in Section 15.5.2 of the text).
Where the analogy fits and where it does not
Where it fits: the line thickness is the absolute value of the weight, and solid and dotted lines show the sign of the weight, exactly as they are. The answer map is made by computing the network output ŷ at each point of a grid on the plane and coloring it, and the black line is the contour ŷ = 0.5. Learning calls the same functions as ② of the detailed view (makeTask, initNet, and trainEpoch in neural-net.model.js) in the same order, and with the same seed it gives the same weights (checked by tests).
Where it does not fit: the “balls” and “lines” are a diagram of the calculation and do not copy the workings of real nerve cells. The biases b also move during learning, but they are not drawn in the picture. The points are dimensionless synthetic data for teaching purposes, not real measured values. Also, a high share of points colored correctly does not guarantee that new data will also be answered correctly (as in the 2000-times example, continued learning can lower the share on new points).
Using the same 2–2–1 network as in Section 15.3 of the text (tanh hidden layer, sigmoid output, cross-entropy loss) and one data point x = (1.0, 0.5), y = 1, one step of learning is shown in four stages. The initial weights are = ((0.5, −0.3), (0.8, 0.2)), = (0.1, −0.1), = (1.0, −1.0), b(2) = 0.2, and the learning rate is η = 0.5.
Table 2: Words on the screen in Scene B and the corresponding terms and symbols
Words on the screen
Term
Symbol or formula
Input balls 1.0, 0.5
input
x = (1.0, 0.5)
Correct answer for this point (its true color): Red / Blue
target value
y = 1 / y = 0
① Signal flows
forward propagation
, ,
Answer (redness)
output (predicted value)
ŷ = 0.489467
② Compare, Gap from the correct answer
error of the output layer (the pair of sigmoid and cross-entropy)
δ(2) = ŷ − y = −0.510533
③ Mistake returns
backpropagation (errors and gradients of the hidden layer)
δ(1), ∂L/∂w
orange thickness = how much that line is fixed
size of the gradient (the amount actually moved is η times it)
|∂L/∂w|
④ Fix the lines
weight update by gradient descent
w ← w − η ∂L/∂w
thicker / thinner
the update increased / decreased the absolute value of the weight
|wnew| > |wold| / |wnew| < |wold|
Answer after fixing the lines
output of forward propagation for the same data with the updated weights
ŷ = 0.709008
Times the lines were fixed
number of updates (steps)
—
The amounts that come back in stage ③ are computed in order from the output side by the following formulas (the formulas of Section 3.2 for this device):
The key point is that the output-layer error δ(2) multiplies every gradient. The “gap” from the correct answer comes back, and each line is given “in which direction and by how much to fix it.” The orange thickness is drawn in proportion to |∂L/∂w| (line width 2 px + 22 × |∂L/∂w| px, at most 12 px).
Numbers for “Try it” (values checked by running trace in neural-net.model.js with Node; the same as Tables 15.1–15.3 and Example 15.3 in Section 15.3 of the text):
One full round?: answer 0.489467 (0.49 on the screen), gap −0.510533 (−0.51). After the lines are fixed, the answer for the same point becomes 0.709008 (0.71) (the gap after fixing is −0.290992; in stage ④ the screen shows “After fixing: −0.29”), and the loss falls from 0.714438 to 0.343888. The lines that get thicker are (0.5 → 0.709829) and (1.0 → 1.10770); the lines that get thinner are (−0.3 → −0.195085), (0.8 → 0.657292), (0.2 → 0.128646), and (−1.0 → −0.830494).
If the correct answer is blue?: the gap is +0.489467 (+0.49). The signs of all 9 gradients are the opposite of those for y = 1, and all weights and biases move in the opposite direction. The answer moves from 0.489467 to 0.272705 (0.27), toward blue (Example 15.3).
Repeat 5 times?: the answer goes 0.49 → 0.71 → 0.80 → 0.85 → 0.88 → 0.90, and the loss goes 0.714438 → 0.343888 → 0.225670 → 0.166949 → 0.132260 → 0.109492. The closer the answer gets to 1, the smaller |δ(2)| = 1 − ŷ becomes, and the sum of squared gradients ‖g‖2 also shrinks from 1.00151 to 0.282656 (just before the second update), so the amount moved in one round also becomes smaller.
Where the analogy fits and where it does not
Where it fits: “the signal flows from left to right” is exactly the order of the forward-propagation calculation (input → hidden layer → output), and “the mistake goes back from right to left” is exactly the order of the backpropagation calculation (δ(2) → δ(1) → gradients on the input side). The numbers are computed with the same function trace as ① of the detailed view.
Where it does not fit: no actual particles flow along the lines; the motion of the particles is staging to show the order of the calculation. The size and speed of the particles have no meaning. The update of the biases b is not drawn in the picture (it is included in the calculation). Also, this scene updates with a single data point, so the weights move in the direction that fits only that data point. When learning from many data points, the mean gradient over a minibatch is used (Scene A, Section 15.5 of the text).
3.1 In words: stack weighted sums and fix the weights with the gradient of the loss
A neural network arranges in layers the calculation unit (neuron) “form a weighted sum and pass it through an activation function,” and uses the output of one layer as the input of the next (Sections 14.1–14.3 of the text). This device is limited to one hidden layer and one output. For classification, the output layer is a sigmoid, the output ŷ is read as “the probability that y = 1,” and the loss for one data point is the cross-entropy
When the correct answer is 1, the loss is large if ŷ is close to 0, and close to 0 if it is close to 1. Learning means searching for the weights that make the mean loss L on the training data small, by gradient descent
(η is the learning rate; Chapter 7, Section 7.2 of the text). ∂L/∂w is needed for every weight, but the loss is a composite function “weighted sum → activation function → … → loss,” so using the chain rule in order from the output side lets us compute the common parts only once and hand out all the partial derivatives. This is backpropagation (Sections 15.1–15.2 of the text).
3.2 Formulas computed
A network with one hidden layer and one output. Input x ∈ ℝD, number of hidden units H, W(1) ∈ ℝH×D, W(2) ∈ ℝ1×H, activation function h(·) (tanh, ReLU, sigmoid).
The loss for one data point is the cross-entropy for classification (y ∈ {0, 1}) and half the squared error for regression. To avoid ln 0, the classification loss computes ln(1 + ea) in a form that does not overflow.
ℬ is the minibatch (a set of data indices) and λ is the weight-decay coefficient (not applied to the biases). Backpropagation finds δ ≡ ∂ℓ/∂a in order from the output side.
The minibatch gradient is the mean of the per-sample gradients plus λW. The update is gradient descent w ← w − η ∂L/∂w (η is the learning rate). At the start of each epoch the order of the training data is shuffled randomly, and the weights are updated for each minibatch of size B (with “All,” one update per epoch).
3.3 Calculation procedure
Set the initial values (Scene A and ②: Xavier normal random numbers for tanh and sigmoid, He for ReLU, biases 0; Scene B and ①: the weights of Section 15.3 of the text).
Forward propagation: for each data point, compute , , a(2), ŷ, and the loss ℓ, and store the intermediate values.
Backpropagation: starting from δ(2) = ŷ − y, use the stored z to find and each gradient.
Minibatch gradient: average the gradients within the minibatch and add the weight decay λW (λ = 0 in Scene A).
Update: w ← w − η ∂L/∂w. Scene B and ① update once with one data point. Scene A and ② shuffle the training data at the start of each epoch and update for each minibatch of 8.
Draw: in Scene A, compute ŷ on a grid over the plane (41 × 41 points for widths under 520 px, 61 × 61 points otherwise), color it, and draw the contour ŷ = 0.5. The pattern inside each ball is zj at 13 × 13 points.
The calculation in the simple view calls the same functions as the detailed view (makeTask, initNet, trainEpoch, forward, gridPredict, and trace in neural-net.model.js). The only things added for the simple view are the breaks for stopping learning partway to draw, the calculation that rounds the accuracy from counts to an integer percentage, the grid for the patterns inside the balls, and the calculation in Scene B that calls trace again with the fixed weights (repeat 5 times) (neural-net.easy.js).
3.4 Gradient check (③ in the detailed view)
In the gradient check in ③, from the loss with each parameter w alone moved by ±ε
we form these and compare them with the backpropagation value. The per-component relative error is |gbackprop − gdiff| / max(|gbackprop|, |gdiff|, 10−8), and the relative error as a vector is ‖gbackprop − gdiff‖ / max(‖gbackprop‖, ‖gdiff‖).
4. How to use the detailed view
The detailed view has three tabs: ① (following one step numerically), ② (watching training), and ③ (gradient checking). Each has the figure and the “Putting the current numbers into the formula” box on the left, and the controls and the readout on the right.
In ①, press “Forward.” What to look at: a(1) = (0.45, 0.8), z(1) = (0.421899, 0.664037), a(2) = −0.0421378, ŷ = 0.489467, L = 0.714438. Although y = 1, ŷ is below 0.5, so the loss is a little larger than ln 2 ≈ 0.693.
Press “Backward.” What to look at: the output error δ(2) = ŷ − y = −0.510533 is multiplied by the weights W(2) = (1.0, −1.0) and the tanh slope 1 − z2 and distributed to the hidden layer, giving δ(1) = (−0.419659, 0.285416). The sign of δ for hidden unit 2 is reversed because W(2)2 is negative.
Press “Update weights.” What to look at: each weight moves by −η∂L/∂w, and the loss falls from 0.714438 to 0.343888. If you repeat from “Forward” again, the loss falls further.
In ①, set the learning rate η to 5 and do the same. Next set y = 0. What to look at: when η is large, a single update overshoots. Changing y flips the sign of δ(2), and the signs of all gradients reverse.
In ②, press “Run” with the task left at “Regression (Data A),” and change the number of hidden units H to 1, 3, and 8. What to look at: in the lower figure, the hidden-unit outputs zj(s) are “moving basis functions” whose positions and slopes change as training proceeds. Switching to “Contribution” shows that their superposition is the prediction curve above. Data A is smooth, so with the default seed the training RMSE after 2000 epochs is 0.945, 0.927, and 0.919 % for H = 1, 3, and 8, about the noise standard deviation of 1 %, and the validation RMSE (1.24, 1.24, 1.22 %) hardly changes either. Increasing H increases the shapes that can be represented, but this data does not need them.
In ②, set the task to “Concentric circles” and train for about 2000 epochs (default H = 3). What to look at: the training loss keeps falling (0.0153 at 2000 epochs), but the validation loss reaches its minimum of 0.104 at epoch 806 and then starts to rise, reaching 0.360 at 2000 epochs (overfitting). Stopping at the epoch of minimum validation loss (◆) is early stopping. With H = 4 and the weight decay λ set to 0, 10−3, and 10−2, the validation loss at 2000 epochs is 0.342, 0.218, and 0.308; when λ is too large, the training loss also stops falling (0.0129, 0.0488, 0.214).
In ②, set the learning rate near its maximum and the minibatch to 1. What to look at: the loss oscillates, and when it diverges the computation stops and the reason is displayed. Set “Initial value” to “All 0” and run. What to look at: with tanh the weights stay at 0 and do not move, and the prediction is a constant (the mean of the training data). With sigmoid the weights do move, but every hidden unit keeps the same value, so increasing H does not increase the shapes that can be represented (symmetry).
In ③, vary ε from 10−12 to 10−1. What to look at: the error of the central difference is smallest near ε ≈ 10−5 (about 10−12); if ε is made too small the error grows because of rounding error, and if it is made too large the error grows because of truncation error (a V shape). On the large-ε side, the central-difference error grows with slope 2 and the forward difference with slope 1.
With the keyboard, Tab moves to buttons and sliders, Enter (or Space) presses a button, and the arrow keys move a slider. The tabs can be switched with ← and →.
5. Conditions of the calculation
5.1 Data and random-number conditions
① uses one data point (default x = (1.0, 0.5), y = 1) and the same weights as Chapter 15, Section 15.3 of the main text: W(1) = ((0.5, −0.3), (0.8, 0.2)) (the first row is hidden unit 1), b(1) = (0.1, −0.1), W(2) = (1.0, −1.0), b(2) = 0.2, and learning rate η = 0.5. No random numbers are used.
The regression in ② uses synthetic data for teaching purposes, “Data A (firing temperature and relative density)”: s ~ U(−1, 1), firing temperature T = 1300 °C + 200 °C × s, relative density y = g(s) + ε, g(s) = 88 + 8s − 5s2 + 2 sin 3s (%), ε ~ 𝒩(0, 1.02) (%). The number of training data points is 5 to 50 (default 20). Training uses the targets standardized by the training mean ȳ and standard deviation sy, (y − ȳ)/sy, and the figure is drawn after converting back to % (the loss is in standardized units). This is not data of a real material.
The classification in ② also uses synthetic data for teaching purposes (dimensionless 2D points, with y ∈ {0, 1} in equal halves). Concentric circles: a radius of 1.0 (y = 0) or 0.5 (y = 1) with 𝒩(0, 0.12) added, and a uniform angle. Two moons: y = 0 is (cos t, sin t) and y = 1 is (1 − cos t, 0.5 − sin t), t ~ U(0, π); subtract (0.5, 0.25) and add 𝒩(0, 0.12) to each coordinate. XOR: centers (±0.5, ±0.5), the quadrants with x1x2 > 0 are y = 1, and 𝒩(0, 0.22) is added to each coordinate. The number of training data points is 40 to 200 (default 100).
The validation data are a separate 200 points from the same distribution as the training data (a separate random-number stream). Changing the number of training data points does not change the validation data.
The random numbers come from a seeded generator (mulberry32). The “data seed” (default 20261112) determines the training and validation data, and the “random-number seed” (default 20261112) determines the initial weights and the minibatch order. Starting over with the same seed gives the same training history.
Initial values: for tanh and sigmoid, the Xavier (Glorot) normal distribution (variance 2/(fanin + fanout)); for ReLU, the He normal distribution (variance 2/fanin); the output layer uses Xavier; biases are 0. “All 0” can also be selected.
Computational limits: 16 hidden units and 5000 epochs. The ε figure in ③ has 34 points from 10−12 to 10−1.
5.2 Conditions fixed in the simple view
Scene A: the tasks are only the three kinds of classification (Ring = concentric circles, Moons = two moons, Diagonal = XOR); the regression (Data A) is not used. 100 training data points, 200 validation data points, tanh hidden layer, sigmoid output with cross-entropy, learning rate η = 0.1, minibatch 8, weight decay 0, and Xavier normal random initial values, the same as the defaults of ② in the detailed view. The number of hidden units is chosen from 1, 3, and 8.
Seeds in Scene A: the data seed and the random-number seed (initial values and minibatch order) are both 20261112 when the page opens; each press of “Start over with other data” changes them to 20261113, …, 20261116, and after 5 variations they return to the start.
“▶ Learn” in Scene A advances 300 epochs per press and stops at 3000 epochs. During the motion, a few epochs at a time are computed within 12 ms per frame, and the readout is rewritten when it finishes. The accuracy is “number correct × 100 / number of points” rounded to an integer (for example, 193/200 → 97 %).
Scene B: the same weights, input, and learning rate (η = 0.5) as in Section 15.3 of the text. Changing the correct answer starts over from the initial weights. The numbers on the screen are rounded to 2 decimal places.
Each time a “Try it” item is pressed, it clears the record of that scene and resets the conditions (Scene A keeps the data seed in use at that moment; the numbers in Section 2.1 are for seed 20261112). When the OS or browser is set to “reduce motion” (prefers-reduced-motion), the motion is skipped and only the result is drawn.
5.3 Simplifications
There is one hidden layer and one output (multiclass softmax is not treated).
The only optimizer is plain (stochastic) gradient descent. Momentum, Adam, learning-rate decay, and dropout are not used.
The training mean and standard deviation are used to standardize the regression targets (no information from the validation data is used).
The numbers in the figure of ① are rounded to 4 significant digits for display (the computation is in double precision; the table has 6 digits).
5.4 Conditions under which results become unstable
When the learning rate is large, the loss oscillates and diverges. When the loss becomes NaN or infinite, or exceeds 106, training stops and the reason is displayed. The smaller the minibatch, the larger the scatter of the gradient, and the more easily training becomes unstable even at the same learning rate.
When sigmoid is used in the hidden layer and the input weights grow large, h′ ≤ 1/4 becomes small and training slows down (the entrance to vanishing gradients). With ReLU, a unit that stays at a ≤ 0 has gradient 0 and no longer moves.
If the training data in classification can be separated perfectly, then without weight decay the weights keep growing and the training loss keeps approaching 0. The validation loss may rise (overfitting).
In the gradient check, if ε is made too small, the difference of L(w ± ε) is buried in rounding error (about 10−16 × L). For components whose gradient is inherently close to 0, the per-component relative error looks large (judge by the relative error as a vector). For an ε that straddles the ReLU kink a = 0, the difference is not the correct derivative.
If the initial values are all 0, then with tanh and ReLU, z(1) = h(0) = 0 gives ∂L/∂W(2) = 0, and W(2) = 0 gives δ(1) = 0, so none of the weights move (only b(2) moves, and the prediction is a constant). With sigmoid, W(1) moves, but every hidden unit keeps the same value.
6. Questions for checking
Questions 1 and 2 can be answered with the simple view alone. Questions 3–6 use the detailed view.
In Scene A of the simple view, with one middle ball the border stays straight no matter how many times the network learns. Why?
Sample answer
With one ball, the answer ŷ is determined only by a single weighted sum a(1)1 = W(1)11x1 + W(1)12x2 + b(1)1, and as a(1)1 increases, ŷ either only increases or only decreases. Therefore ŷ = 0.5 holds where a(1)1 takes one fixed value, that is, on a single straight line. Learning changes only the direction and position of the line. To surround only the inside of the ring, you need more balls so that several ridges with straight edges can be combined.
In Scene B of the simple view, when you press “Repeat 5 times?”, the answer approaches 1, but the amount it moves in one round gradually gets smaller. Why?
Sample answer
Because the output gap δ(2) = ŷ − y multiplies the amount by which every line is fixed. The closer the answer gets to the correct 1, the closer the gap gets to 0 and the smaller the amount that comes back (the gradient), so even at the same learning rate the amount moved in one round decreases. The sum of squared gradients falls from 1.00151 in the first round to 0.282656 in the second.
With the default values in ①, why are the signs of δ(1) for hidden units 1 and 2 opposite? Also, why is ∂L/∂W(1)12 exactly half of ∂L/∂W(1)11?
Sample answer
δ(1)j = (1 − zj2) W(2)jδ(2), and 1 − z2 > 0 and δ(2) = −0.510533 are common to both, so the sign is determined by W(2)j = +1.0, −1.0 (−0.419659 and +0.285416). ∂L/∂W(1)ji = δ(1)jxi, and x2/x1 = 0.5/1.0 (−0.209829 = 0.5 × (−0.419659)).
In ①, one update changes the loss from 0.714438 to 0.343888. When η is made very small, what determines how much the loss decreases?
Sample answer
By the first-order Taylor expansion, L(w − ηg) ≈ L − η‖g‖2, so the decrease is proportional to the square of the gradient magnitude, ‖g‖2 = 1.00151 (over all 9 parameters). The actual decrease at η = 0.5, 0.370550, is smaller than 0.5 × 1.00151 ≈ 0.501, so it deviates from the first-order approximation (η = 0.5 cannot be called “small”).
In ② with concentric circles, why does the validation loss rise while the training loss keeps falling? Where is it good to stop training?
Sample answer
Once the training data can be separated perfectly, the training loss keeps falling as the weights are enlarged to raise the confidence even for training points near the boundary, but if a validation point is misclassified with high confidence, the cross-entropy becomes large. Either stop at the epoch of minimum validation loss (◆ in the figure) (early stopping), or use the weight decay λ to keep the weights from growing.
In ③, when ε is made smaller, why does the error decrease up to a point and then increase beyond it?
Sample answer
The truncation error of the central difference is about (ε2/6)|L‴| and decreases with ε, but L(w + ε) and L(w − ε) each carry a rounding error of about 10−16 × L, and dividing it by 2ε makes the rounding error grow in proportion to 1/ε. The error is smallest near ε ≈ 10−5, where the two balance.
7. Corresponding sections of the text and references
C. M. Bishop, Pattern Recognition and Machine Learning, Springer (2006) (Chapter 5 treats neural network training and backpropagation).
I. Goodfellow, Y. Bengio, A. Courville, Deep Learning, MIT Press (2016) (Chapter 6 treats feed-forward networks, output layers and losses, and activation functions. The full text can be read on the authors’ website, deeplearningbook.org).
D. E. Rumelhart, G. E. Hinton, R. J. Williams, "Learning representations by back-propagating errors", Nature323, 533–536 (1986), doi:10.1038/323533a0 (the paper that showed hidden units learning features through backpropagation).
M. Minsky, S. Papert, Perceptrons: An Introduction to Computational Geometry, MIT Press (1969) (an analysis of the limits of the single-layer perceptron; an expanded edition appeared in 1988).