The artificial neuron
What exactly does an artificial neuron do?
Lesson complete
If you like:
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.
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.
Review modeComment on this stepI finished the lesson
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
- 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.
- With two inputs, the points where the sum equals zero form a straight line: the decision boundary. Weights tilt it; the bias shifts it.
- 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.
- 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.
- 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.
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 , weights and bias computes
where is the activation function. With the lesson’s numbers, , and :
With the step, . With the sigmoid, . If and is the identity, we get : the line from lesson 3 is the simplest case of a neuron.
The decision boundary
The neuron changes its answer where , that is, . It is a line whose normal vector is . Its distance from the origin is , and the signed distance from a point to it is . In the example, : the line passes from the origin and the example email sits away.
Changing shifts the line; changing rotates it (if it is vertical: only matters). Multiplying and by does not move the line, but with a sigmoid it changes how sharp the transition is, because the output becomes . With inputs, the boundary is a hyperplane.
Two activations
The step is if and otherwise. The sigmoid is
with maximum slope at . The derivative of the step is zero except at , 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 (the correct answer and the neuron’s answer):
It changes only when , and then . The same example improves: has the right sign. It is a stochastic subgradient descent step on the loss (the “perceptron criterion”), with : 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 and a margin with for every example (with the bias as one more input, equal to 1) and , the perceptron, starting from zero weights, makes at most mistakes: the bound comes straight out of Novikoff’s proof (1962). With the lesson’s 16 emails, (the largest ) and , 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, 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
- Artificial neuron A unit of computation that multiplies each input by a weight, adds the results, adds a bias, and applies an activation function: y = f(w·x + b).
- Dendrite In a biological neuron, each of the branches that receive signals from other neurons. In the artificial neuron they correspond to the inputs.
- Cell body The central part of a biological neuron, where the signals arriving through the dendrites are combined. In the artificial neuron it corresponds to the weighted sum.
- Axon The long extension through which a biological neuron sends its pulse to other neurons when the combined signals are strong enough. In the artificial neuron it corresponds to the output.
- Activation function A function applied to the weighted sum plus the bias to produce the neuron’s output. Examples: the step and the sigmoid.
- Decision boundary The set of points where the neuron changes its answer. With two inputs it is a straight line: w₁x₁ + w₂x₂ + b = 0.
- Perceptron A model proposed by Frank Rosenblatt in 1958: threshold units connected in a network that learn from examples. In its simplest version, a neuron with a step whose weights are corrected only when it is wrong.
- Sigmoid The function σ(z) = 1/(1 + e⁻ᶻ): it turns any number into a value between 0 and 1, and equals 0.5 when z = 0.
- Weight (w) In a linear model, the number that multiplies the input: the slope of the line. It tells how much the prediction rises for each unit the input grows.
- Bias (b) The term added at the end of the model: the prediction when the input is zero, that is, the height at which the line crosses the vertical axis. It is not the bias of data or of an unfair model, which is a different concept.
- Parameter Each of the numbers a model adjusts while training and in which it stores what it learned.
- Feature One measurement of an example expressed as a number: the number of links in an email, the brightness of a pixel. The features of an example make up its vector.
- Prediction (ŷ) The number the model returns for a given input. Comparing it with the real value gives the error.
- Gradient descent A method that adjusts the weights step by step, always against the slope of the error (the gradient), until it reaches a bottom.
- Gradient The list of the slopes of the error, one for each weight. Seen as an arrow, it points to where the error rises fastest.
- Learning rate A number (η) that multiplies the slope and sets the size of each step. Too small is slow; too large bounces or diverges.
Full transcript
Sources
- McCulloch, W. S., Pitts, W. (1943). A logical calculus of the ideas immanent in nervous activity
- Rosenblatt, F. (1958). The perceptron: a probabilistic model for information storage and organization in the brain
- Hay, J. C., Lynch, B. E., Smith, D. R. (1960). Mark I Perceptron Operators’ Manual (Project PARA), informe VG-1196-G-5 del Cornell Aeronautical Laboratory (sección 7.5, apéndice A.1 a A.4 y A.10)
- Novikoff, A. B. J. (1962). On convergence proofs on perceptrons (charla del Symposium on the Mathematical Theory of Automata, vol. 12, pp. 615–622, 1962; la copia en línea es el informe técnico del Stanford Research Institute, enero de 1963)
- Smithsonian National Museum of American History (1958). Electronic Neural Network, Mark I Perceptron (objeto de colección)
- Lefkowitz, M., Cornell Chronicle (2019). Professor’s perceptron paved the way for AI – 60 years too soon
- United Press International (1958). New Navy Device Learns by Doing; Psychologist Shows Embryo of Computer Designed to Read and Grow Wiser (despacho de UPI, The New York Times, 8 de julio de 1958, p. 25)
- Azevedo, F. A. C. et al. (2009). Equal numbers of neuronal and nonneuronal cells make the human brain an isometrically scaled-up primate brain
- Beniaguev, D., Segev, I., London, M. (2021). Single cortical neurons as deep artificial neural networks
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