NeuronCanvas
Neural Networks
Foundations

The Single Neuron

The building block: how one neuron computes a weighted sum, a bias, and an activation.

Step 01 - The break

Three very different days, one identical verdict

The machine from the previous page answers by asking whether its total came out above zero. Run it on three days.

day x1 sky x2 forecast total z verdict
Monday 0.80 0.60 1.400000 above zero -> bring it
Wednesday 0.55 0.45 0.725000 above zero -> bring it
Thursday 0.30 0.35 0.150000 above zero -> bring it

Monday cleared the line by a mile. Thursday cleared it by 0.15 and could have gone either way. The machine says the identical two words to all three, because "above zero or not" keeps the sign of the total and throws away everything else about it.

There is a second thing wrong with those three lines and it is easier to miss. The verdict is a hard switch: at a total of -0.000001 it says no, at +0.000001 it says yes, and nowhere in between does it say anything. Nudge the total by a hair anywhere except that one exact point and the answer does not move at all - that is what it means for a curve to have no slope there, the same "steepness" idea as the slope of a straight line, just measured one point at a time. In four pages' time, when the machine has to work out how to correct itself, a step with no slope will turn out to be a step it cannot learn through at all.

Step 02 - Before this page
Step 03 - The stage

The same two-input neuron you dragged on the previous page, now with every number on it named and checked by hand. Drag any slider and watch both the diagram and the arithmetic below it update instantly. Every number this page works through by hand is reachable on these five sliders, and you are meant to check them.

Preview frame from the "The Single Neuron" animation0:15

What this animation shows

Three labeled inputs connect through colored weighted edges into a central sum node, drawn as a large sigma. The sum flows into a small sigmoid curve that draws itself, then on into a final output neuron that lights up. This traces the exact recipe a single neuron follows: weighted sum, activation, output.

0.6-0.30.730.62inputweighted sumoutput
x₁ × w₁ = 0.60 × 0.80 = 0.480
x₂ × w₂ = -0.30 × -0.50 = 0.150
sum + bias = 0.480 + 0.150 + 0.10 = 0.730
tanh(0.730) = 0.623
A single neuron combining two weighted inputs and a bias, then applying an activation function.
Step 04 - One question first

With the worked example dialled in, switch the Activation dropdown from Sigmoid to Linear (none). Before you do it: which of the four lines in the readout will change?

Commit to a guess, then open this

Only the last one.

x₁ * w₁, x₂ * w₂ and sum + bias are all computed before the activation is ever consulted. They read 1.200, 1.200 and 1.400 under every setting of that dropdown, because the dropdown does not exist as far as they are concerned.

That is worth more than it sounds. The activation is not a mode the neuron runs in. It is the last of three steps, it happens after everything else has finished, and it touches exactly one number. Which is also why swapping it later, on a network that is already built, changes the answer without changing anything about how the answer was reached.

Step 05 - Plain explanation

A neuron does exactly three things, in order: multiply each input by a weight (how much that clue matters), add the results up along with a bias (a built-in lean toward yes or no), and then pass that total through an activation function, a fixed curve applied to the one number that comes out. The activation is not there to keep numbers tidy. It is there to bend the neuron's response, and the next page shows with arithmetic that without that bend, stacking a hundred layers gives you exactly the power of one.

The thermostat

A thermostat reads more than one sensor: the room, the outside wall, sometimes the floor. It does not treat them equally, because the wall sensor lags and the room sensor is next to a lamp. Each reading is scaled by how much this thermostat trusts it. There is also a calibration offset screwed into the unit at the factory, a fixed number added to everything, which is there because the sensor package reads two degrees warm and somebody had to compensate for it once and for all. And then there is the face: whatever internal voltage the thing computes, the display shows you a number between 5 and 30 with a degree sign after it, because "0.62 volts" is not an answer to the question you asked.

Where it breaks downthe thermostat's calibration offset was measured once by an engineer. A bias is not measured, it is learned from the neuron's own mistakes.

Step 06 - The depth ladder
WordsThe three steps, one at a timeMultiply, add, activate - and the two letters, z and a, that name the results of steps 2 and 3.Rung 01

