Home / Science / Social sciences / Cognitive science / Neural network toysTool #729

Perceptron and Hopfield network simulator: watch a neuron learn AND, OR and fail on XOR (free)

Two classic neural network models to play with in the browser. Click points and watch a perceptron move its decision line epoch by epoch, converging on AND and OR and failing on XOR. Draw small black-and-white patterns, store them in a Hopfield network and recall them from a noisy cue while the energy falls.

Keep it one tap away for everyday use.

Bookmark Neural network toys?

Press Ctrl + D now. Your browser opens its own bookmark box, where you choose the name and folder.

  1. Points
  2. Learn line
  3. Patterns
  4. Recall
Nothing is uploadedWorks offline once open

Which toy?

Points

Click the picture to add a point of class

Each epoch goes through the points in order. For a point on the wrong side, every weight moves by learning rate × (target − output) × input, and the bias by learning rate × (target − output). Training stops after an epoch with no mistakes, or at the most epochs.

Learning

Epochs

Download

What it does

This page holds two of the oldest ideas in neural networks, small enough to watch step by step. They are often taught in cognitive science and psychology courses because they show, in a few lines of maths, how learning can live in connection weights.

  • Perceptron. One artificial neuron adds up its two inputs, each times a weight, plus a bias, and outputs 1 when the sum is above zero and 0 otherwise. That rule draws a straight line through the plane. Training nudges the line after every mistake.
  • Hopfield network. A set of on/off units, every one connected to every other. Storing a pattern strengthens the connections between units that agree (Hebb’s rule, “cells that fire together wire together”). Given a damaged copy, each unit follows the vote of the others until the network settles into a stored memory.

It works well with the publication plot maker, the sample size and power calculator and the factor analysis.

Perceptron: how to use it

  1. Pick a starting set: AND, OR or XOR on the four corners (0, 0), (0, 1), (1, 0) and (1, 1), two made-up clouds, or an empty plane.
  2. Click the picture to add points. Choose class 1 (filled circles) or class 0 (open squares) first. “Remove last” and “Clear” undo.
  3. Set the learning rate (how far the weights move after a mistake), the most epochs (passes through all points) and the starting weights (zero, or small fixed random numbers).
  4. Slide Show epoch, or step forward and back, to watch the line move. Shaded is the side called class 1; points on the wrong side are circled.

The rule: for each point in turn, error = target − output. Each weight changes by learning rate × error × input, and the bias by learning rate × error. Training stops after a pass with no mistakes.

Hopfield network: how to use it

  1. Choose a grid size. The 7 × 7 grid starts with three made-up shapes stored. Tap squares to draw your own and press Store this pattern, or use Random pattern.
  2. Choose a stored pattern, how many units to flip, and a noise seed. The cue shows flipped units outlined in red; tap it to change units by hand.
  3. Choose the update: one unit at a time in random order (always settles, because each change lowers the energy E = −½ Σ wᵢⱼ sᵢ sⱼ), or all at once (can swing between two states).
  4. Slide Show sweep to watch the state clean up. The table gives the overlap with every stored pattern.

Worked examples

AND with zero starting weights and learning rate 0.1 converges after 6 epochs, ending with weights 0.2 and 0.1 and bias −0.2: the line x₂ = −2 x₁ + 2 leaves only (1, 1) on the class 1 side. OR at rate 0.1 also converges. XOR never does: after 50 epochs 2 of the 4 points are still wrong, because no straight line puts (0, 1) and (1, 0) on one side and (0, 0) and (1, 1) on the other.

Hopfield: with the three 7 × 7 shapes stored, pattern 1 with 10 flipped units (seed 1) is recalled exactly. Raise the flips towards 20 or more and some cues land on a mixed (spurious) state or on the negative of a pattern, which the network stores too.

Frequently asked questions

Why does the learning rate not matter for AND? With zero starting weights, the rate only scales every weight by the same amount, so the line and the number of epochs stay the same. It matters when you start from random weights.

How many patterns fit? For random patterns, about 0.138 × the number of units: about 6 on a 7 × 7 grid. Patterns that look alike interfere sooner.

Is anything sent anywhere? No. Everything runs in your browser and nothing is stored.

Where the numbers come from

  • Perceptron learning rule: Rosenblatt (1958); limits on XOR: Minsky and Papert (1969). Hopfield network with Hebbian weights and energy: Hopfield (1982); storage limit about 0.138 N: Amit, Gutfreund and Sompolinsky (1985). Methods only; no data or tables are copied.
  • Written by fibub and checked in the tests against an independent NumPy implementation with the same update order and the same seeded random numbers.
  • The example points and patterns are made up.

Standard scientific values, such as constants, atomic weights and melting points, are facts found in every textbook; we name where ours were checked. If you are an author or publisher and want a value, a credit or a table changed or removed, tell us and we will act quickly.

Last updated 2026-11-09.

Related tools

Sample size and power calculator #32 How many subjects, samples or survey responses do you need? Sample size for comparing two means, paired data, two proportions, or a survey's margin of error, with power curves. Matches R and G*Power. Publication plot maker #27 Paste columns or open a CSV or Excel file and get a clean scientific figure with error bars, sized for a journal column. Download vector SVG or PDF, or PNG at 300 or 600 dpi. Your data stays in your browser. Factor analysis #724 Run an exploratory factor analysis in your browser: correlation matrix, KMO and Bartlett's test, scree plot with parallel analysis, principal axis or maximum likelihood extraction, varimax or promax rotation, loadings and communalities. Matches Python's factor_analyzer. Memory and attention tasks #727 Run a digit span or Corsi block test (forward or backward), a visual search task with search slopes, and simple or choice reaction time, in the browser. Get scores, a results table for the session and a CSV of every trial. Eye-tracking heat map #728 Open a gaze export (time, x, y), find fixations with the velocity (I-VT) or dispersion (I-DT) method, and see a heat map and scanpath over your own stimulus picture. Draw areas of interest to get dwell time, time to first fixation, fixation counts and visits. Download CSV and PNG. Nothing is uploaded. 1D Schrödinger solver #923 Choose a textbook potential, type a formula or draw your own, and get the lowest energy levels and wavefunctions of the one-dimensional Schrödinger equation by the matrix (finite-difference) method, with the exact levels alongside for the box, harmonic oscillator, finite well, Morse, linear and Pöschl–Teller potentials.