SECTION 02 / 4

The Perceptron, Weights, Bias and Errors

6 min read
On this page 8 headings
BUILD INTUITION WITH NUMBERS

Weights and bias make one decision

Use weights 1 and 1, bias −1.5, and output 1 when the weighted sum is at least zero.

  1. With both inputs on, calculate the score.

    z=1(1)+1(1)−1.5=0.5⇒y=1z=1(1)+1(1)-1.5=0.5\quad\Rightarrow\quad y=1
  2. Switch the second input off.

    z=1(1)+1(0)−1.5=−0.5⇒y=0z=1(1)+1(0)-1.5=-0.5\quad\Rightarrow\quad y=0

What changed? The bias sets how much positive evidence is needed before the neuron fires.

Quick check: Keep both inputs on, but change the bias to −2.5. What happens?

The score becomes −0.5, so the output is 0.

Swipe long formulas, tables or code sideways to see the rest.

Start here The MP neuron treats every input the same and needs a human to choose θ\theta . In real life some reasons matter more than others. The perceptron gives each input its own weight, accepts real numbers, and — most importantly — can learn its weights from data.

1. Who made it?

  • Frank Rosenblatt, an American psychologist, proposed the perceptron in 1958.
  • Minsky and Papert (1969) refined and carefully analysed it. Their version is the “perceptron” used in this course.

Two main differences from the MP neuron:

  1. Numerical weights w1,w2,…,wnw_{1}, w_{2}, \ldots , w_{n} for the inputs, and a way to learn them.
  2. Inputs are no longer limited to 0/1 — they can be real numbers.

2. The perceptron rule

y=1y = 1 if w1x1+w2x2+…+wnxn≥θy=0w_{1}x_{1} + w_{2}x_{2} + \ldots + w_{n}x_{n} \ge \theta y = 0 otherwise

Now move θ\theta to the left side:

y=1y = 1 if w1x1+…+wnxn−θ≥0w_{1}x_{1} + \ldots + w_{n}x_{n} - \theta \ge 0

The neat trick: add a fake input x0=1x_{0} = 1 with weight w0=−θw_{0} = -\theta . Then −θ=w0x0-\theta = w_{0}x_{0}, and the rule becomes one clean sum starting at i=0i = 0:

  • y=1y = 1 if ∑i=0nwixi≥0\sum _{i=0}^{n} w_{i}x_{i} \ge 0
  • y=0y = 0 if ∑i=0nwixi<0\sum _{i=0}^{n} w_{i}x_{i} < 0
The bias is just one more weight, attached to an input that is always 1.
The bias is just one more weight, attached to an input that is always 1.
Open image ↗
Perceptron with x0 = 1 and w0 = -theta feeding a summing unit

3. Why weights? Why “bias”?

Lecture example — will I like this movie? Inputs (0 or 11): x_{1} = isActorDamon, x2=x_{2} = isGenreThriller, x3=x_{3} = isDirectorNolan. From past viewing we know Nolan movies are almost always liked. So we give w3abigw_{3} a big weight. Even if the actor is not Matt Damon and it is not a thriller, w3w_{3} alone can push the sum over the threshold.

Weights == importance. A bigger weight means that input matters more.

w0w_{0} is called the bias because it represents a prior (prejudice) — how easily you say “yes” before looking at anything.

Viewer Threshold θ\theta Meaning
Movie buff θ=0\theta = 0 watches anything — genre, actor, director don’t matter
Very selective viewer θ=3\theta = 3 watches only thrillers with Matt Damon directed by Nolan (all 3 must be 1)
The bias is how easily you say “yes” before looking at the inputs.
The bias is how easily you say “yes” before looking at the inputs.
Open image ↗
Movie buff with threshold 0 watches everything; selective viewer with threshold 3 needs all three features

Both the weights and the bias are learned from data (here, the viewer’s history).

Why do we keep studying Boolean functions? Because they are the simplest test case. If a model can’t even do AND/OR/XOR, it can’t do real tasks. And “like/dislike a movie” is itself a yes/no (Boolean) decision.

4. Perceptron vs MP neuron

MP neuron Perceptron
Inputs only 0/1 real numbers allowed
Weights none (all equal) each input has a weight wiw_{i}
Threshold hand-chosen learned (as bias w0w_{0})
Learning algorithm none yes (next page)
What it can represent linearly separable functions still only linearly separable functions

Very important: a perceptron also splits the input space into two halves with a line (plane). So it also can only do linearly separable functions. The difference is that its line can be learned and placed anywhere.

5. Finding weights for OR by hand

For the perceptron to do OR, each row of the truth table gives one condition:

x1x_{1} x2x_{2} OR Condition Simplifies to
0 0 0 w0+w1⋅0+w2⋅0<0w_{0} + w_{1}\cdot 0 + w_{2}\cdot 0 < 0 w0<0w_{0} < 0
0 1 1 w0+w1⋅0+w2⋅1≥0w_{0} + w_{1}\cdot 0 + w_{2}\cdot 1 \ge 0 w2≥−w0w_{2} \ge -w_{0}
1 0 1 w0+w1⋅1+w2⋅0≥0w_{0} + w_{1}\cdot 1 + w_{2}\cdot 0 \ge 0 w1≥−w0w_{1} \ge -w_{0}
1 1 1 w0+w1⋅1+w2⋅1≥0w_{0} + w_{1}\cdot 1 + w_{2}\cdot 1 \ge 0 w1+w2≥−w0w_{1} + w_{2} \ge -w_{0}

One solution: w0=−1,w1=1.1,w2=1.1.w_{0} = -1, w_{1} = 1.1, w_{2} = 1.1. Check every row:

  • (0,0):−1+0+0=−1<0→0✔(0,0): -1 + 0 + 0 = -1 < 0 \to 0 ✔
  • (0,1):−1+0+1.1=0.1≥0→1✔(0,1): -1 + 0 + 1.1 = 0.1 \ge 0 \to 1 ✔
  • (1,0):−1+1.1+0=0.1≥0→1✔(1,0): -1 + 1.1 + 0 = 0.1 \ge 0 \to 1 ✔
  • (1,1):−1+1.1+1.1=1.2≥0→1✔(1,1): -1 + 1.1 + 1.1 = 1.2 \ge 0 \to 1 ✔

Many other solutions also work (for example w0=−1,w1=1,w2=1w_{0} = -1, w_{1} = 1, w_{2} = 1).

6. Errors and the error surface

Fixw0=−1Fix w_{0} = -1 and try different (w1,w2)(w_{1}, w_{2}). Count how many of the 4 OR rows come out wrong.

w1w_{1} w2w_{2} errors Working
−1 −1 3 (0,0): −1 → 0 ✔; (1,0): −2 → 0 ✘; (0,1): −2 → 0 ✘; (1,1): −3 → 0 ✘
1.5 0 1 (0,1):−1+0=−1→0(0,1): -1 + 0 = -1 \to 0 ✘; others correct
10 −10 2 (0,1): −11 → 0 ✘; (1,1): −1 → 0 ✘

Note on the slide: the lecture table lists 1 error for w1=−1,w2=−1w_{1} = -1, w_{2} = -1. Working it out (above) gives 3 errors: (1,0), (0,1) and (1,1) all give a negative sum, so the output is 0 when OR says 1. Only (0,0) is correct.

If we work out the error count for every possible (w1,w2)(w_{1}, w_{2}) and plot it, we get the error surface. Each point on it is one choice of weights; we want to reach a point with 0 errors.

For OR, an error happens if:

  • (x1,x2)=(0,0)(x_{1}, x_{2}) = (0,0) but w0+w1x1+w2x2≥0w_{0} + w_{1}x_{1} + w_{2}x_{2} \ge 0, or
  • (x1,x2)≠(0,0)(x_{1}, x_{2}) \ne (0,0) but w0+w1x1+w2x2<0w_{0} + w_{1}x_{1} + w_{2}x_{2} < 0.

Trying values by hand is slow. We need an algorithm that finds weights with zero error — that is the Perceptron Learning Algorithm.

In one line: A perceptron is an MP neuron with learnable weights and bias; it still draws only one line, but it can learn where to draw it.

Exam words: perceptron, Rosenblatt (1958), Minsky–Papert (1969), weight, bias w0=−θ,x0=1w_{0} = -\theta , x_{0} = 1, prior/prejudice, error surface, linearly separable.

Quick check

  1. Why do we addx0=1add x_{0} = 1 and w0=−θw_{0} = -\theta ?
So the threshold becomes just another weight. The rule becomes ∑i=0nwixi≥0\sum _{i=0}^{n} w_{i}x_{i} \ge 0, and the threshold can be learned like any other weight.
  1. A perceptron has w0=−2,w1=1,w2=1w_{0} = -2, w_{1} = 1, w_{2} = 1. Which Boolean function?
AND. (1,1):−2+1+1=0≥0→1(1,1): -2 + 1 + 1 = 0 \ge 0 \to 1. All other rows give −1 or −2 → 0.
  1. Can a single perceptron represent more functions than a single MP neuron (no inhibitory inputs)?
No new kinds of Boolean functions — both only represent linearly separable functions. The perceptron’s advantage is real-valued inputs, weights, and learning.
  1. With w0=−1,w1=2,w2=−0.5w_{0} = -1, w_{1} = 2, w_{2} = -0.5, how many OR errors?
(0,0): −1 → 0 ✔. (1,0): 1 → 1 ✔. (0,1): −1.5 → 0 ✘. (1,1): 0.5 → 1 ✔. So 1 error.
  1. What does a “movie buff” with θ=0\theta = 0 mean in perceptron terms?
The bias w0=−θ=0w_{0} = -\theta = 0, so the perceptron fires even when all inputs are 0 — a very low threshold / strong prior towards “yes”.
YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