Let's build the umbrella-decision machine for real, with actual numbers instead of clouds and forecasts. A neuron does exactly three things, in order, and each one is worth a paragraph.

Step 1, multiply.Each input gets scaled by its own weight. A weight of +2.00 means "this clue counts double". A weight of +0.10 means "I barely care about this". A weight of -1.00 means "more of this clue pushes the answer the otherway". Sign is the important part: blue for positive, orange for negative, as on every diagram here.

Step 2, add. Sum all the scaled inputs, then add the bias. The bias belongs to the neuron, not to any input, and it does not care what the inputs are. It shifts the whole answer up or down by a fixed amount. The result of this step is called the pre-activation, and it is written z. You will see z on every page from here to the end of the module.

Step 3, activate. Feed zthrough one fixed curve and out comes the neuron's activation, written a. This step has no weights and nothing to learn, with one exception (PReLU) covered two pages from now. It is the same curve for every neuron in a layer, applied to one number at a time.

That is a neuron. Everything else in this module is many of these, arranged, and a procedure for choosing the weights.

NumbersOne neuron, fully worked, with numbers that do not moveThree worked blocks: the full three-step calculation, one weight at three settings, one bias at three settings.Rung 02

Here is one neuron, fully worked, with numbers that do not move. Two clues about the weather, both already scaled to a 0-to-1 range. This is the first hidden neuron of the small network that the rest of this module reuses on every page, so it is worth getting comfortable with.

One symbol appears below that has not been introduced, and it will appear in almost every formula from here to the end of the module, so here it is once. e is a fixed number, 2.718282 to six places, in the same way that pi is a fixed number. It turns up whenever something grows or shrinks smoothly, which is why it ends up inside every curve on this site. e^-1.400000 means e raised to the power -1.4, and it works out to 0.246597. You do not need to know where e comes from to follow anything here. Take it off a calculator and carry on.

WORKED EXAMPLE - hidden neuron h1
inputs
x1 = 0.80 how grey the sky looks
x2 = 0.60 forecast chance of rain
parameters
w11 = +1.50 (blue) w21 = +2.00 (blue) b1 = -1.00
STEP 1 multiply
x1 * w11 = 0.80 * 1.50 = 1.200000
x2 * w21 = 0.60 * 2.00 = 1.200000
STEP 2 add, including the bias
z1 = 1.200000 + 1.200000 + (-1.00) = 1.400000
STEP 3 activate (sigmoid here, because it is the easiest curve to read)
a1 = sigmoid(1.400000) = 1 / (1 + e^-1.400000)
= 1 / (1 + 0.246597)
= 1 / 1.246597
= 0.802184
If you recompute a line from the printed inputs rather than at full
precision, the last digit may come out one different.

Read that last line as "the neuron is 80.2% convinced". The three steps never change. Only the numbers do.

One thing to expect, so it does not look like a mistake later. Sigmoid was chosen here because 0.802184 reads straight off as "80.2% convinced", which is the clearest possible thing for a first worked example. From the next page onward this same neuron uses tanh instead, and its answer changes. That is not a correction to this page; it is a better choice for a neuron sitting inside a network rather than at the end of one, and page 4 explains exactly why sigmoid is the wrong curve for a hidden layer. The neuron, the inputs and the weights stay identical throughout.

This exact configuration is reproducible in Figure 02 above. Set x1 = 0.80, w1 = 1.50, x2 = 0.60, w2 = 2.00, bias = -1.00, activation Sigmoid. The widget calls these weights w1 and w2 rather than w11 and w21 because it only has the one neuron, so there is no second neuron to tell them apart from: its w1 is this page's w11, and its w2 is this page's w21. The widget's readout should show the same 1.40 and the same output. If it does not, the page is wrong and should be reported.

What the weight actually does

Change one weight and nothing else, and watch where the total lands.

WORKED EXAMPLE - one weight, three settings (x1 = 0.80, x2 = 0.60, b1 = -1.00)
w21 = +2.00 z1 = 1.200000 + 1.200000 - 1.00 = 1.400000 sigmoid -> 0.802184
w21 = +0.50 z1 = 1.200000 + 0.300000 - 1.00 = 0.500000 sigmoid -> 0.622459
w21 = -1.00 z1 = 1.200000 - 0.600000 - 1.00 = -0.400000 sigmoid -> 0.401312

