Artificial Intelligence and Machine Learning · Lecture 13 of 16

Classification · Part 3

McCulloch & Pitts neuron and perceptron

From a hand-set threshold for AND to a learned separator. XOR shows the limit of a single straight boundary.

6.1 · McCulloch & Pitts Neuron
6.2 · Perceptron
6.2.1 · Learning rate
6.2.2 · What’s next
6 · Classification

How can we classify by location?

In Part 2, we used nearby examples to classify a new point. Now we’ll focus on the geometry of the decision. What separates the parts of the plot that get different labels?

What is a separator?

A separator, also called a discriminant, is a decision rule that divides the input space into regions. A new point gets the label of the region it lands in.

How many regions?

With C classes, there are C prediction regions, one for each label. For two classes, a straight line can serve as the boundary if the classes lie on opposite sides.

Can one line separate the two classes in a plot of switch settings? We’ll start with logical AND, set a rule by hand, then see how a perceptron can learn one from examples.
6.1 · McCulloch & Pitts Neuron

The AND problem starts with four switch settings

Each switch is off (0) or on (1). Our task is to predict the output of logical AND, which is 1 only when both switches are on.

6.1 · McCulloch & Pitts Neuron

How can a threshold neuron model AND?

For each switch setting xᵢ, the neuron adds the two inputs. The sum g(xi) counts how many switches are on. The neuron predicts 1 when the score reaches the threshold b, and 0 otherwise. To model AND, only the setting (1, 1) should reach b.

