The first artificial neurons · lesson 1 of 7
Parts in this lesson
A1 if sum(w * x for w, x in zip(weights, inputs)) >= threshold else 0a McCulloch–Pitts unit
Bmp_unit((x1, x2), (1, 1), 2)AND: both inputs needed
Citertools.product(values, values, values)trying every setting on a grid

Brains and the first model neuron

Last updated

Every neural network in this course is built from one small idea, first written down in 1943: a unit that adds up its inputs and fires if the total is big enough. This lesson starts with the real neuron that inspired it, builds the model, and uses it to make logic gates. Then it finds the first gate the model can't make, a problem that will shape the next forty years.

By the end of this lesson you can

  • Describe, roughly, how a biological neuron takes in signals and fires
  • Compute a McCulloch–Pitts unit's output from its inputs, weights and threshold
  • Set weights and a threshold to make AND, OR and NOT, and explain why XOR is impossible
  • Say what the model leaves out of a real neuron

A neuron, roughly

Your brain is made of nerve cells, neurons: tens of billions of them, each connected to thousands of others. Leaving out almost all the biology, one works like this:

  • Dendrites, branches that reach out from the cell, receive signals from other neurons.
  • Each signal arrives at a synapse, a small gap where two cells meet. Some synapses are excitatory: a signal there pushes the receiving cell towards firing. Others are inhibitory: they push it away. Some synapses are stronger than others.
  • The cell body adds up the pushes. If the total passes a threshold, the neuron fires: a sharp electrical pulse, a spike, runs down its axon, a long fibre that carries it to the next neurons' synapses.
  • If the total stays below the threshold, nothing is sent. A spike is all or nothing: there's no half-sized one.

So a neuron takes many signals in, weighs them, and makes one yes-or-no decision. In 1943 the neurophysiologist Warren McCulloch and the logician Walter Pitts asked what that decision could compute.

Inputs, threshold, fire or not

The McCulloch–Pitts unit keeps just that much. Its inputs x1,…,xn are each 0 or 1 (a signal arrived, or didn't). Each has a weight wi: positive for an excitatory synapse, negative for an inhibitory one. The unit adds the weighted inputs and fires if the total reaches its threshold θ (theta):

y=1 if ∑i=1nwixi≥θ, and y=0 otherwise.

Here's one with three inputs, two excitatory (+1) and one inhibitory (−1). Switch the inputs on and off, and move the threshold:

Neuron firea McCulloch–Pitts unit
1x1+10x2+10x3−1sum1fires if sum ≥ θ = 11output

Sum: 1 × (+1) + 0 × (+1) + 0 × (−1) = 1. That reaches θ = 1, so the unit fires.

With θ=1, either excitatory input on its own makes it fire, unless the inhibitory one is also on. With θ=2, it needs both, and the inhibitory one off.The weights and the threshold decide what the unit computes. In 1943 nobody knew how to learn them; McCulloch and Pitts set them by hand. Learning them from examples is lesson 5.2.

Logic gates from threshold units

With 0 and 1 as false and true, the unit is a logic gate. Two equal weights of 1 and a threshold of 2 is AND: it fires only if both inputs are 1. Lower the threshold to 1 and it's OR. In Python:

neurons.ipynb

NOT needs one input with a negative weight and a threshold of 0: an input of 0 gives a sum of 0, which reaches the threshold, so it fires; an input of 1 gives −1, which doesn't.

neurons.ipynb

Now build the gates yourself. The square on the right has the four possible inputs at its corners. The unit fires on one side of the line w1x1+w2x2=θ (shaded), and every setting of the weights and threshold is just a different line. Make AND, OR and NAND (not AND):

Gate builderw₁ = 1, w₂ = 0.5, θ = 1
x₁x₂unitAND0000✓0100✓1010✗1111✓(0, 0)(0, 1)(1, 0)(1, 1)

3 of 4 rows right for AND. The unit fires in the shaded part of the square, where w₁x₁ + w₂x₂ ≥ θ; AND wants it to fire at the filled circles. Move the line so only the filled circles are on the shaded side.

This was McCulloch and Pitts's big claim: with AND, OR and NOT you can build any logical function, so a network of these units, wired the right way, can compute anything a logic circuit can. A brain, they suggested, might be a kind of logic machine.

Wrong way: making XOR with one unit

Now pick XOR in the figure above: exclusive or, true when exactly one input is 1. Try to make it.

You can't. XOR wants the unit to fire at (0, 1) and (1, 0), on opposite corners of the square, and stay quiet at (0, 0) and (1, 1), the other two corners. One straight line can't cut off two opposite corners from the other two. Every setting puts at least one corner on the wrong side.

To be sure it isn't just a matter of finding the right numbers, try every weight and threshold from −2 to 2 in steps of 0.25, almost 5,000 settings, and count how many make each gate:

neurons.ipynb

84 settings make AND, 204 make OR, 120 make NAND, and none make XOR. A single unit can only compute functions whose true and false cases a straight line can separate: in more dimensions, a flat hyperplane. Such functions are called linearly separable, and XOR isn't one.

The fix was known from the start: use more than one unit. XOR is "OR, but not AND", and a second layer can combine an OR unit and an AND unit (lesson 5.6). But in 1943 nobody could learn the weights of a network with more than one layer, and that's the difficulty that runs through the rest of this stage.

What the model leaves out

The McCulloch–Pitts unit is a cartoon, and the differences matter:

  • Learning. Its weights are fixed. A real brain changes its synapses with experience. In 1949, Donald Hebb proposed how: a connection strengthens when the cells on both sides of it fire together. That idea, connections that change with use, is where learning in neural networks begins.
  • Time. A real neuron sends a train of spikes, and information is carried in how often and when they come, not in one 0 or 1. Hodgkin and Huxley's 1952 equations for a single spike in a squid's nerve fibre won a Nobel Prize, and they're four coupled differential equations, not a threshold.
  • Everything else. Dendrites do some computing of their own, chemicals change how cells respond, and the whole thing is noisy.

So the units in this course are inspired by neurons, not models of them. That's why this course says unit as often as neuron. From here on, what matters is what the units can compute and learn, not how much they resemble cells.

Check what you learned

A McCulloch–Pitts unit has weights 2, 1 and −1 and a threshold of 2. Its inputs are 0, 1 and 1. What does it output?
Which weights and threshold make a two-input OR gate?
Why can’t one McCulloch–Pitts unit compute XOR?
What did Hebb add, in 1949, that the McCulloch–Pitts model lacked?

Sources

Every example on this page was run with Python 3.14, and its output and error messages are copied from it. These pages cover the same ground in more depth.

All sources for Simple Machine Learning