How it works
Each point passes through hidden units. Every unit takes a weighted sum, adds a bias, and squashes it through a nonlinearity (tanh or ReLU). A second layer collapses those activations into one score, and a sigmoid turns that score into a probability:
Training compares against the true label using binary cross-entropy, averaged over all points:
The whole reason this pairing is used: for a sigmoid output with cross-entropy loss, the gradient at the output collapses to the elegantly simple , just the prediction minus the truth. Backpropagation pushes that error back through and , and each frame nudges every weight a little way downhill.
each frame:
repeat a few times: # a few gradient steps
forward pass over all points
accumulate ∂L/∂W by backprop
W ← W − (lr / N) · ∂L/∂W
every 4th frame:
re-evaluate the net on a 44×44 grid → heatmapThe heatmap is deliberately coarse. Evaluating the net on a full-resolution grid every frame would be wasteful, so it runs on a small lattice, gets cached, and is scaled up smoothly behind the points.
Where it shows up
This exact structure is the smallest honest example of how every deep model learns. Swap two coordinates for a thousand-dimensional embedding and one hidden layer for ninety, and the picture is unchanged: a differentiable function, a loss, and gradient descent bending a boundary until the errors shrink. The same shape underlies logistic regression (drop the hidden layer and the boundary can only be a straight line), support-vector machines, and the sigmoid gate of a control system deciding when to switch. Nonlinear hidden units are the only reason the spiral is learnable at all.
The knobs
- Dataset: the toy problem to separate. XOR and circles are gentle, moons is harder, and the spiral is the real test of a curved boundary.
- Hidden units: how many neurons the middle layer has. Too few and the boundary cannot bend enough to fit the spiral; more units buy sharper, tighter curves.
- Learning rate: the size of each downhill step. Small values crawl safely; large ones descend fast but can overshoot and wobble.
- Activation: the hidden nonlinearity. Tanh gives smooth, rounded boundaries; ReLU builds the surface from crisp, folded straight pieces.