The forecast input never moved. It sat at 0.60 the whole time. All that changed is how much this neuron cares about it, and the answer swung from 80% convinced to 40% convinced, crossing from "yes" to "no" on the way. That is the entire meaning of a weight: not what the evidence is, but how much this particular neuron trusts it.

At w21 = -1.00, drawn orange, the forecast is now evidence against rain. That is obviously wrong for weather, and it is exactly the kind of wrongness training exists to fix. An untrained network's weights are random, so roughly half of them start out backwards like this.

What the bias actually does

The bias is the one number that ignores the inputs entirely. Hold everything else fixed and move only the bias.

WORKED EXAMPLE - one bias, three settings (x1 = 0.80, w11 = 1.50, x2 = 0.60, w21 = 2.00)
evidence from the inputs, unchanged in all three rows: 1.200000 + 1.200000 = 2.400000
b1 = 0.00 z1 = 2.400000 + 0.00 = 2.400000 sigmoid -> 0.916827
b1 = -1.00 z1 = 2.400000 - 1.00 = 1.400000 sigmoid -> 0.802184
b1 = -2.50 z1 = 2.400000 - 2.50 = -0.100000 sigmoid -> 0.475021

Same evidence, three different verdicts, ranging from 91.7% convinced to under half convinced. The bias is how easily this neuron is persuaded. A large negative bias makes it a sceptic that needs a lot of evidence before it says yes; a positive bias makes it credulous.

A useful way to see it: the bias is just a weight on an input that is always 1. On the previous page the same decision used three clues, the third being "got soaked yesterday", pinned at 1.00 with a weight of +0.30 and a bias of -1.30. Because that third input never varies, its contribution is a constant 0.30, and folding it into the bias gives -1.30 + 0.30 = -1.00, the exact bias used here. Same neuron, same answer of 1.40, one fewer moving part. Some textbooks write every network this way, with the bias hidden as a permanently-on input. This site keeps it separate because it is easier to read.

PictureThe line a neuron drawsThe boundary derived from the arithmetic rather than observed, then drawn: x2 = 0.50 - 0.75 * x1.Rung 03

Here is the geometric fact that motivates the whole next page, made concrete rather than asserted.

First, one link back to the number you just computed. The neuron's answer was 0.802184, a probability, and a probability above 0.5 is the neuron leaning yes. But sigmoid has a convenient property: it passes through exactly 0.5 when its input is exactly 0, and it only ever climbs, so a1 is above 0.5 exactly when z1 is above zero. "The probability came out above half" and "the total came out above zero" are the same statement about the same neuron, checked on two different numbers. That means you can look for the yes/no boundary in the easier of the two, z1, and read the answer off the harder one for free.

So the neuron says yes when z1 is above zero and no when it is below, and the boundary between yes and no is the set of inputs where z1 is exactly zero:

WORKED EXAMPLE - the decision boundary
z1 = 0
1.50 * x1 + 2.00 * x2 - 1.00 = 0
2.00 * x2 = 1.00 - 1.50 * x1
x2 = 0.50 - 0.75 * x1 <- a straight line
points on that line
x1 = 0.00 -> x2 = 0.5000
x1 = 0.40 -> x2 = 0.2000
x1 = 0.80 -> x2 = -0.1000
our actual input, (0.80, 0.60)
the line at x1 = 0.80 sits at x2 = -0.1000
our x2 = 0.60 is above that, so we are on the yes side
confirmed by z1 = +1.40, which is positive
The weights set the tilt, the bias slides the line without tilting it.

x2 = 0.50 - 0.75 * x1is a straight line, and no choice of weights or bias will ever make it anything else. The weights set the line's tilt; the bias slides it back and forth without changing the tilt. A neuron with three inputs draws a flat plane in three dimensions instead, and with more inputs a flat slice of higher-dimensional space, but it is always flat. That flatness is precisely what one neuron cannot escape, and it is why the next page needs more than one.

EquationWriting it down compactlyThe two-line form, then the dot-product shorthand worked on this neuron's own numbers.Rung 04

