HomeMachine Learning & Neural NetworksPerceptron

🧠 Perceptron

Interactive perceptron simulator: click to add points, watch the decision line tilt via w ← w + ηyx, and see convergence on linearly separable data.

Machine Learning & Neural Networks3DModerate60 FPS
perceptron ↗ Open standalone

About this simulation

This simulation trains a perceptron — Frank Rosenblatt's original single-neuron learning algorithm — live in your browser on 2D points you choose or generate from a preset. On every misclassified point the weight vector is nudged with the classic update rule w ← w + η·y·x, b ← b + η·y, tilting the green decision line w·x + b = 0 a little closer to separating the blue (+1) and red (−1) classes, until it converges — or, on data like XOR, never does.

🔬 What it shows

A single linear classifier learning from mistakes, one point at a time. The canvas tints the plane blue or red according to which side of the current decision boundary w·x + b = 0 is predicted positive or negative, the yellow arrow is the live weight vector w, and the small chart in the corner tracks mistakes-per-pass so you can watch the error count fall toward zero as training proceeds — or oscillate forever on non-separable data.

🎮 How to use

Choose a Preset (Two Gaussians, Linear stripe, XOR, or Circle in square) or switch to Custom and click the canvas to place + Positive / − Negative points yourself. Adjust the Learning rate η (0.01–1.0) and Speed, then hit Step to apply one update or Auto-run to train continuously; Reset w zeroes the weights and bias without touching your points. The Stats panel tracks Iteration, mistakes per pass, total mistakes, the weight components w₁/w₂, bias b, margin, and whether the model has Converged.

💡 Did you know?

The perceptron convergence theorem guarantees that if the data is linearly separable, this exact update rule will find a separating line in a finite number of steps, no matter how the weights are initialised. But try the XOR preset — its four points can never be split by a single straight line, so the perceptron will keep making mistakes and update forever, which is historically the same limitation that stalled neural-network research in the 1970s until multi-layer networks arrived.

Frequently asked questions

What is a perceptron?

The perceptron is the earliest trainable model of a single artificial neuron, invented by Frank Rosenblatt in 1958. It takes an input vector x, computes a weighted sum w·x + b, and outputs +1 if that sum is at least zero and −1 otherwise, acting as a linear binary classifier. It is the conceptual ancestor of the multi-layer neural networks used in modern deep learning.

How does the perceptron learning rule actually work?

The algorithm scans through the points looking for one the current weights get wrong, meaning its label y and score w·x + b disagree in sign. When it finds such a point, it applies the update w ← w + η·y·x and b ← b + η·y, which shifts the decision boundary directly toward correctly classifying that point. This repeats, one misclassified point at a time, until every point is classified correctly or the iteration limit is reached.

What do the weight vector and decision line actually mean?

The decision line is the set of points where w·x + b = 0, which the simulation draws in green; everything on one side is predicted +1 and everything on the other is predicted −1. The yellow arrow is the weight vector w itself, and it always points perpendicular to the decision line, in the direction that increases the score w·x + b fastest — that is, toward the positive class.

Why does the perceptron fail on the XOR preset?

XOR-style data has positive points in two diagonally opposite regions and negative points in the other two, so no single straight line can separate the classes no matter how the weights are set — this is the well-known "linear separability" limitation. Because the perceptron can only ever represent one straight decision boundary, it keeps finding misclassified points forever on this preset, and the mistakes-per-pass chart never settles to zero, unlike on the separable Gaussians or Linear stripe presets.

What does "convergence" mean here, and why does it matter?

Convergence means the current weights classify every point in the dataset correctly, so a full scan finds no misclassified point and training stops with the Converged stat switching to YES. The perceptron convergence theorem proves this must happen in a finite number of updates whenever the data is linearly separable, which is a foundational result in machine learning theory — though it says nothing about how good the resulting margin between classes will be.

⚙ Under the hood

Rosenblatt's 1958 algorithm: each misclassified point tilts the weight vector w ← w + η·y·x. The line converges on separable data — and fails on XOR.

Canvas 2DMachine LearningPerceptronLinear ClassifierRosenblatt

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)