Perceptron

The simplest artificial neuron: a weighted vote followed by a hard decision.

The Big Question

So far, we have learned models that fit lines, build trees, transform features, compress representations, and discover groups. Deep learning begins with a smaller question.

What is the simplest computational unit that can learn from data?

The answer is the perceptron. A perceptron is one artificial neuron. By itself, it is limited. Combined with many other neurons, it becomes the building block of modern neural networks.

Historical Motivation

In 1958, Frank Rosenblatt introduced the perceptron. Researchers wanted machines inspired by the brain: units that receive signals, combine them, and fire when the combined signal is strong enough.

The perceptron was a mathematical version of that idea. It was primitive, but it started the neural-network story.

Core Intuition

Imagine predicting whether Jessie orders a burger using hours since last meal, burger price, and number of friends ordering burgers.

FeatureValueVote
Hours since last meal8probably hungry
Burger price$15a little expensive
Friends ordering burgers4social pressure

The perceptron gives every feature a weight. Positive weights push toward Burger. Negative weights push toward No Burger. Weights near zero mean the feature barely matters.

This should feel familiar. A perceptron is logistic regression stripped down to its most basic neural idea: compute one weighted sum, then make one decision.

Interactive Demo

Weighted vote lab

Evidence contributions

Hours6.40
Price-3.00
Friends2.00
Bias-2.00
Decision boundary

Current line classifies 6/6 points correctly.

Weighted sum
3.40
Step output
Burger

Positive evidence pushes the score up. Negative evidence pushes it down. The step function turns the score into a hard decision, not a probability.

Adjust the weights and inputs. The perceptron has no probability output. The score either crosses the threshold or it does not.

Mathematics

The Artificial Neuron

Suppose the input vector is xx and the weights are ww. The perceptron first computes:

z=wTx+bz=w^Tx+b

Expanded for three features:

z=w1x1+w2x2+w3x3+bz=w_1x_1+w_2x_2+w_3x_3+b

This quantity is sometimes called the activation or logit. The equation is the same weighted sum used by linear regression and logistic regression.

The Step Function

The perceptron turns the weighted sum into a hard decision with a step function:

y^={1,z00,z<0\hat y=\begin{cases}1,&z\ge0\\0,&z<0\end{cases}

If the total evidence is positive, predict Burger. Otherwise, predict No Burger. Unlike a sigmoid, the step function does not produce probabilities.

Worked Example

Suppose x1=8x_1=8 hours since meal, x2=15x_2=15 dollars, and x3=4x_3=4 friends.

w=[0.80.20.5],b=2w=\begin{bmatrix}0.8\\-0.2\\0.5\end{bmatrix},\quad b=-2
z=0.8(8)0.2(15)+0.5(4)2z=0.8(8)-0.2(15)+0.5(4)-2
z=6.43+22=3.4z=6.4-3+2-2=3.4

Since z>0z>0, the perceptron predicts Burger. The calculation is interpretable as weighted evidence: hunger and friends push up, price pushes down.

The Decision Boundary

Because the score is linear, a single perceptron learns a linear decision boundary. In two dimensions, the boundary is a line. In three dimensions, it is a plane. In higher dimensions, it is a hyperplane.

The Learning Rule

If the perceptron makes a mistake, move the weights so the correct answer becomes more likely:

ww+η(yy^)xw\leftarrow w+\eta(y-\hat y)x

Here yy is the true label, y^\hat y is the prediction, and η\eta is the learning rate.

If Jessie did not order a burger but the model predicted Burger, then yy^=1y-\hat y=-1. With η=0.1\eta=0.1:

wnew=w0.1xw_{\text{new}}=w-0.1x
[0.80.20.5]0.1[8154]=[01.70.1]\begin{bmatrix}0.8\\-0.2\\0.5\end{bmatrix}-0.1\begin{bmatrix}8\\15\\4\end{bmatrix}=\begin{bmatrix}0\\-1.7\\0.1\end{bmatrix}

The features that incorrectly pushed the model toward Burger are weakened. Unlike gradient descent, this update happens only when the perceptron is wrong.

Why It Works

If the prediction is correct, yy^=0y-\hat y=0, so nothing changes. If the prediction is wrong, the weights move in a direction that makes the correct label more likely for that example.

If the data is linearly separable, the Perceptron Convergence Theorem says this learning rule will find a separating hyperplane in a finite number of updates. If the data is not linearly separable, it may never converge.

Perceptron Versus Logistic Regression

Weighted sumw^T x + bw^T x + b
ActivationStep functionSigmoid
OutputHard class decisionProbability
LearningMistake-driven updateGradient descent on log loss
Modern useHistorical building blockPractical linear classifier

Why One Perceptron Is Limited

A single perceptron cannot solve XOR:

x1x2XOR
000
011
101
110

No single straight line separates the positive and negative XOR examples. The solution is not a better single perceptron. The solution is to connect perceptrons in layers.

Implementation

This implementation trains a perceptron from scratch. Labels are encoded as 0 and 1. The update happens only when the prediction is wrong.

import numpy as np

class Perceptron:
    def __init__(self, learning_rate=0.1, epochs=20):
        self.learning_rate = learning_rate
        self.epochs = epochs
        self.w = None
        self.b = 0.0

    def step(self, z):
        return 1 if z >= 0 else 0

    def fit(self, X, y):
        self.w = np.zeros(X.shape[1])
        self.b = 0.0

        for _ in range(self.epochs):
            for x_i, y_i in zip(X, y):
                z = np.dot(self.w, x_i) + self.b
                y_hat = self.step(z)
                error = y_i - y_hat

                if error != 0:
                    self.w += self.learning_rate * error * x_i
                    self.b += self.learning_rate * error

        return self

    def predict(self, X):
        scores = X @ self.w + self.b
        return np.where(scores >= 0, 1, 0)

Interview Discussion

What is a perceptron?

A perceptron is a single artificial neuron that computes a weighted sum and applies a step function to produce a binary decision.

How does it differ from logistic regression?

Both compute the same weighted sum. Logistic regression applies a sigmoid and outputs a probability; the perceptron applies a step function and outputs a hard class.

Why is the step function problematic?

It is not differentiable in a useful way, so it cannot be trained with backpropagation like modern neural networks.

Why can a perceptron not solve XOR?

XOR is not linearly separable, and a single perceptron can only draw one linear decision boundary.

When is the perceptron guaranteed to converge?

When the data is linearly separable, the perceptron learning algorithm finds a separating hyperplane in finite updates.

Active Recall

1. What computation does every perceptron perform before applying the activation function?

2. Why is the step function not suitable for modern deep learning?

3. Write the perceptron update rule from memory.

4. What assumption is required for the Perceptron Convergence Theorem?

5. Why did the XOR problem motivate multi-layer neural networks?

Common Mistakes

  • Thinking the perceptron is fundamentally unrelated to logistic regression.
  • Assuming the perceptron outputs probabilities.
  • Believing a single perceptron can solve any classification problem.
  • Confusing the perceptron learning rule with gradient descent.

Connection To Neural Networks

Representation learning showed that models can automatically discover useful features. The perceptron provides the simplest computational unit capable of learning from data. By itself, it is limited. Connected with other perceptrons, it becomes the beginning of neural networks.