AIML · Lecture 13 · Classification · Part 3Course homeOpen slide deck  
Artificial Intelligence and Machine Learning · Lecture 13 of 16

Classification · Part 3

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

22 reading sections · 9 interactive examples · Lecture 13 of 16. Use the contents to navigate. Printing retains the worked steps and lab previews.

6 · ClassificationHow 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?

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. 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. Later, we’ll try the same idea on XOR to see where a single straight boundary falls short.

  • 6.1 · McCulloch & Pitts Neuron
  • 6.2 · Perceptron
  • 6.2.1 · Learning rate
  • 6.2.2 · What’s next
Open the corresponding slide ↗

6.1 · McCulloch & Pitts NeuronThe 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.

In the plot, the first switch gives the horizontal coordinate, the second gives the vertical coordinate, and the output gives the class. Try drawing a line that leaves the three class-0 points on one side and the class-1 point on the other.

Each row is one test. The observation index i tells you which test to read. The feature index j tells you which switch to read in that test. In test 3, the second switch is off, so x32 = 0.

Test iFirst switch
j = 1
Second switch
j = 2
Class Y
1000
2010
3100
4111
Interactive example · The AND problem starts with four switch settings
Four AND tests. Test 3 is selected and its second switch is off.
Change the controls and inspect the result. The example pauses when you move away.
Open the corresponding slide ↗

6.1 · McCulloch & Pitts NeuronHow 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

The McCulloch & Pitts neuron is a simplified model of a firing neuron. In the plot, (1, 0) and (0, 1) each give a score of 1, and (1, 1) gives a score of 2. The designer sets b by hand. The indicator returns 1 when its condition holds, including equality at b. On the next slide we plug the switch settings into both formulas and compare two thresholds.

Open the corresponding slide ↗

6.1 · McCulloch & Pitts NeuronWork 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.

Use the same four observations for each threshold. In row 4, x₄₁ = 1 and x₄₂ = 1, so g(x₄) = 2. At b = 2, g(x₄) − b = 0, and the indicator 𝟙(0 ≥ 0) returns 1. At b = 2.5, the same sum gives −0.5, and 𝟙(−0.5 ≥ 0) returns 0. Checking whether g(xᵢ) − b is at least zero is equivalent to checking whether g(xᵢ) is at least b. The next slide finds every b that gives the AND outputs.

Open the corresponding slide ↗

6.1 · McCulloch & Pitts NeuronWhich 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

Class 0 requires its sum to be strictly below b because the neuron fires at equality. The three class-0 rows therefore give 0 < b, 1 < b and 1 < b. Class 1 requires 2 ≥ b. Combining them gives 1 < b ≤ 2. For example, b = 1.9 satisfies both bounds.

Open the corresponding slide ↗

6.1 · McCulloch & Pitts NeuronHow 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?

At b = 1.9, the line x₁ + x₂ = 1.9 separates (1, 1) from the other three inputs. At b = 1, both single-switch inputs lie on the line and predict 1, so the rule acts like OR. At b = 2, (1, 1) lies on the line and still predicts 1. We choose b by hand in this neuron. Select OR to compare the required thresholds.

Interactive example · How does moving the boundary change AND?
Initial threshold experiment at b = 1.9.
Change the controls and inspect the result. The example pauses when you move away.
Open the corresponding slide ↗

6.2 · PerceptronThe 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

The Navy’s photo caption reported perfect recognition in the typeface used for training and 85% after letters in another typeface were added. That is an early example of a generalization question. If the shape of the letters changes, will the same learned weights still work?

Open the corresponding slide ↗

6.2 · PerceptronThe four AND inputs become four clouds

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

The 360 observations vary around the four ideal corners. The target remains class 1 for the upper-right cloud. This motivates learning a weighted separator from examples.

Interactive example · The four AND inputs become four clouds
Initial state of the interactive example: Replace ideal corners with noisy observations
Change the controls and inspect the result. The example pauses when you move away.
Open the corresponding slide ↗

6.2 · PerceptronThe 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

A perceptron is a threshold neuron with learnable weights and bias. A positive weight raises the score as its feature increases, and a negative weight lowers it. In two dimensions the score-zero line separates the predicted classes. Learning the weights lets the model change the line’s direction, and the bias shifts its position. Writing the constant input xᵢ₀ = 1 lets us use the same update rule for the bias and the other weights.

Open the corresponding slide ↗

6.2 · PerceptronHow 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 turning each switch on or off. Each combination starts with zero weights and shows one training example. The initial score of 0 predicts class 1. The AND label is 1 only when both switches are on. For the starting input (1, 0), the AND label is 0. With the update rule on the next slide, this mistake decreases the bias and the first weight by one each. The second weight stays zero. The score for (1, 0) becomes −2, and the same input now predicts class 0. Training then uses the updated weights for the next example. A correct prediction leaves them unchanged.

Open the corresponding slide ↗

6.2 · PerceptronUse 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

For each observation, compute the prediction with the current weights, then use that prediction error to update each weight. The same rule applies to the bias because xᵢ₀ = 1. The index t counts the observations processed during training.