Now that you have watched it move, here is the same thing in the notation the rest of this module uses. Nothing new is happening; this is shorthand for the arithmetic above.

z = w1 * x1 + w2 * x2 + ... + wn * xn + b
a = f(z)

z is the pre-activation, a is the activation, f is whichever curve you chose. When there are many inputs, writing out the sum gets tedious, so the multiply-and-add step gets a single symbol:

z = w . x + b

The dot is a dot product, and it means exactly "multiply matching pairs and add up the results", which is Steps 1 and 2 with a shorter name. For our neuron, w = (1.50, 2.00) and x = (0.80, 0.60):

w . x = 1.50 * 0.80 + 2.00 * 0.60 = 2.40
z = 2.40 - 1.00 = 1.40

Same number, fewer characters.

One more name, for orientation: a single neuron with a sigmoid activation is exactly logistic regression, a model that predates neural networks by decades and is still the default first thing to try on a binary classification problem. If you already know logistic regression, you already know a neuron. If you don't, you now know logistic regression.

General caseWhat changes when the data is realSeven hundred inputs changes nothing but the length of the sum - and the one preprocessing step this page quietly did for you.Rung 05

Nothing above depends on there being two inputs. With seven hundred inputs, step 1 is seven hundred multiplications and step 2 is a sum of seven hundred and one numbers including the bias. The count of parameters in one neuron is always "one per input, plus one", so a neuron reading seven hundred inputs owns seven hundred and one numbers and not one thing about the three steps has changed.

One simplification worth naming.Every number on this page was chosen to be readable, and the inputs were handed to you already scaled to a 0-to-1 range. Real data does not arrive like that. A raw temperature in Celsius and a raw price in rupees differ by orders of magnitude, and feeding both into the same neuron unscaled makes one clue's weight matter thousands of times more than the other's before any learning has happened. Rescaling inputs to a comparable range is a routine, mandatory preprocessing step, and the initialization pages explain what breaks when it is skipped.

Step 07 - Why this and not that

Why this and not that

Why have an activation at all, rather than just checking whether the total is above zero?

A hard yes/no switch has a slope of zero everywhere except at the single point where it jumps, where it has no slope at all. Four pages from now, the entire method for correcting a network turns out to run on slopes, and a step with no slope is a step nothing can be learned through. The curve exists so that the machine's answer changes a little when its inputs change a little.

Why sigmoid here, if the next page switches to tanh?

Because 0.802184reads straight off as "80.2% convinced", which is the clearest possible thing for a first worked example. Sigmoid is the right curve at the end of a network answering a yes/no question, and the wrong curve inside one. Page 4 makes that a measured claim rather than an assertion. The neuron, the inputs and the weights are identical either way.

Why is the bias a separate thing rather than a fourth weight?

It can be a fourth weight, on an input pinned at 1, and rung 2 shows the fold. Some textbooks write every network that way. This site keeps it separate because a number that ignores the inputs behaves differently from one that does not, and hiding that costs more than the tidiness is worth.

Why does a bigger weight not just mean a more important clue?

Because the input's own scale is in there too. A weight of 0.001 on a clue that arrives in millions is doing more work than a weight of 5.0 on a clue that arrives between 0 and 1. Weights are only comparable to each other when the inputs are on comparable scales, which is rung 5's point.

A single neuron with a sigmoid is logistic regression. So is this whole subject just statistics with new names?

For one neuron, yes, exactly and without qualification. The subject starts being something else on the next page, when the outputs of several of these become the inputs of another one.

