Skip to content
  • The Neuron & Perceptron · Deep Learning

The Neuron & Perceptron

LearnViaNotes @learnvianotes· 3 min read

An artificial neuron takes a weighted sum of its inputs, adds a bias and passes the result through an activation function. The perceptron is the oldest version — and its failure on XOR explains why we need hidden layers.

z = w₁x₁ + w₂x₂ + … + wₙxₙ + b = w · x + b a = f(z)

PartRole
Inputs xFeatures (pixel values, measurements, outputs of the previous layer)
Weights wHow much each input matters — learned
Bias bShifts the threshold — lets the neuron fire even when all inputs are 0
Activation fA non-linearity (step, sigmoid, ReLU…) applied to the sum z
Python
import numpy as np

x = np.array([0.5, -1.0, 2.0])     # inputs
w = np.array([0.4, 0.3, -0.2])     # weights
b = 0.1                            # bias

z = w @ x + b                      # weighted sum: 0.2 - 0.3 - 0.4 + 0.1
a = 1 / (1 + np.exp(-z))           # sigmoid activation
print(round(z, 2), round(a, 3))    # -0.4 0.401

The perceptron learning rule

Rosenblatt's perceptron (1958) uses a step activation (output 1 if z > 0, else 0) and a simple rule: after each example, nudge the weights toward the right answer.

w ← w + η (y − ŷ) x b ← b + η (y − ŷ)

Python
import numpy as np

X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])

def train_perceptron(X, y, epochs=20, lr=0.1):
    w, b = np.zeros(2), 0.0
    for _ in range(epochs):
        for xi, yi in zip(X, y):
            pred = int(xi @ w + b > 0)
            w += lr * (yi - pred) * xi          # no change when the prediction is right
            b += lr * (yi - pred)
    return (X @ w + b > 0).astype(int).tolist()

print(train_perceptron(X, np.array([0, 0, 0, 1])))       # [0, 0, 0, 1] ← AND: learned
print(train_perceptron(X, np.array([0, 1, 1, 1])))       # [0, 1, 1, 1] ← OR: learned
print(train_perceptron(X, np.array([0, 1, 1, 0]), 1000)) # [1, 1, 0, 0] ← XOR: wrong, whatever the epochs

Why XOR breaks it

A single neuron draws one straight line (a hyperplane) through the input space. AND and OR are linearly separable; XOR is not — no single line puts (0,1) and (1,0) on one side and (0,0), (1,1) on the other. Minsky & Papert's 1969 book made this point and helped cause the first “AI winter”.

Biological neuronArtificial neuron
InputsDendrites receive signalsNumbers x₁…xₙ
IntegrationCell body sums chargeWeighted sum w · x + b
FiringSpikes past a thresholdActivation function f(z)

What is the role of the bias term?

Can a single perceptron learn XOR?

Free for students and teachers

Write notes like this one

Cards for every idea, quizzes and flashcards, read aloud — on the web and your phone.

Something wrong with this note? Open it to report