g(xi)=∑j=1mxij
y^i={1if g(xi)≥b0otherwise=1(∑j=1mxij−b≥0)
i = observation indexj = feature index (1 to m)xᵢ = input vector for observation ixᵢⱼ = feature j of observation im = number of input featuresg(xᵢ) = sum of the inputs for observation ib = threshold (called bias in this neuron)ŷᵢ = predicted class
6.1 · McCulloch & Pitts Neuron

Work out the neuron’s output for two thresholds

Each row i is one switch setting. Here m = 2. Add the two inputs to get g(xᵢ), subtract b, then use the indicator 𝟙. It gives 1 for zero or positive results and 0 otherwise.

Row iFirst input xi1Second input xi2Sum g(xᵢ)Threshold b = 2Threshold b = 2.5
g(xᵢ) − bOutput ŷᵢg(xᵢ) − bOutput ŷᵢ
1000 + 0 = 00 − 2 = −2𝟙(−2 ≥ 0) = 00 − 2.5 = −2.5𝟙(−2.5 ≥ 0) = 0
2010 + 1 = 11 − 2 = −1𝟙(−1 ≥ 0) = 01 − 2.5 = −1.5𝟙(−1.5 ≥ 0) = 0
3101 + 0 = 11 − 2 = −1𝟙(−1 ≥ 0) = 01 − 2.5 = −1.5𝟙(−1.5 ≥ 0) = 0
4111 + 1 = 22 − 2 = 0𝟙(0 ≥ 0) = 12 − 2.5 = −0.5𝟙(−0.5 ≥ 0) = 0
With b = 2, only (1, 1) reaches the threshold. Its adjusted score is exactly 0, so it predicts 1.
With b = 2.5, even (1, 1) falls below the threshold. Every row predicts 0.
6.1 · McCulloch & Pitts Neuron

Which thresholds reproduce AND?

X₁X₂X₁ + X₂Y
0000
0110
1010
1121

Keep class 0 below the threshold

0+0<b,0+1<b,1+0<b⟹b>1

The largest class-0 sum is 1. A threshold of 1 would also fire for a single active input.

Let class 1 reach the threshold

1+1≥b⟹b≤2

The only class-1 row has sum 2. A threshold of 2 still fires at equality.

Combine the two bounds

1<b≤2⟺b∈(1,2]

This interval contains every threshold that classifies all four AND inputs correctly.

X₁ and X₂ = binary inputsY = AND outputb = threshold
6.1 · McCulloch & Pitts Neuron

How does moving the boundary change AND?

Start at b = 1.9 and find the only input on the class-1 side. Then try b = 1 and b = 2. Which points land on the line, and what does the neuron predict for them?

6.2 · Perceptron

The machine that learned to read letters

Archival photograph of the Mark I Perceptron and its electronic cabinets.
Mark I Perceptron, U.S. Navy photograph (1960)

In 1958, Frank Rosenblatt asked how memory changes what we recognize.

“In what form is information stored, or remembered?”

The Mark I saw a letter through 400 light sensors. Its adjustable weights were physical components turned by little motors.

A trainer corrected the machine when it guessed wrong. We’ll do the same with the weights of a separator.

Rosenblatt’s 1958 paper, p. 386 · Hardware details, fig. 4.8

6.2 · Perceptron

The four AND inputs become four clouds

Inspect how the input coordinates vary. The upper-right cloud still has class 1.

6.2 · Perceptron

The perceptron learns a weighted threshold rule

To separate the noisy classes, the perceptron uses a weighted McCulloch & Pitts neuron (MPN). It learns the weights w = (w₀, …, wₘ) from labeled examples, so some inputs can have more influence than others.

y^i= 𝟙 ( ∑j=0m wjxij ≥0) = 𝟙 ( ∑j=1m wjxij+w0 ≥0)

Why are the forms equal? The sum starting at j = 0 includes the term w₀xᵢ₀. Since xᵢ₀ = 1 for every observation, that term is just w₀. The second form writes it outside the sum.
Setting every feature weight to 1 and w₀ = −b gives the original MPN rule with threshold b.

wⱼ = weight for feature j, w₀ = biasxᵢⱼ = feature j of observation ixᵢ₀ = 1 for every observationm = number of input featuresŷᵢ = predicted class (0 or 1)𝟙 = indicator function
6.2 · Perceptron

How does a perceptron learn its weights?

Predict

Switch 1On (1)
Switch 2Off (0)
Zero weights give a score of 0.
A score of 0 predicts class 1.

Compare

Initial prediction1
AND label0
Mismatch

Adjust the weights

Now predicts class 0.
Try the switches. Each combination starts from zero weights.
6.2 · Perceptron

The perceptron in action

Watch on YouTube ↗
6.2 · Perceptron

Use the prediction error to update the weights

The update is inspired by Hebbian learning, a principle that links connection strength to neuron activity. The perceptron uses the known label to decide how to correct its prediction.

wj(t+1)=wj(t)+(yi−y^i)xij(j=0,…,m)
Observed labelPredicted labelChange to each weight
00Keep the weights
11Keep the weights
10Add each input component
01Subtract each input component
yᵢ = observed class, ŷᵢ = predicted classxᵢⱼ = feature j of observation it = current step, t + 1 = next stepj = weight index, including j = 0 for the bias
6.2 · Perceptron

Why does the correction move the score?

Compare the weighted score for the same example before and after one update. Zero or more predicts class 1. A negative score predicts class 0.

Correct prediction

yi=y^i⟹wj(t+1)=wj(t)

The predicted class matches the observed class, so yᵢ − ŷᵢ = 0. The update adds 0 to every weight, leaving the score for this example unchanged.

Missed a class 1

∑j=0mwj(t+1)xij=∑j=0m(wj(t)+xij)xij

The true class is 1 and the prediction is 0. Put the error 1 − 0 into the update rule for one weight.

wj(t+1)=wj(t)+(1−0)xij=wj(t)+xij

In the right sum, the xᵢⱼ inside the parentheses comes from this weight update. The xᵢⱼ outside is the input we multiply by to score the same example again.

Expand the product

∑j=0mwj(t+1)xij=∑j=0m(wj(t)xij+xij2)

In the right-hand sum, multiply the outside xᵢⱼ by both terms in parentheses. The old weight gives wⱼ⁽ᵗ⁾xᵢⱼ. The added input gives xᵢⱼ × xᵢⱼ = xᵢⱼ².

Separate the sums

∑j=0mwj(t+1)xij=∑j=0mwj(t)xij+∑j=0mxij2

Collect the old weighted inputs into the first sum. That is the old score. The second sum adds the squared inputs. This increases the score because xᵢ₀ = 1 contributes 1². The prediction becomes 1 when the new score reaches zero or above.

Predicted 1 by mistake

∑j=0mwj(t+1)xij=∑j=0mwj(t)xij−∑j=0mxij2

Now the true class is 0 and the prediction is 1, so the error is −1. Each new weight is the old weight minus its input. The same multiplication gives old score minus the sum of squared inputs. A negative new score predicts class 0.

yᵢ = observed class, ŷᵢ = predicted classxᵢⱼ = feature j of observation ixᵢ₀ = 1wⱼ⁽ᵗ⁾ and wⱼ⁽ᵗ⁺¹⁾ = weight before and after the updatet = current update stepm = number of input features
6.2 · Perceptron

Which formulas do we use for one update?

Use the old score and the change in each weight to rescore the same example.

Find each weight change

Δwj=η(yi−y^i)xij

Multiply the learning rate by the prediction error and by the input for that weight.

Compute the new score

snew=sold+∑j=02Δwjxij

Multiply each weight change by its input again. Add these contributions to the old score.

Predict the class

y^new={1ifsnew≥00ifsnew<0

Check the new score against zero.

η = learning rateyᵢ = true label, ŷᵢ = initial predictionΔwⱼ = change to weight jxᵢⱼ = input j of this examplej = 0 is the bias input, with xᵢ₀ = 1j = 1 and j = 2 are the two features
6.2 · Perceptron · Worked answer

What changes after one perceptron update?

The starting score is −7, the true label is 1, and the prediction is 0. The learning rate η is 1. Use inputs (1, 2, −1), with the bias input first.

StepFormulaWith these numbers

Update each weight

Δwj=η(yi−y^i)xij
Δw0=1(1−0)(1)=1Δw1=1(1−0)(2)=2Δw2=1(1−0)(−1)=−1

Compute the new score

snew=sold+∑j=02Δwjxij
−7+1×1+2×2+(−1)×(−1)=−1

Predict the class

y^new={1ifsnew≥00ifsnew<0
−1<0⇒y^new=0
Answer D. Score −1, prediction 0.Δwⱼ = change to weight jxᵢⱼ = input j of this example
6.2 · Perceptron

Step through perceptron learning

Choose Next example to follow the circled point. Compare its prediction before the update with its score afterward.

6.2 · Perceptron

Inspect a trained perceptron on noisy AND

This trained perceptron separates all 360 noisy training points. Select a point to see which side of the learned line it falls on.

6.2.1 · Learning rate

The learning rate controls the size of a correction

wj(t+1)=wj(t)+η(yi−y^i)xijη>0

One mistake

Doubling η doubles the size of that weight correction.

A complete run

With zero initial weights, fixed order and constant positive η, the weights scale with η and the mistake sequence stays the same in exact arithmetic.

η = positive learning rateyᵢ = observed class, ŷᵢ = predicted classxᵢⱼ = feature j of observation iwⱼ⁽ᵗ⁾ = weight before this update
6.2.2 · What’s next

Try to separate the four XOR points

Change AND to “exactly one switch is on.” Can you draw a single line that separates the two labels?

6.2.2 · What’s next

Why one line cannot separate XOR

Class 0 at (0,0) and (1,1)

w0<0
w1+w2+w0<0

Class 1 at (1,0) and (0,1)

w1+w0≥0
w2+w0≥0

w1+w2+w0≥−w0>0
wⱼ = weight for feature j, w₀ = biasOutput 1 at a score of zero or aboveOutput 0 at a negative score
6.2.2 · What’s next

Four points, one line, and a famous book

Marvin Minsky and Seymour Papert’s 1969 book Perceptrons studied the limits of this kind of classifier. XOR is the smallest parity example. It asks whether the number of active inputs is odd.

What made it worth studying

“worthy of study despite (and even because of!) its severe limitations”

We just saw one such limit. A straight line through the two original features cannot separate XOR.

What they left open

“elucidate (or reject) our intuitive judgment that the extension is sterile”

They were skeptical that adding layers would yield a useful learning rule. Their wording invites a test of that conjecture.

Minsky & Papert, Perceptrons (1969) · §13.2, pp. 231–232

6.2.2 · What’s next

What cooled during the first AI winter?

The first AI winter was a period of reduced interest and funding for parts of AI research. The perceptron debate was one part of a broader slowdown.

1960s · Funding was already tightening

Rosenblatt struggled to secure funding for larger projects before the 1969 book appeared.

1973 · The UK scrutinized AI

James Lighthill’s review asked why methods that worked on small examples struggled as the number of possibilities exploded.

1986 · XOR returned as a test case

Rumelhart, Hinton and Williams showed how backpropagation could train hidden units that let a network solve XOR.

In Part 4, we’ll ask what happens when a classifier gets a different set of features to work with.

Funding history · Lighthill’s report · The 1986 XOR experiments

Lecture recap

What to take away

  • Use an input sum and a threshold to reproduce AND.
  • Explain how a perceptron learns by correcting mistakes.
  • Use XOR to explain the limits of a single linear separator.
Further reading

Bishop on classification

Read chapters 4 and 7 for linear discriminants, perceptron learning, and support vector machines.

Continue learning
AIML · Lecture 13 · Classification · Part 3
Course home