05

The artificial neuron

What exactly does an artificial neuron do?

11 minExecutive path

The artificial neuron

With voice. You can pause and jump to any step.

Lesson complete

Subtitles

In the previous lessons, the model was a straight line with a weight and a bias. Today that model becomes the building block of networks: the artificial neuron.

Voice

No voice: the lesson advances on its own with subtitles.

The voice for this lesson is being recorded: for now it advances on its own with subtitles.

0:00 / 0:00

What you will achieve

  • Calculate the output of a two-input neuron: inputs times weights, sum, bias, and activation.
  • Explain why a two-input neuron is a straight line that splits the plane, and what each parameter does.
  • Describe how the perceptron learns and recognize how far the analogy with the brain goes.

Key ideas

  1. An artificial neuron computes y = f(w₁x₁ + w₂x₂ + b): it multiplies each input by its weight, adds them, adds the bias, and applies an activation function.
  2. With two inputs, the points where the sum equals zero form a straight line: the decision boundary. Weights tilt it; the bias shifts it.
  3. The step answers zero or one abruptly and gives no gradient; the sigmoid gives a smooth score between zero and one and does give one.
  4. The perceptron (Rosenblatt, 1958) is a network of threshold units that learns from examples. In its simplest version, a neuron with a step, it corrects its weights only when it is wrong and, if a line that separates the data exists, finds it in a finite number of steps.
  5. An artificial neuron is a formula inspired by biology, not a model of the brain: a real neuron is vastly more complex.

What many people believe

Common belief An artificial neuron works like a neuron in the brain: it is a miniature brain that “thinks.”

What is true It is a formula: it multiplies, adds, and applies a function. It is inspired by biology (McCulloch and Pitts, 1943), but a real neuron is a vastly more complex cell. What networks achieve comes from combining very many of these formulas with parameters adjusted from data.

Check yourself

Four questions. No grade, no account: they just show whether the idea stuck.

ConceptIn a two-input neuron, what effect does changing only the bias b have?
ConceptWhy is the sigmoid preferred over the step when a neuron is trained with gradient descent?
CalculationA neuron with a step has w = (0.5, −0.5) and b = 0. For the example x = (1, 2) it should have answered 1, but it answered 0. With rate η = 1, what are the weights and bias after one perceptron step?
ApplicationA vendor claims its system uses “neurons that think like the brain.” Which question is the most useful for evaluating it?

Under the hoodFor those who want the math and the code. You do not need it to follow the course.

The neuron as a formula

A neuron with inputs x1,…,xnx_1,\dots,x_n, weights w1,…,wnw_1,\dots,w_n and bias bb computes

z=∑i=1nwixi+b=w⋅x+b,y=f(z)z = \sum_{i=1}^{n} w_i x_i + b = \mathbf{w}\cdot\mathbf{x} + b, \qquad y = f(z)

where ff is the activation function. With the lesson’s numbers, x=(0.8, 0.2)\mathbf{x}=(0.8,\,0.2), w=(2, −1.5)\mathbf{w}=(2,\,-1.5) and b=−0.5b=-0.5:

z=2⋅0.8+(−1.5)⋅0.2−0.5=0.8z = 2\cdot 0.8 + (-1.5)\cdot 0.2 - 0.5 = 0.8

With the step, y=1y=1. With the sigmoid, y=σ(0.8)≈0.69y=\sigma(0.8)\approx 0.69. If n=1n=1 and ff is the identity, we get y=wx+by=wx+b: the line from lesson 3 is the simplest case of a neuron.

The decision boundary

The neuron changes its answer where z=0z=0, that is, w1x1+w2x2+b=0w_1x_1+w_2x_2+b=0. It is a line whose normal vector is w\mathbf{w}. Its distance from the origin is ∣b∣/∥w∥|b|/\lVert\mathbf{w}\rVert, and the signed distance from a point to it is z/∥w∥z/\lVert\mathbf{w}\rVert. In the example, ∥w∥=2.5\lVert\mathbf{w}\rVert=2.5: the line passes 0.20.2 from the origin and the example email sits 0.8/2.5=0.320.8/2.5=0.32 away.

Changing bb shifts the line; changing w\mathbf{w} rotates it (if w2=0w_2=0 it is vertical: only x1x_1 matters). Multiplying w\mathbf{w} and bb by k>0k>0 does not move the line, but with a sigmoid it changes how sharp the transition is, because the output becomes σ(kz)\sigma(kz). With nn inputs, the boundary is a hyperplane.

Two activations

The step is H(z)=1H(z)=1 if z≥0z\ge 0 and 00 otherwise. The sigmoid is

σ(z)=11+e−z,σ′(z)=σ(z) (1−σ(z))\sigma(z)=\frac{1}{1+e^{-z}},\qquad \sigma'(z)=\sigma(z)\,\bigl(1-\sigma(z)\bigr)

with maximum slope 1/41/4 at z=0z=0. The derivative of the step is zero except at z=0z=0, where it does not exist: it gives gradient descent no signal at all. The sigmoid’s derivative exists everywhere. A sigmoid neuron trained to minimize cross-entropy is logistic regression. Other activations are also used today, such as ReLU (lesson 7).

The perceptron rule

With t,y∈{0,1}t,y\in\{0,1\} (the correct answer and the neuron’s answer):

wi←wi+η (t−y) xi,b←b+η (t−y)w_i \leftarrow w_i + \eta\,(t-y)\,x_i,\qquad b \leftarrow b + \eta\,(t-y)