Open the corresponding slide ↗

6.2 · PerceptronWhen has the perceptron finished learning?

Apply the update rule to each observation in turn. After one pass through the training set, start another pass with the latest weights.

When convergence is guaranteed

If the training classes are linearly separable, the perceptron finds a separator after finitely many updates. With two features, a straight line can separate the classes.

How to tell it has converged

Check for one complete pass with no mistakes. Every weight stays the same throughout that pass, so the same rule correctly classifies every training example.

Here convergence means that a full pass makes no updates. A single correct prediction also leaves the weights unchanged for that step. To check convergence, continue through every observation. The finite-update guarantee applies to the standard perceptron on a finite, linearly separable training set. The lab caps the number of passes so that runs on XOR can end.

Try the training example on the slides ↗

6.2 · PerceptronWhy 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

Read steps 2–4 as three lines of the same calculation for a missed class 1. Step 5 switches to the opposite mistake. Each correction moves the score of that example toward the right class. For example, if a missed class 1 starts at −3 and the sum of squared inputs is 2, the score rises to −1 and still predicts 0.

Open the corresponding slide ↗

Which formulas do we use for one update?

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

  1. Find each weight change. Multiply the learning rate by the prediction error and by the input for that weight.
    Δwj=η(yi−y^i)xij
  2. Compute the new score. Multiply each weight change by its input again. Add these contributions to the old score.
    snew=sold+∑j=02Δwjxij
  3. Predict the class. Check the new score against zero.
    y^new={1ifsnew≥00ifsnew<0
η = 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
Open the formula slide ↗

6.2 · PerceptronStep through perceptron learning

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

Try AND with the default order and learning rate η = 1. The weights are listed in order (w₀, w₁, w₂). Compute the old score as w₀ + w₁x₁ + w₂x₂, and predict 1 if the score is zero or higher. The first point (0, 0) has target 0 but starts with score 0, so its prediction is 1. Its error is −1. The correction is (−1, 0, 0) because both features are zero and the bias uses a constant input of 1. The new score is −1, so the same point now predicts 0. A line appears once a feature weight changes and the boundary enters the plot. Use Back to revisit an example. Finish pass processes the rest of the current pass and displays its final example. Training stops after a complete pass with no mistakes or after 25 passes.

Interactive example · Step through perceptron learning
First AND example. The old score is zero, the target is zero, and the update subtracts one from the bias.
Change the controls and inspect the result. The example pauses when you move away.
Open the corresponding slide ↗

6.2 · PerceptronInspect 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.

A line can separate these training classes, so the convergence guarantee applies. The step-through lab may reach a different valid line because the training order and starting weights affect the updates.

Interactive example · Inspect a trained perceptron on noisy AND
Initial state of the interactive example: Compare with the supplied trained perceptron
Change the controls and inspect the result. The example pauses when you move away.
Open the corresponding slide ↗

6.2.1 · Learning rateThe 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

A learning rate sets the update scale. Try 0.25, 1 and 4 in the training lab. In this classic zero-initialized setup, the sign of each score is unchanged by positive rescaling, so the number of mistakes is unchanged. Effects on speed and numerical stability depend on the setup. The basic rule uses η = 1.

Open the corresponding slide ↗

6.2.2 · What’s nextTry 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?

XOR outputs 1 when exactly one input equals 1. The class-0 points are (0,0) and (1,1), and the class-1 points are (1,0) and (0,1). Both classes have the same midpoint (½,½). A single straight separator cannot put their line segments on opposite sides. Try XOR in the perceptron lab to see the updates continue.

Interactive example · Try to separate the four XOR points
Initial state of the interactive example: XOR exposes the limit of one linear separator
Change the controls and inspect the result. The example pauses when you move away.
Open the corresponding slide ↗

6.2.2 · What’s nextWhy 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

Adding the two class-1 inequalities gives w₁ + w₂ + 2w₀ ≥ 0. Since the score at (0,0) requires w₀ < 0, this implies a positive score at (1,1), contradicting its class-0 label. The two classes occupy opposite corners. A multilayer perceptron can solve XOR, as can a suitable nonlinear representation.

Open the corresponding slide ↗

6.2.2 · What’s nextFour 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

The book’s analysis covered more than XOR, including parity and connectedness under restrictions on the units. The two-input example gives us a concrete way to see why the choice of features matters. A new intermediate feature can change which labels a straight line can separate.

Open the corresponding slide ↗

6.2.2 · What’s nextWhat 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

Lighthill’s report discussed a broader concern familiar from the search lectures. Adding more possibilities can make a small working demonstration very expensive at a realistic scale. Meanwhile, researchers kept working on neural networks. To see what a hidden unit changes, give the XOR classifier one extra feature that turns on when both inputs are 1. Add the two input values and subtract twice that feature. The result is 1 for the two cases with exactly one active input and 0 for the other two. This is a concrete feature the output can use to separate the classes.

Open the corresponding slide ↗

Lecture recapWhat 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.
Open the corresponding slide ↗

Further readingBishop on classification

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

Open the corresponding slide ↗
Continue learning