Neural Networks
Perceptron & Activation Functions
A signed observation changes weights and bias together, moving the same boundary that produced its score.
Weighted sum 1.50, Output 1.5000
No activation applied yet — the weighted sum 1.50 passes straight through.
- Input value
- Negative weight
- Activation output
- Slope of the activation
The first value entering the neuron.
The second value entering the neuron.
The ten-layer readout multiplies ten equal local activation slopes only. Weight Jacobians and other gradient paths are omitted; it is not a complete network gradient or a guarantee that learning stops. A zero ReLU slope is local to this input and these parameters.
What arrives before any weights?
Two inputs and one output, with nothing between them yet but addition. Drag the input values and watch the number arrive.
Addition
Inputs add before the weights are revealed.
Check this stage
Check your understanding
Inspect weighted scores, step through labelled observations and watch exact perceptron updates move a linear boundary. Test non-separable data.
What does a perceptron learn?
A perceptron learns an affine decision boundary by visiting labelled observations and adding a signed observation to its parameters when its signed score is nonpositive. It can separate linearly separable data; one affine boundary cannot solve XOR or assign different predictions to identical coordinates.
The first five stages preserve the neuron explorer: change inputs, weights and bias, then compare sigmoid, tanh and ReLU and their derivatives. Learning adds the classical perceptron update. That update does not differentiate the step function.
Inspect the score before the update
The training labels are −1 and +1. The score is
Predict +1 when s is at least zero, and −1 otherwise. The score is not a calibrated probability. The solid line is the current score-zero set. Select Inspect observation to connect one row's products, score, prediction and signed margin to its proposed update. The dashed line is the boundary that would result from visiting that row now. Selecting a row does not change the training order.
This lab updates when y times s is nonpositive, including a positive example correctly predicted at score zero. Thus updates and classification mistakes differ. For constant positive learning rate η:
There is no factor two from an alternative rule based on y minus the predicted label. The intercept is updated like a weight on an extra constant feature equal to one.
Set both weights and the bias to zero, keep rate 0.5 and inspect row 0 in Separable: x=(−2,−1), y=−1. Its score is 0 and prediction +1, so the update is Δ(w₁,w₂,b)=(1,0.5,−0.5). Press Step: the actual parameters become (1,0.5,−0.5), the row's new score is −3 and the boundary is x₁+0.5x₂−0.5=0. Row 1, at (−1,−2) with label −1, then has score −2.5 and needs no update. Open Under the hood for raw row proposals and the sequential visit ledger. Its entries retain the before parameters, score, actual delta and after parameters for every completed visit.
When has training finished?
Step visits one observation in displayed forward row order, wrapping after the last row. Observation order can reverse it. One completed epoch is one complete pass; a clean epoch contains no parameter updates. This lab stops at a clean epoch or the displayed visit budget. Zero mistakes in a partial pass is not a clean epoch. A budget stop is not convergence and does not by itself prove non-separability.
The weight and bias sliders are manual starting parameters. Editing starts, learning rate, fixture or order restarts training; trained parameters are shown separately without rounding them back to a slider grid. Restart training retains settings and clears completed visits. Shared links reproduce completed visits by exact deterministic replay; guesses and recovery stay in memory. Reset controls keeps the stage, restores defaults and returns to guided mode.
Try XOR, same-label duplicates and Contradictory duplicates. Duplicates remain separate visits even where their marks overlap; inspect them with the selector or table. The failure preset loads opposite labels at identical coordinates. No deterministic classifier can give that location both labels. Restore experiment recovers the whole preceding experiment even after further edits or free exploration.
The convergence result assumes a finite fixed dataset with a strictly positive separating margin in augmented feature space, bounded augmented input norms, a fixed positive rate and repeated visitation. Under the standard zero-start convention the update bound is (R/γ)², where R bounds augmented norms and γ is the margin of a unit separator. This lab neither estimates that bound for arbitrary starts nor promises convergence on arbitrary data. A separating training fit need not maximise margin or generalise to unseen observations.
Zero weights produce a constant prediction. With zero bias too, every location has score zero: there is no unique boundary line. Vertical boundaries are drawn exactly; off-plot boundaries are labelled rather than replaced with a line along the frame. The dashed inspected-row proposal can coincide with the solid line when no update is needed. Its numeric parameters remain available.
What do activation slopes tell us?
In Squashing and The slope, change Activation between sigmoid, tanh and ReLU. Both the activation and dashed derivative curve are drawn. Sigmoid's peak local derivative is 0.25; multiplying ten identical activation factors gives 0.25¹⁰ = 9.5367431640625 × 10⁻⁷. At ten factors of 0.05 the product is 9.765625 × 10⁻¹⁴. The readout isolates these activation factors: a real network's chain rule also includes weight Jacobians and potentially other paths. It is not a complete network gradient.
Push Input x₁ to 3 at the default weights and bias: the weighted sum is 4 and the sigmoid derivative is about 0.017663, below the lab's 0.05 saturation threshold. That threshold is a teaching convention. Sigmoid crosses it around |z|=2.887271; tanh around |z|=2.178272. Their local derivatives become small rather than mathematically zero at finite real inputs.
ReLU has local derivative 1 above zero. At or below zero this lab uses derivative 0 (the mathematical derivative at zero is undefined). That input contributes no local activation gradient under these parameters. Other inputs, upstream changes or other update mechanisms can reactivate a unit; a single negative score is not proof of a permanently dead unit. ReLU's positive slope alone does not guarantee healthy full network gradients.
Sources
The Cornell perceptron notes explain augmented bias and the separable-data bound. The MIT perceptron lecture distinguishes the convergence guarantee from finite-time non-separability detection. Deep Learning, chapter 6 provides the broader context for affine units, nonlinear representations and derivatives.
Stage recap
In and out
Two inputs and one output, with nothing between them yet but addition. Drag the input values and watch the number arrive.
Weights
Each connection multiplies what passes through it. Edge thickness is the magnitude, and a dashed edge means the weight is negative — so a strong inhibitory connection looks strong, not absent.
The sum
Add the weighted inputs and the bias. This single number is everything the neuron knows before it decides what to output.
Squashing
The sum enters an activation function. Without one, stacking layers would be pointless — a chain of linear maps is just one linear map.
The slope
The dashed curve is the derivative of the solid one. That slope is what gets multiplied into the gradient at every layer, so where it is flat, learning can be attenuated. This slope-only product omits weight Jacobians.
Learning
Visit observations in the displayed order. Update when label times score is nonpositive; a clean epoch has no updates. A budget stop is not convergence.
Reference
- Weighted sum
- z = w₁x₁ + w₂x₂ + b
- Perceptron update
- Labels −1/+1; predict +1 at score zero; update iff y*s ≤ 0: Δw=η*y*x, Δb=η*y. Fixed positive η; repeated displayed row order.
- Stop
- Convergence means a whole epoch without updates. Visit-budget exhaustion is separate.
- Sigmoid
- σ(z) = 1 / (1 + e⁻ᶻ), σ′(z) = σ(z)·(1 − σ(z)) — peaks at 0.25
- Tanh
- tanh(z), derivative 1 − tanh²(z) — peaks at 1, and zero-centred
- ReLU
- max(0, z), derivative 1 for z > 0 and 0 for z < 0
- Saturation
- σ′ → 0 as |z| grows, so this local activation factor attenuates a backpropagated gradient
- Saturation onset
- σ′ falls below 0.05 past |z| = 2.89; tanh′ past |z| = 2.18
- Dead ReLU
- a unit stuck at z < 0 outputs 0 with derivative 0 under current inputs and parameters
- Depth cost
- ten equal local activation factors multiply to slope¹⁰; weight Jacobians omitted — 9.5e-7 at σ′s best, 1e-13 at 0.05
- Why non-linear
- composing linear maps gives a linear map, so depth would buy nothing
Break it on purpose
Opposite labels at identical coordinates cannot be separated. A visit budget can stop training without a clean epoch. Activation slopes are a separate local gradient mechanism.
Explore next
- Multi-Layer PerceptronNonlinear hidden features let an affine output separate patterns that one affine classifier cannot represent.
- 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.