perceptron
how it works
The idea in a few sentences and three pictures, then one run played step by step.
A perceptron splits two kinds of points, triangles and squares, with one straight line. It keeps the line as three numbers. A spot's score is the first number times its steps right of the plane's middle, plus the second times its steps up, plus the third. A step left or down counts as minus 1. Over 0 is the triangles' side and under 0 the squares'. A score of 0 is on the line, on neither side. The line starts upright through the middle, as 1, 0 and 0. Then the points are checked one by one, pass after pass. A point not on its own side nudges the line. For a triangle, the step size times its steps right, its steps up and 1 are added to the three numbers. For a square they are taken away. The run stops at the first pass that nudges nothing, or after six passes. Take triangles at 2 6, 4 9 and 3 3, squares at 6 4, 8 7 and 7 1, and step size 0.5. Each point is written across then up, and the middle is 5 5. So 2 6 stands 3 left and 1 up: minus 3 and 1. It scores 1 times minus 3, which is minus 3: the squares' side, so it is wrong. Add 0.5 times minus 3, 1 and 1. The line becomes minus 0.5, 0.5 and 0.5, and 2 6 now scores 2.5. The next three points are on their own sides. The square at 8 7 stands 3 right and 2 up. It scores minus 1.5 plus 1 plus 0.5, which is 0: on the line, so wrong. Take away 0.5 times 3, 2 and 1, and the line becomes minus 2, minus 0.5 and 0. Pass 1 made 2 nudges. In pass 2 the triangle at 4 9 scores 0, and its nudge leaves minus 2.5, 1.5 and 0.5. Pass 3 finds every point on its own side. That is 3 nudges, and 3 passes of 6 checks, 18 in all. A nudge that puts one point right can put another wrong, as the square's did to 4 9. Even so, with no limit on the passes, the nudges end whenever some line splits the points. Questions 2 to 4 show it for these six. Square the line's three numbers and add them: each nudge here adds 5.25 at most. Yet each nudge takes 0.5 or more off the first number, so by 26 nudges its square alone would pass the most that sum can reach. It never can, so the nudges must stop by 25. When no line splits the points, no pass can nudge nothing, as question 5 shows.
Pass 3 nudged nothing, so the run stops there. After 3 nudges the line has every point on its own side.
With scripts on, a slider sets the passes and a selector swaps the points. The plane, the chart and this line change with them.
| nudge | wrong point | its score | a step right adds | a step up adds | every score starts at |
|---|---|---|---|---|---|
| before any | 1 | 0 | 0 | ||
| 1 | triangle 2 6 | -3 | -0.5 | 0.5 | 0.5 |
| 2 | square 8 7 | 0 | -2 | -0.5 | 0 |
| 3 | triangle 4 9 | 0 | -2.5 | 1.5 | 0.5 |
step 1 of 25
6 points. The line starts upright through the middle. A point's score starts at 0, and each step it stands right of the middle adds 1; a step left takes 1 away. Over 0 is the triangles' side, under 0 the squares'. Your step size is 0.5.
what it remembers to know where it is
- pass
- not yet
- each step right adds
- 1
- each step up adds
- 0
- every score starts at
- 0
Where it says not yet, nothing is held there at that moment.
step 2 of 25
Pass 1, point 1: the triangle at 2 6 scores -3. Under 0 is the squares' side. It is not on its own side, so it is ringed.
what it remembers to know where it is
- pass
- 1
- each step right adds
- 1
- each step up adds
- 0
- every score starts at
- 0
step 3 of 25
Nudge the line. A triangle's score must rise, so add 0.5 × -3 to what a step right adds, 0.5 × 1 to what a step up adds and 0.5 to the start: now -0.5, 0.5 and 0.5. The point scores 2.5.
what it remembers to know where it is
- pass
- 1
- each step right adds
- -0.5
- each step up adds
- 0.5
- every score starts at
- 0.5
step 7 of 25
Pass 1, point 5: the square at 8 7 scores 0. A score of 0 is on neither side. It is not on its own side, so it is ringed.
what it remembers to know where it is
- pass
- 1
- each step right adds
- -0.5
- each step up adds
- 0.5
- every score starts at
- 0.5
step 8 of 25
Nudge again: take away 0.5 × 3, 0.5 × 2 and 0.5. The numbers are now -2, -0.5 and 0. The point's score goes from 0 to -7.
what it remembers to know where it is
- pass
- 1
- each step right adds
- -2
- each step up adds
- -0.5
- every score starts at
- 0
step 12 of 25
Pass 2, point 2: the triangle at 4 9 scores 0. A score of 0 is on neither side. It is not on its own side, so it is ringed.
what it remembers to know where it is
- pass
- 2
- each step right adds
- -2
- each step up adds
- -0.5
- every score starts at
- 0
step 13 of 25
Nudge again: add 0.5 × -1, 0.5 × 4 and 0.5. The numbers are now -2.5, 1.5 and 0.5. The point's score goes from 0 to 9.
what it remembers to know where it is
- pass
- 2
- each step right adds
- -2.5
- each step up adds
- 1.5
- every score starts at
- 0.5
step 25 of 25
Pass 3 found every point on its own side, so the line splits the triangles from the squares. It took 3 nudges and 18 checks.
what it remembers to know where it is
- pass
- 3
- each step right adds
- -2.5
- each step up adds
- 1.5
- every score starts at
- 0.5
the steps, in plain words
choose a step to mark the Python, a programming language, that does it
- start with an upright line through the middlePython lines 12 and 13
- repeat, a pass over the pointsPython lines 14 and 15
- work out each point's scorePython lines 16, 17, 18 and 19
- if it is not on its own side, nudge the linePython lines 20, 21, 22, 23 and 24
- until a pass nudges nothing, or the passes run outPython lines 25, 26 and 27
the same in Python
The steps in plain words are what to learn. Python is a programming language, and the code below does the same steps, for those who code. Python numbers the places in a list from 0, not 1: the first number is numbers[0], the second numbers[1], and so on.
def perceptron(points, rate):
"""The line the passes end on, as its three numbers.
points are (across, up, shape) tuples, each shape "triangle" or
"square". A spot's score is the first number times its steps right
of the middle, 5 5, plus the second times its steps up, plus the
third. Over 0 is the triangles' side. A point not on its own side
nudges the line: rate times its steps right, its steps up and 1,
added for a triangle and taken away for a square. The sums are done
in whole tenths, so a score on the line is exactly 0.
"""
step = round(rate * 10) # the step size, in tenths
across, up, base = 10, 0, 0 # start with an upright line through the middle
for _ in range(6): # a pass over the points, six at most
nudged = False
for x, y, shape in points:
right, above = x - 5, y - 5 # its steps from the middle
want = 1 if shape == "triangle" else -1
score = across * right + up * above + base # in tenths
if score * want <= 0: # on the wrong side, or on the line
across += step * want * right # nudge the line
up += step * want * above
base += step * want
nudged = True
if not nudged:
break # a whole pass nudged nothing
return across / 10, up / 10, base / 10
how it scales
How the checks grow, from ten points to ten thousand.
Each step across or up is ten times the one before, a log-log plot. Both lines climb one step up for each step across: ten times the points, ten times the checks. The run that makes all six passes sits six times higher than the run that makes one, against .
points checked, ten times more at each mark up
, how many points there are, ten times more at each mark to the right
- points along one row, a triangle then a square by turns, which no line can split, so all six passes are madesolid where measured by running it; dashed where its formula carries it on to ten millionslope 1: ten times n, 10 times the work
- triangles in a column right of the middle and squares in a column left of it, which the starting line already splits, so the first pass nudges nothingsolid where measured by running it; dashed where its formula carries it on to ten million
| points checked | time | |
|---|---|---|
| 1,000 | 6,000 | about 6 microseconds |
| 100,000 | 600,000 | about 600 microseconds |
| 10,000,000 | 60,000,000 | about 60 milliseconds |
The points checked are the same on any computer. The times are not: a real computer may be faster or slower than a billion a second.
make these counts yourself
Copy this script and run it with Python 3.12 or later. It counts the same steps as the plot. Where a count depends on a random shuffle, yours will differ a little.
"""Count the perceptron's checks yourself, as the plot on this page does.
Run it with Python 3.12 or later. For each n it stands n points twice:
once in two columns the starting line already splits, so one pass
nudges nothing, and once along one row, a triangle then a square by
turns, which no line can split, so all six passes are made. It prints
how many points each run checks, up to n = 500, in under a second. The
counts are the same on any computer.
"""
def perceptron(points, rate):
"""The line the passes end on, as its three numbers.
points are (across, up, shape) tuples, each shape "triangle" or
"square". A spot's score is the first number times its steps right
of the middle, 5 5, plus the second times its steps up, plus the
third. Over 0 is the triangles' side. A point not on its own side
nudges the line: rate times its steps right, its steps up and 1,
added for a triangle and taken away for a square. The sums are done
in whole tenths, so a score on the line is exactly 0.
"""
step = round(rate * 10) # the step size, in tenths
across, up, base = 10, 0, 0 # start with an upright line through the middle
for _ in range(6): # a pass over the points, six at most
nudged = False
for x, y, shape in points:
right, above = x - 5, y - 5 # its steps from the middle
want = 1 if shape == "triangle" else -1
score = across * right + up * above + base # in tenths
if score * want <= 0: # on the wrong side, or on the line
across += step * want * right # nudge the line
up += step * want * above
base += step * want
nudged = True
if not nudged:
break # a whole pass nudged nothing
return across / 10, up / 10, base / 10
def count(points, rate):
"""The same method, counting each point it checks."""
step = round(rate * 10)
across, up, base = 10, 0, 0
checks = 0
for _ in range(6):
nudged = False
for x, y, shape in points:
right, above = x - 5, y - 5
want = 1 if shape == "triangle" else -1
checks += 1 # one check for each point of each pass
score = across * right + up * above + base
if score * want <= 0:
across += step * want * right
up += step * want * above
base += step * want
nudged = True
if not nudged:
break
return checks
def cheapest(n):
"""n points the starting line already splits, and the step size 0.5.
Triangles stand in a column 3 steps right of the middle and squares
in a column 3 steps left of it, a triangle then a square by turns.
"""
points = [(8 if i % 2 == 0 else 2, i // 2, "triangle" if i % 2 == 0 else "square") for i in range(n)]
return points, 0.5
def dearest(n):
"""n points along the middle row, which no line can split, and 0.1.
A triangle then a square by turns, 1 apart. One point, or two, can
always be split: theirs is a triangle 1 step left of the middle,
which takes all six passes to put right at this step size.
"""
if n < 3:
return [(4, 5, "triangle"), (0, 5, "square")][:n], 0.1
return [(i, 5, "triangle" if i % 2 == 0 else "square") for i in range(n)], 0.1
if __name__ == "__main__":
print(f"{'n':>6} {'already split':>14} {'no line splits':>15}")
for n in (10, 20, 50, 100, 200, 500):
print(f"{n:>6} {count(*cheapest(n)):>14} {count(*dearest(n)):>15}")
best, worst and average
A pass checks each of the n points once. How many passes are made depends on where the points stand, their order and the step size. Best means cheapest here.
A case is one kind of input, the thing the method is given, such as a set of points with a step size. A bound says how fast that case's cost grows as more points come in.
The dearest run's count is in the grid: 6 passes of n checks each, 6n, so all three bounds grow as n.
| besttriangles in a column right of the middle and squares in a column left of it, which the starting line already splits, so the first pass nudges nothing | worstpoints along one row, a triangle then a square by turns, which no line can split, so all six passes are made | |
|---|---|---|
| points checked | ||
| nudges | none | at least 6, and at most |
| how the points checked grow in each case | ||
| tight, | ||
| ceiling, | ||
| floor, | ||
extra memory: the line's three numbers
Extra memory is the room it needs on top of the input itself, while it runs.
| points | checks, already split | checks, no line splits | nudges, no line splits |
|---|---|---|---|
| 10 | 10 | 60 | 49 |
| 100 | 100 | 600 | 552 |
| 1,000 | 1,000 | 6,000 | 5,873 |
| 10,000 | 10,000 | 60,000 | 59,630 |
where the formula comes from
What one nudge does, why the nudges must end, and the counts, worked out in small steps.
the move: nudge the line
the line:the line's number before the nudge adds after a step right adds 1 r times -3 1 - 3r a step up adds 0 r times 1 r every score starts at 0 r r The nudge, number by number. The point's own minus 3, 1 and 1, each times the step size, are added. why it is allowed: 2 6 stands 3 left of the middle and 1 up: minus 3 and 1. It is a triangle, so times minus 3, times 1 and times 1 are added to the line's 1, 0 and 0.
the move: score the point again
the line:why it is allowed: A score is the first number times the steps right, plus the second times the steps up, plus the third. The three numbers are those in line 1 above, and the point still stands at minus 3 and 1.
guess it, thenthe move: multiply out
the line:step size the score after on its own side 0.1 -1.9 no 0.2 -0.8 no 0.3 0.3 yes 0.5 2.5 yes 1 8 yes The triangle's score after its nudge at five step sizes. It rises by 11 for each 1 of step size, from minus 3. Past 0 the point is on the triangles' side. why it is allowed: Minus 3 lots of 1 is minus 3. Minus 3 lots of minus is , as a minus times a minus is a plus.
guess it, thenthe move: gather the lots
the line:why it is allowed: Nine lots, one lot and one lot make 11. The 11 is the point's own numbers squared and added: 9, 1 and 1. Squares are never below 0, so a nudge always moves its own point's score towards its own side. At step size 0.2 the score is minus 0.8: nearer, but still wrong.
guess it, then
try it with a small : at , line 2 gives , which you can work out by hand
the move: one nudge
the line:point steps right its nudge changes the first number by triangle 2 6 -3 -1.5 triangle 4 9 -1 -0.5 triangle 3 3 -2 -1 square 6 4 1 -0.5 square 8 7 3 -1.5 square 7 1 2 -1 Each point's steps right of the middle, and what its nudge does to the first number at step size 0.5. Every nudge lowers it, by 0.5 at the least. why it is allowed: Every triangle here stands left of the middle and every square right, so each nudge pushes the first number the same way. The first number is what a step right adds. A wrong triangle adds 0.5 times its steps right to it, and every triangle here stands 1 or more steps left, a minus. A wrong square takes away 0.5 times its steps right, and every square stands 1 or more steps right. Either way the first number drops by 0.5 or more.
the move: after k nudges
the line:why it is allowed: The first number starts at 1. By line 1, each of the nudges takes 0.5 or more off it.
guess it, then
try it with a small : at , line 2 gives , which you can work out by hand
the move: one nudge
the line:number before, amount twice before times amount amount squared first 1, -1.5 -3 2.25 second 0, 0.5 0 0.25 third 0, 0.5 0 0.25 added -3 2.75 Section 1's first nudge, from the triangle at 2 6, which scored minus 3. The sum of squares changes by minus 3 plus 2.75: from 1 to 0.75. The minus 3 is twice 0.5 times the score. The 2.75 is 0.25 times 11. why it is allowed: Change a number by an amount. Its square changes by twice the number times the amount, plus the amount squared, by multiplying out the bracket as the distance page does. For a triangle each amount is 0.5 times one of the point's own numbers: its steps right, its steps up and 1. The line's numbers times the point's own numbers add to its score. So the first parts add to twice 0.5 times the score, and to minus that for a square. A wrong triangle scores 0 or less and a wrong square 0 or more, so they add to 0 or less. The last parts add to 0.25, which is 0.5 squared, times the point's steps right squared, its steps up squared and 1.
the move: the most of any point
the line:point steps right, steps up squared and added, with 1 0.25 times that triangle 2 6 -3, 1 11 2.75 triangle 4 9 -1, 4 18 4.5 triangle 3 3 -2, -2 9 2.25 square 6 4 1, -1 3 0.75 square 8 7 3, 2 14 3.5 square 7 1 2, -4 21 5.25 Each point's own numbers squared and added, and the most its nudge can add to the sum of squares at step size 0.5. The two squares of its steps make the square of its distance from the middle. why it is allowed: By line 1, a point's most is 0.25 times its own numbers squared and added. The square at 7 1 stands furthest from the middle, 2 right and 4 down: 4, 16 and 1 make 21. 0.25 times 21 is 5.25.
guess it, thenthe move: after k nudges
the line:why it is allowed: The sum starts at 1, the square of 1. By line 2, each of the nudges adds 5.25 at most.
guess it, then
try it with a small : at , line 3 gives , which you can work out by hand
the move: the first number's square
the line:why it is allowed: By question 2 the first number is at most . From 2 nudges on that is 0 or below, so the first number stands or more below 0. So its square is at least .
the move: the room
the line:The straight line is the most the sum of squares can be after each number of nudges, from 2 to 30. The curve is the least the first number's square can be. The curve may never pass the line. They meet at 25 nudges, the marker, at 132.25. nudges first number, then F sum of squares, then S 0 1, 1 1, 1 1 -0.5, 0.5 0.75, 6.25 2 -2, 0 4.25, 11.5 3 -2.5, -0.5 8.75, 16.75 Section 1's run beside the two limits, each pair the run's number and then its limit. The first number stays at or under F, and the sum of squares at or under S. why it is allowed: The first number's square is one of the three squares, and none is below 0, so it is never more than their sum. By question 3 the sum is at most . So a run can reach nudges only while is 0 or more.
guess it, thenthe move: multiply out the square
the line:why it is allowed: times itself is , take away two lots of , plus 1.
guess it, thenthe move: take the bracket away
the line:why it is allowed: Taking the bracket away flips each sign in it, so its is added. The 1s cancel, and and one more make .
guess it, thenthe move: take out what both parts share
the line:why it is allowed: Both parts hold , and 6.25 is 25 lots of 0.25. At 25 nudges the room is 0. At 26 it is minus 6.5, which cannot be. So the run makes 25 nudges at most, whatever order the points come in, even with no limit on its passes. It made 3. The limit is loose, but it is a limit.
guess it, then
try it with a small : at , line 2 gives , which you can work out by hand
the move: one pass
the line:why it is allowed: A pass works out the score of every point once, one check for each of the points.
the move: count the passes
the line:pass nudges in it checks so far 1 3 3 2 3 6 3 3 9 4 3 12 5 2 15 6 2 18 Section 3's three points on one row, at step size 0.5. Every pass nudges, and each adds 3 checks. The sixth brings them to 18. why it is allowed: A pass that nudged nothing would have found every point on its own side. Its line would split the points. No line does, so every pass nudges, and the run goes on to its sixth and last pass.
guess it, thenthe move: add them up
the line:why it is allowed: is the checks made. By lines 1 and 2, for each of the 6 passes.
guess it, thenthe move: six lots
the line:why it is allowed: Six lots of . For the three points, 18.
guess it, thenthe move: a ceiling
the line:why it is allowed: By line 4, is , so it is at most .
guess it, thenthe move: read it as a bound
the line:why it is allowed: By line 5, is at most 6 times .
guess it, thenthe move: a floor
the line:why it is allowed: By line 4, is at least too.
guess it, thenthe move: read it as a bound
the line:why it is allowed: By line 7, never drops below 6 times .
guess it, thenthe move: ceiling and floor together
the line:why it is allowed: Lines 6 and 8 bound by the same growth, .
guess it, then
try it with a small : at , line 3 gives , which you can work out by hand
the move: the first pass
the line:Three points the starting line already splits, after pass 1. Both triangles stand right of the upright line and the square left of it, so the pass nudged nothing. why it is allowed: Under the starting line a spot's score is its steps right. Every triangle stands right of the middle, so it scores over 0. Every square stands left, so it scores under 0. Each point is found on its own side.
the move: count the passes
the line:why it is allowed: The run stops at the first pass that nudges nothing, and by line 1 that is pass 1.
guess it, thenthe move: one pass
the line:why it is allowed: is the checks made. By line 2 there is 1 pass, and it checks each of the points once.
guess it, thenthe move: a ceiling
the line:why it is allowed: By line 3, is , so it is at most .
guess it, thenthe move: read it as a bound
the line:why it is allowed: By line 4, is at most 1 times .
guess it, thenthe move: a floor
the line:why it is allowed: By line 3, is at least too.
guess it, thenthe move: read it as a bound
the line:why it is allowed: By line 6, never drops below 1 times .
guess it, thenthe move: ceiling and floor together
the line:why it is allowed: Lines 5 and 7 bound by the same growth, .
guess it, then
try it with a small : at , line 3 gives , which you can work out by hand
count it yourself
Count every step on section 3's three points on one row, which no line can split. After the points comes the step size, 0.5. Then check the checks against the formula.
| step | the row | what happens | points checked | nudges |
|---|---|---|---|---|
| 1 | 3 points. The line starts upright through the middle. A point's score starts at 0, and each step it stands right of the middle adds 1; a step left takes 1 away. Over 0 is the triangles' side, under 0 the squares'. Your step size is 0.5. | 0 | 0 | |
| 2 | 0 | Pass 1, point 1: the triangle at 2 5 scores -3. Under 0 is the squares' side. It is not on its own side, so it is ringed.0 | 1 | 0 |
| 3 | 1 | Nudge the line. A triangle's score must rise, so add 0.5 × -3 to what a step right adds, 0.5 × 0 to what a step up adds and 0.5 to the start: now -0.5, 0 and 0.5. The point scores 2.1 | 1 | 1 |
| 4 | 1 | Pass 1, point 2: the square at 5 5 scores 0.5. Over 0 is the triangles' side. It is not on its own side, so it is ringed.1 | 2 | 1 |
| 5 | 2 | Nudge again: take away 0.5 × 0, 0.5 × 0 and 0.5. The numbers are now -0.5, 0 and 0. The point's score goes from 0.5 to 0.2 | 2 | 2 |
| 6 | 2 | Pass 1, point 3: the triangle at 8 5 scores -1.5. Under 0 is the squares' side. It is not on its own side, so it is ringed.2 | 3 | 2 |
| 7 | 3 | Nudge again: add 0.5 × 3, 0.5 × 0 and 0.5. The numbers are now 1, 0 and 0.5. The point's score goes from -1.5 to 3.5.3 | 3 | 3 |
| 8 | 3 | Pass 1 is over. It nudged the line 3 times, and a nudge that puts one point right can put another wrong. So every point is checked again.3 | 3 | 3 |
| 9 | 3, 0 | Pass 2, point 1: the triangle at 2 5 scores -2.5. Under 0 is the squares' side. It is not on its own side, so it is ringed.3, 0 | 4 | 3 |
| 10 | 3, 1 | Nudge again: add 0.5 × -3, 0.5 × 0 and 0.5. The numbers are now -0.5, 0 and 1. The point's score goes from -2.5 to 2.5.3, 1 | 4 | 4 |
| 11 | 3, 1 | Pass 2, point 2: the square at 5 5 scores 1. Over 0 is the triangles' side. It is not on its own side, so it is ringed.3, 1 | 5 | 4 |
| 12 | 3, 2 | Nudge again: take away 0.5 × 0, 0.5 × 0 and 0.5. The numbers are now -0.5, 0 and 0.5. The point's score goes from 1 to 0.5.3, 2 | 5 | 5 |
| 13 | 3, 2 | Pass 2, point 3: the triangle at 8 5 scores -1. Under 0 is the squares' side. It is not on its own side, so it is ringed.3, 2 | 6 | 5 |
| 14 | 3, 3 | Nudge again: add 0.5 × 3, 0.5 × 0 and 0.5. The numbers are now 1, 0 and 1. The point's score goes from -1 to 4.3, 3 | 6 | 6 |
| 15 | 3, 3 | Pass 2 is over. It nudged the line 3 times, and a nudge that puts one point right can put another wrong. So every point is checked again.3, 3 | 6 | 6 |
| 16 | 3, 3, 0 | Pass 3, point 1: the triangle at 2 5 scores -2. Under 0 is the squares' side. It is not on its own side, so it is ringed.3, 3, 0 | 7 | 6 |
| 17 | 3, 3, 1 | Nudge again: add 0.5 × -3, 0.5 × 0 and 0.5. The numbers are now -0.5, 0 and 1.5. The point's score goes from -2 to 3.3, 3, 1 | 7 | 7 |
| 18 | 3, 3, 1 | Pass 3, point 2: the square at 5 5 scores 1.5. Over 0 is the triangles' side. It is not on its own side, so it is ringed.3, 3, 1 | 8 | 7 |
| 19 | 3, 3, 2 | Nudge again: take away 0.5 × 0, 0.5 × 0 and 0.5. The numbers are now -0.5, 0 and 1. The point's score goes from 1.5 to 1.3, 3, 2 | 8 | 8 |
| 20 | 3, 3, 2 | Pass 3, point 3: the triangle at 8 5 scores -0.5. Under 0 is the squares' side. It is not on its own side, so it is ringed.3, 3, 2 | 9 | 8 |
| 21 | 3, 3, 3 | Nudge again: add 0.5 × 3, 0.5 × 0 and 0.5. The numbers are now 1, 0 and 1.5. The point's score goes from -0.5 to 4.5.3, 3, 3 | 9 | 9 |
| 22 | 3, 3, 3 | Pass 3 is over. It nudged the line 3 times, and a nudge that puts one point right can put another wrong. So every point is checked again.3, 3, 3 | 9 | 9 |
| 23 | 3, 3, 3, 0 | Pass 4, point 1: the triangle at 2 5 scores -1.5. Under 0 is the squares' side. It is not on its own side, so it is ringed.3, 3, 3, 0 | 10 | 9 |
| 24 | 3, 3, 3, 1 | Nudge again: add 0.5 × -3, 0.5 × 0 and 0.5. The numbers are now -0.5, 0 and 2. The point's score goes from -1.5 to 3.5.3, 3, 3, 1 | 10 | 10 |
| 25 | 3, 3, 3, 1 | Pass 4, point 2: the square at 5 5 scores 2. Over 0 is the triangles' side. It is not on its own side, so it is ringed.3, 3, 3, 1 | 11 | 10 |
| 26 | 3, 3, 3, 2 | Nudge again: take away 0.5 × 0, 0.5 × 0 and 0.5. The numbers are now -0.5, 0 and 1.5. The point's score goes from 2 to 1.5.3, 3, 3, 2 | 11 | 11 |
| 27 | 3, 3, 3, 2 | Pass 4, point 3: the triangle at 8 5 scores 0. A score of 0 is on neither side. It is not on its own side, so it is ringed.3, 3, 3, 2 | 12 | 11 |
| 28 | 3, 3, 3, 3 | Nudge again: add 0.5 × 3, 0.5 × 0 and 0.5. The numbers are now 1, 0 and 2. The point's score goes from 0 to 5.3, 3, 3, 3 | 12 | 12 |
| 29 | 3, 3, 3, 3 | Pass 4 is over. It nudged the line 3 times, and a nudge that puts one point right can put another wrong. So every point is checked again.3, 3, 3, 3 | 12 | 12 |
| 30 | 3, 3, 3, 3, 0 | Pass 5, point 1: the triangle at 2 5 scores -1. Under 0 is the squares' side. It is not on its own side, so it is ringed.3, 3, 3, 3, 0 | 13 | 12 |
| 31 | 3, 3, 3, 3, 1 | Nudge: add 0.5 × -3, 0.5 × 0 and 0.5, making -0.5, 0 and 2.5. Now no spot on the plane scores under 0: no line crosses it, and the squares have no side left.3, 3, 3, 3, 1 | 13 | 13 |
| 32 | 3, 3, 3, 3, 1 | Pass 5, point 2: the square at 5 5 scores 2.5. Over 0 is the triangles' side. It is not on its own side, so it is ringed.3, 3, 3, 3, 1 | 14 | 13 |
| 33 | 3, 3, 3, 3, 2 | Nudge again: take away 0.5 × 0, 0.5 × 0 and 0.5. The numbers are now -0.5, 0 and 2. The point's score goes from 2.5 to 2.3, 3, 3, 3, 2 | 14 | 14 |
| 34 | 3, 3, 3, 3, 2 | Pass 5, point 3: the triangle at 8 5 scores 0.5. Over 0 is the triangles' side, where it belongs.3, 3, 3, 3, 2 | 15 | 14 |
| 35 | 3, 3, 3, 3, 2 | Pass 5 is over. It nudged the line 2 times, and a nudge that puts one point right can put another wrong. So every point is checked again.3, 3, 3, 3, 2 | 15 | 14 |
| 36 | 3, 3, 3, 3, 2, 0 | Pass 6, point 1: the triangle at 2 5 scores 3.5. Over 0 is the triangles' side, where it belongs.3, 3, 3, 3, 2, 0 | 16 | 14 |
| 37 | 3, 3, 3, 3, 2, 0 | Pass 6, point 2: the square at 5 5 scores 2. Over 0 is the triangles' side. It is not on its own side, so it is ringed.3, 3, 3, 3, 2, 0 | 17 | 14 |
| 38 | 3, 3, 3, 3, 2, 1 | Nudge again: take away 0.5 × 0, 0.5 × 0 and 0.5. The numbers are now -0.5, 0 and 1.5. The point's score goes from 2 to 1.5.3, 3, 3, 3, 2, 1 | 17 | 15 |
| 39 | 3, 3, 3, 3, 2, 1 | Pass 6, point 3: the triangle at 8 5 scores 0. A score of 0 is on neither side. It is not on its own side, so it is ringed.3, 3, 3, 3, 2, 1 | 18 | 15 |
| 40 | 3, 3, 3, 3, 2, 2 | Nudge again: add 0.5 × 3, 0.5 × 0 and 0.5. The numbers are now 1, 0 and 2. The point's score goes from 0 to 5.3, 3, 3, 3, 2, 2 | 18 | 16 |
| 41 | 3, 3, 3, 3, 2, 2 | Pass 6 nudged the line 2 times, and this page makes 6 passes at most. The 2 ringed points are still wrong: more passes might split them, or no line can.3, 3, 3, 3, 2, 2 | 18 | 16 |
In all, 18 points checked. The formula from section 4, , gives at : the same.
where you meet it
One of the first machines that learnt from examples, and still a tool in today's libraries.
scikit-learn, a Python library for machine learning
Its Perceptron tool finds a splitting line by nudges like these, one point at a time. Each point may carry any number of measurements, not only an across and an up. By default it shuffles the points before each pass, and makes 1,000 passes at most.
source: scikit-learn's documentation, the user guide's section on linear models and the Perceptron reference
NLTK, a Python library for working with language
Its usual tool for tagging each word of a sentence as a noun, a verb and so on is an averaged perceptron. It nudges its numbers whenever it tags a word wrong, and answers with their average over the whole run.
source: NLTK's documentation, the nltk.tag.perceptron module and the pos_tag function
where it comes from
Frank Rosenblatt described the perceptron in 1958, as a model of how a brain might learn. In 1962 Albert Novikoff proved that the nudges end whenever some line splits the points, by a count like questions 2 to 4 made for any such line. In 1969 Marvin Minsky and Seymour Papert's book Perceptrons set out what one line can never do. Crossed corners, which books call XOR, are the best-known case.
source: Rosenblatt, The perceptron: a probabilistic model for information storage and organization in the brain, Psychological Review, 1958. Novikoff, On convergence proofs on perceptrons, Proceedings of the Symposium on the Mathematical Theory of Automata, 1962. Minsky and Papert, Perceptrons: an introduction to computational geometry, 1969.
what is used instead
A perceptron stops at the first line that splits the points, which may pass close to one of them. Other methods look for the line with the widest gap on both sides. Joining several perceptrons in layers, a neural network, splits what one line cannot.
how it compares
The perceptron beside itself at other step sizes. The same six points, five runs.
| step size | nudges in each pass | nudges | checks | the line it ends on |
|---|---|---|---|---|
| 0.1 | 5, 2, 0 | 7 | 18 | -0.3, 0.1, 0.1 |
| 0.2 | 3, 1, 0 | 4 | 18 | -0.4, 0.2, 0 |
| 0.3 | 3, 0 | 3 | 12 | -0.8, 0, 0.3 |
| 0.5 | 2, 1, 0 | 3 | 18 | -2.5, 1.5, 0.5 |
| 1 | 1, 0 | 1 | 12 | -2, 1, 1 |