It changes only when t≠yt\neq y, and then t−y=±1t-y=\pm1. The same example improves: Δz=η (t−y) (∥x∥2+1)\Delta z=\eta\,(t-y)\,(\lVert\mathbf{x}\rVert^2+1) has the right sign. It is a stochastic subgradient descent step on the loss max⁡(0,−t~ z)\max(0,-\tilde t\,z) (the “perceptron criterion”), with t~=2t−1\tilde t=2t-1: the idea of lesson 4, applied to a different loss because the step’s own loss (counting errors) is flat almost everywhere.

The convergence theorem says: if there is a unit vector u\mathbf{u} and a margin γ>0\gamma>0 with t~i (u⋅xi)≥γ\tilde t_i\,(\mathbf{u}\cdot\mathbf{x}_i)\ge\gamma for every example (with the bias as one more input, equal to 1) and ∥xi∥≤R\lVert\mathbf{x}_i\rVert\le R, the perceptron, starting from zero weights, makes at most (R/γ)2(R/\gamma)^2 mistakes: the bound comes straight out of Novikoff’s proof (1962). With the lesson’s 16 emails, R≈1.63R\approx 1.63 (the largest ∥(x1,x2,1)∥\lVert(x_1,x_2,1)\rVert) and γ≈0.12\gamma\approx 0.12, so the bound is about 190 mistakes; in 300 runs with random order, from zero, it never took more than 31. If the data cannot be separated by a line, it does not converge: the weights never stop moving.

In code

import math

def neuron(x, w, b, activation="step"):
    z = sum(wi * xi for wi, xi in zip(w, x)) + b
    if activation == "step":
        return 1 if z >= 0 else 0
    return 1 / (1 + math.exp(-z))

x, w, b = [0.8, 0.2], [2.0, -1.5], -0.5
print(round(sum(wi * xi for wi, xi in zip(w, x)) + b, 2))   # z
print(neuron(x, w, b))                                       # step
print(round(neuron(x, w, b, "sigmoid"), 3))                  # sigmoid
# 0.8
# 1
# 0.69

And the perceptron rule learning the OR function:

data = [([0, 0], 0), ([0, 1], 1), ([1, 0], 1), ([1, 1], 1)]
w, b, eta = [0.0, 0.0], 0.0, 1.0

def output(x):
    return 1 if w[0] * x[0] + w[1] * x[1] + b >= 0 else 0

for epoch in range(10):
    errors = 0
    for x, t in data:
        y = output(x)
        if y != t:
            w[0] += eta * (t - y) * x[0]
            w[1] += eta * (t - y) * x[1]
            b += eta * (t - y)
            errors += 1
    print(epoch, errors, w, b)
    if errors == 0:
        break
# 0 2 [0.0, 1.0] 0.0
# 1 2 [1.0, 1.0] 0.0
# 2 1 [1.0, 1.0] -1.0
# 3 0 [1.0, 1.0] -1.0

Where it comes from, carefully

McCulloch and Pitts (1943) assumed all-or-none neurons that fire when a fixed number of excitatory synapses is active, with absolute inhibition (a single inhibitory synapse prevents firing) and a network that does not change over time. They showed that such networks can compute functions of propositional logic. They had no weights to be learned.

Rosenblatt (1958) described the perceptron as a system of threshold units: a retina of sensors (S), association units (A) wired at random, and response units (R). The paper describes learning as reinforcement of the A units (the experimenter “forces” the response, or rewards and punishes); it does not contain the rule above. Correcting only when there is an error appears in his laboratory’s 1960 reports, and the single-neuron form is the one taught since.

The Mark I Perceptron (1960 manual): 400 photoresistors in a 20 × 20 grid, 512 A units wired at random to the sensors (generated by a program on an IBM 704 and set on a plugboard), and 8 R units. The values of the A units, the weights, are potentiometers moved by direct-current motors.

The July 1958 demonstration ran on an IBM 704 computer: after 50 trials it told cards marked on the left from cards marked on the right. The Navy’s line about a machine “conscious of its existence” comes from the UPI dispatch that The New York Times published on July 8.

The brain numbers. Azevedo et al. (2009) counted, in adult male brains, 86.1±8.186.1\pm 8.1 billion neurons on average. Beniaguev et al. (2021) needed a temporally convolutional network with five to eight layers to imitate a detailed biophysical model of a layer 5 cortical pyramidal neuron; when they removed the NMDA receptors from the model, a network with a single hidden layer was enough. It is a property of that simulated model, not a measure of every neuron.

What comes next

A single neuron can only separate with a line; lesson 6 shows a case it cannot handle (XOR). Lesson 7 stacks layers with nonlinear activations, and lesson 8 computes the gradient of every weight in the network (backpropagation).

Decision lens

What this idea means if your job is to decide, not to code.

  • When a vendor talks about “neurons” or a system that “thinks like the brain,” translate it: they are formulas with parameters adjusted from data. Ask what data it was trained on and how it was evaluated, not how “intelligent” it seems.
  • A single neuron can be audited: if the inputs are on the same scale, its weights say how much each one contributes to the decision. With billions of parameters, that direct reading is lost. If a decision must be explainable, ask what explanation the system can give.
  • An output between 0 and 1 is not automatically a probability: a 0.9 does not mean “right nine times out of ten.” Check it with your own data before setting decision thresholds (lesson 33).
  • Weights learn what is in the data: if the examples reflect the prejudices or mistakes of whoever labeled them, the neuron reproduces them. And a neuron only separates what a line can separate: ask whether the problem really has that shape.

Terms in this lesson

Full transcript
CommentsThis lesson’s public conversation: questions, facts to check, ideas.

Comments live in GitHub Discussions, in the course’s public repository; writing one requires a GitHub account. They load from giscus.app when you open this section. The course reviewers read them, and if a change is accepted, it is applied in both languages. Open the thread on GitHub

Sources