Name origins
z and a
conventional, and universal enough to rely on: z for the raw weighted sum before the curve, a for the activation after it. No deeper meaning; they are just the letters everyone settled on.
pre-activation
the number before the activation runs. The name is literal.
activation
inherited from the biological story, where a neuron "fires" or "activates". The word survived the story.
sigmoid
Greek sigma plus -oid, "shaped like an S". It describes the picture and nothing else.
logistic
in logistic regression: from the logistic function, named by Verhulst in the 1840s for population growth. It has nothing to do with logistics.
logit
short for "logistic unit", and it is the log-odds log(p / (1 - p)), which is precisely the inverse of sigmoid. Calling the number before the squash a logit is literally correct, not jargon.
e
Euler's number, 2.718282. It shows up in every smooth-growth curve on this site, which is why it ends up inside sigmoid, tanh, ELU, GELU, softplus and softmax.
dot product
the dot is the symbol; "product" because it multiplies pairs. On this site the dot means this and nothing else, and multiplication everywhere else is written *.
Step 08 - Where people go wrong
Step 09 - Practice
  1. 01
    Reproduce the worked example exactly, to three decimals.
    Hint
    Five sliders and one dropdown; the values are all in rung 2's first block.
    Answer
    x₁ = 0.80 w₁ = 1.50 x₂ = 0.60 w₂ = 2.00 bias = -1.00 Sigmoid

    Readout: contributions 1.200 and 1.200, total 1.400, output 0.802.

  2. 02
    Keeping Monday's verdict at yes, make the neuron trust the sky twice as much as the forecast, which is the reverse of how it starts.
    Hint
    "Twice as much" is a statement about the two weights, not about the two inputs.
    Answer

    Any pair with w₁ = 2 * w₂ that keeps the total positive, for instance w₁ = 2.00, w₂ = 1.00, giving 1.600 + 0.600 - 1.000 = 1.200 and an output of 0.769. Note that the contributionsare now 1.600 and 0.600 rather than 1.200 and 1.200, because the two inputs are not equal, and "trusts twice as much" is about the dials, not about what comes out of them.

  3. 03
    Find the bias that puts Monday exactly on the fence.
    Hint
    What does the total have to be for the output to be 0.500?
    Answer

    bias = -2.40, giving a total of 0.000 and an output of 0.500. The evidence from the two inputs is 2.400, so a bias of -2.40 cancels it exactly. Every setting that produces exactly 0.500 has a total of exactly zero, which is the boundary drawn in rung 3.

  4. 04
    Show the bias identity for yourself. The previous page used three clues with a bias of -1.30, the third clue being a constant 1.00 with a weight of +0.30. Get the same total out of this two-input widget.
    Hint
    A constant input contributes a constant amount, so it can be added to the bias once and forgotten.
    Answer

    The third clue contributes 0.30 * 1.00 = 0.30 on every single example, so fold it in: -1.30 + 0.30 = -1.00. Set the bias to -1.00 and the total is 1.400, identical to the three-clue version. One fewer moving part, same neuron, same answer.

  5. 05
    Hardest. Find a setting where Sigmoid and Tanh disagree about the sign of the answer, and explain why that is not a bug.
    Hint
    Look at what each curve does when the total is negative.
    Answer

    Any negative total. At z = -0.400000 sigmoid gives 0.401312 and tanh gives -0.379949. Sigmoid's output is positive for every possible input, including very negative ones, so a neuron that has concluded "no" still emits a positive number. Tanh runs from -1 to 1 and can say no with a negative number. That difference has a name, zero-centering, it has real consequences for how fast a network trains, and page 4 measures them.

Step 10 - Seen in the wild
  • Hospital readmission scoresA logistic regression, which is exactly this page's neuron, is still what most hospitals use to score a patient's risk of readmission within thirty days: a few dozen clues, one weight each, one bias, one sigmoid, and a number a clinician reads as a percentage.
  • Why it has not been replacedIt survives against much larger models for a reason this page makes obvious, which is that you can print the weights and see, clue by clue and sign by sign, what the model believed and how much.
Step 11 - Memory anchor

Multiply, add, bend.

Three steps, in that order, forever. The multiplying is trust, the adding is a total plus one standing grudge, and the bend is the step that makes the rest of this module necessary. Take the bend out and the next page proves that a hundred layers of this are worth exactly one.

Step 12 - The next break

Set those five sliders to anything you like. The boundary between yes and no is still x2 = 0.50 - 0.75 * x1, or some other straight line, and it will never be anything but a straight line, because rung 3 derived the line from the arithmetic rather than observing it.

Now ask for a pattern no straight line separates: yes when exactly one of two switches is on, no when both are on and no when neither is. There is no line to draw. The next page proves that in four lines, builds the two-layer network that does solve it, and then traces one day's weather all the way from the left edge to a percentage without skipping a single multiplication.

Layers and the Forward Pass