Neural Networks
Multi-Layer Perceptron
Nonlinear hidden features let an affine output separate patterns that one affine classifier cannot represent.
Concentric rings, 150 points, evenly split between the two classes. The field is hidden at this stage; the inspected row already has an output. Inspected row 0: logit 0.9465647775301815, sigmoid 0.720423802559331, prediction 1. 30 by 30 cell-centre samples, not an exact contour.
Architecture — 17 parameters
2 to 4 to 1: two inputs, 1 hidden layer of 4, and one sigmoid output. 4 hidden units and 17 parameters in total, with ReLU on the hidden layers. Edge thickness is the size of a weight clipped at 4 for display; a dashed edge is negative. Node values are rounded to two decimals and omitted in dense layouts; raw values stay in inspection.
- Positive class
- Negative class
Training fit only; no generalisation estimate. Graph positions illustrate connectivity; labels are inspected activations rounded to two decimals and omitted in dense layouts. Edge magnitude is clipped at 4 for display; raw weights remain in inspection. Field uses 900 cell-centre samples; opacity is an uncalibrated score.
Fixed XOR quadrants, concentric rings or interleaved moons.
Every hidden layer has the selected width. Linear depth retains an affine logit.
Width changes the representation and parameter count; a failed run is not a capacity proof.
Where does one observation go?
Inspect a row and follow its actual activations through the network. Graph positions illustrate connectivity, not feature-space distances.
- Input observation
- Weighted sums + biases
- Hidden activations
- Output logit
- Sigmoid and threshold
Hidden representation
The vector of activations computed from an observation by a hidden layer.
Check this stage
Check your understanding
Nonlinear hidden features let an MLP represent boundaries that one affine classifier cannot. Inspect its exact forward computation, then train it on fixed observations.
Follow one observation
A hidden layer computes nonlinear features from the two inputs. The output combines all final hidden activations into a logit, then applies a sigmoid. Nonlinear hidden features can separate patterns that one affine classifier cannot represent. Depth alone does not do this when every hidden activation is linear.
Choose Inspect observation, then open Under the hood. Each unit shows its raw inputs, weights, products, bias, pre-activation and activation. Graph labels, where space permits, are the same row's activations rounded to two decimals; graph positions illustrate connectivity rather than distances. Negative edges are dashed. Their displayed magnitude is clipped at four, while raw weights remain available in inspection. Dense graph layouts omit numeric labels rather than shrinking text; inspection retains every unit.
Labels are 0 and 1. The stored sigmoid score at least 0.5 predicts class 1, including equality. In exact real arithmetic this is the logit-zero cut. Floating-point sigmoid can round tiny nonzero logits to exactly 0.5, so the stored score decides numerical ties. These synthetic model scores have no evidence of probability calibration. The generated XOR quadrants use class 1 for equal signs; this is the complement of the usual Boolean XOR convention, with the same affine separability limitation.
Watch the actual update
The network has two inputs, one to three equal-width hidden layers and one sigmoid output. Hidden units use Linear, ReLU or Tanh. ReLU uses derivative zero at its kink. Weights start from a seeded normal draw: standard deviation sqrt(2/fanIn) for ReLU, sqrt(1/fanIn) otherwise, including the output layer. Biases start uniform in [-0.1, 0.1). This is the implemented fan-in scheme; it is not a promise of stability. Reseed changes initial weights and biases, leaving the fixed training observations.
Step accumulates gradients at the old parameters in displayed row order over all 150 observations, divides by 150, and changes all weights and biases simultaneously:
The implementation evaluates this binary cross-entropy stably from logits. The output delta is sigmoid(logit) minus label; hidden deltas include both weight matrices and activation derivatives. There is no shuffle, momentum, penalty or validation fit. Current loss, accuracy, graph, field and inspection all use the updated parameters. History starts at epoch zero. Play repeats real updates; Pause retains them. Changing learning rate retains the current parameters and records the actual rate used on each subsequent epoch. Other model/data edits restart the run and pause.
Large rates can give poor fits or numerical failure. A completed epoch budget is a stop policy, not evidence of convergence. Training accuracy says how well the network fits these rows; this lab has no independent generalisation estimate.
Remove the nonlinearities
Set Activation to Linear, or use Remove nonlinearities and later Restore experiment. Weighted sums with biases compose into one affine map:
The output sigmoid still applies, but its threshold has an affine logit zero set. For nonzero effective weights that set is a line; for zero weights it is empty or the whole plane. More linear hidden layers cannot represent XOR. Nonlinear features can, but a representation existing does not guarantee gradient descent finds it.
Sampled logit non-affinity is the RMS residual of an affine fit divided by sampled logit spread on the original input coordinates. It is withheld when sampled spread is below the numerical tolerance or nonfinite; inspection retains both raw RMS values and the tolerance. It is not geometric boundary curvature. A small value, constant samples or samples of one predicted class do not prove global geometry. An inactive ReLU has zero local derivative; other inputs and parameter changes may change it. Tanh saturation can reduce gradients, but is not a permanent-failure proof. Identical connected units receive identical updates when their parameters are symmetric. Opposite labels at identical inputs cannot both be classified correctly by this model.
How nonlinear features solve a concrete XOR
For a separate, hand-set Boolean example, let and . Use output logit , followed by the same sigmoid and threshold as this lab.
| Input | Hidden pair | Logit | Prediction |
|---|---|---|---|
| (0, 0) | (0, 0) | -0.5 | 0 |
| (0, 1) | (1, 0) | 0.5 | 1 |
| (1, 0) | (1, 0) | 0.5 | 1 |
| (1, 1) | (2, 1) | -0.5 | 0 |
The second hidden unit introduces a hinge at input sum one. A single affine output in this hidden representation therefore corresponds to two parallel cuts in input space, keeping the two middle-sum corners together. One affine cut of the original square cannot do that. Making both hidden activations linear removes the hinge and collapses the logit to , which fails XOR.
This is a capacity witness with specified weights, not the currently trained model or a promise that gradient descent finds those weights. The generated quadrant cloud uses the complementary positive-label convention and different coordinates; it is a separate experiment. Inspect its actual weights and outputs in the drawer.
Inspect the hidden representation
On the last stage, Show first hidden coordinate pair replaces the input canvas with the first hidden layer's first two activations. With width one the second coordinate is a zero reference. The selected row is emphasised in either view and remains linked to the graph and output computation. Other hidden units are omitted from this view, although all still contribute to the output; separation in two displayed coordinates is not a claim about the full learned representation. Domains expand with finite values.
The input field uses 900 cell-centre forward passes, with rounded SVG cells. Its visible class transitions approximate the boundary; they are not exact continuous contours. The hidden view omits this field because arbitrary pairs do not determine the omitted coordinates. Loss axes expand to the run; nonfinite readings stay in inspection and are excluded from the drawn path. A numerical failure withholds network geometry.
Try the small-network challenge on the original rings. A successful run establishes an example within the hidden-unit budget. An unsuccessful finite run establishes no universal width limit. Explore freely unlocks all controls and views. Sharing reproduces settings, initialisation seed, selection and actual update schedule, paused in guided mode; predictions and recovery snapshots stay in memory. Reset controls restores the original seed and defaults while retaining the stage. Local Mark explored records exploration without assessing answers.
The mechanism follows Deep Learning, chapter 6. Initialisation and saturation are discussed by Glorot and Bengio and He and colleagues.
Stage recap
The data and the network
Inspect a row and follow its actual activations through the network. Graph positions illustrate connectivity, not feature-space distances.
Before training
Random initial weights already give predictions. The 900 field cells are sampled forward passes, with no calibration claim.
Training
Step updates the full batch once; Play repeats at a readable interval. History includes epoch zero and the current parameters. Fit describes these training rows only.
The non-linearity
Linear hidden layers collapse to an affine logit. Nonlinear features can add representational capacity, but successful optimisation is a separate question.
Reference
- Architecture
- Two inputs, 1–3 equal-width hidden layers, one sigmoid output. Parameter count includes every bias.
- Hidden computation
- z = W a + b; a = linear(z), ReLU(z), or tanh(z). The selected row has exact raw values in inspection.
- Output and labels
- Labels 0/1; sigmoid score >= 0.5 predicts 1 including equality. Analytically the cut is logit zero; machine-rounded scores decide numerical ties. No calibration evidence.
- Loss
- Mean binary cross-entropy in nats, computed stably from logits. Current metrics and each epoch reading use current parameters.
- Update
- Full-batch descent: accumulate old-parameter gradients in displayed row order, divide by N, update simultaneously. Rate multiplies that mean.
- Output delta
- Sigmoid with logit BCE gives delta = score - label. Hidden deltas include weight matrices and activation derivatives.
- Linear collapse
- Composed affine hidden layers yield an affine logit. The sigmoid is still present at the output.
- Sampled logit non-affinity
- RMS affine-fit residual divided by sampled input-logit spread. Withheld for below-tolerance or nonfinite spread; not curvature or a boundary proof.
- Initialisation
- Normal weights with standard deviation sqrt(2/fanIn) for ReLU or sqrt(1/fanIn) otherwise, including output. Biases uniform [-0.1,0.1).
- Training scope
- 150 fixed training observations; Reseed changes weight initialisation. Budget completion is not convergence; fit is not generalisation.
Break it on purpose
Set Activation to Linear. Every hidden affine map composes into one affine logit, regardless of depth. Its zero set can be a straight line, empty or the whole plane; depth alone cannot represent XOR.
Explore next
- Perceptron & Activation FunctionsA signed observation changes weights and bias together, moving the same boundary that produced its score.
- BackpropagationMultiply local Jacobians along each path; add contributions where a value feeds multiple paths.
- Batch Norm & DropoutChange the batch statistics and dropout mask to see how they affect the same network.