Skip to content

perceptron

learning

Level 2 of 3

Also called the perceptron learning rule and Rosenblatt's 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.

02468100246810
The six points and the upright line they start from, before any pass. The triangles' side is on its right and the triangles stand on its left, so all six points are on the wrong side, each ringed.
02468100246810
00.511.52123passnudges in the passnudges

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.

The same six points with the passes free to change: 2 nudges, then 1, then none, and the run stops after pass 3. The other points are four corners, triangles on one diagonal and squares on the other, which no line can split. There every pass nudges, and after six the line still has 2 points on the wrong side.
nudgewrong pointits scorea step right addsa step up addsevery score starts at
before any100
1triangle 2 6-3-0.50.50.5
2square 8 70-2-0.50
3triangle 4 90-2.51.50.5
The run as numbers. Each row is one nudge, the point that made it, the score that put it wrong, and the line's three numbers after it.
Triangles on the left, and three nudges turn the line round: 8 moments of its 25 steps, the steps between them left for the watch page
  1. step 1 of 25

    02468100246810123456

    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.

    watch from here

  2. step 2 of 25

    024681002468101234560

    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

    watch from here

  3. step 3 of 25

    024681002468101234561

    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

    watch from here

  4. step 7 of 25

    024681002468101234561

    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

    watch from here

  5. step 8 of 25

    024681002468101234562

    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

    watch from here

  6. step 12 of 25

    0246810024681012345620

    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

    watch from here

  7. step 13 of 25

    0246810024681012345621

    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

    watch from here

  8. step 25 of 25

    02468100246810123456210

    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

    watch from here

the steps, in plain words
  1. start with an upright line through the middlePython lines 12 and 13
  2. repeat, a pass over the pointsPython lines 14 and 15
  3. work out each point's scorePython lines 16, 17, 18 and 19
  4. if it is not on its own side, nudge the linePython lines 20, 21, 22, 23 and 24
  5. 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, 6n6n against nn.

points checked, ten times more at each mark up

slope 1102104106108101102103104105106107slope 1101102103104105106107108101102103104105106107slope 1101102103104105106107108101102103104105106107

nn, 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
what all six passes cost, at a billion points checked a second
nnpoints checkedtime
1,0006,000about 6 microseconds
100,000600,000about 600 microseconds
10,000,00060,000,000about 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.

what each case costs, and how fast that cost grows; section 4 works out every formula in it
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 nothingworstpoints along one row, a triangle then a square by turns, which no line can split, so all six passes are made
points checkednn6n6n
nudgesnoneat least 6, and at most 6n6n
how the points checked grow in each case
tight, Θ\ThetaΘ(n)\Theta(n)Θ(n)\Theta(n)
ceiling, OOO(n)O(n)O(n)O(n)
floor, Ω\OmegaΩ(n)\Omega(n)Ω(n)\Omega(n)

extra memory: the line's three numbers

Extra memory is the room it needs on top of the input itself, while it runs.

pointschecks, already splitchecks, no line splitsnudges, no line splits
10106049
100100600552
1,0001,0006,0005,873
10,00010,00060,00059,630
The two kinds of points the plot measures. Points the starting line already splits cost one pass and no nudge. Points along one row, at step size 0.1, cost six passes, and most of their checks nudge.
02468100246810
0123123456passnudges in the passnudges
A square between two triangles on one row, after six passes at step size 0.5. No line can split them, and every pass nudged: 3, 3, 3, 3, 2 and 2 times. The line still has 2 points on the wrong side, each ringed.
02468100246810
Two triangles one step above two squares, after six passes at step size 0.1. The sixth pass still nudged. Yet its line lies level, halfway between the rows, with every point on its own side.

where the formula comes from

What one nudge does, why the nudges must end, and the counts, worked out in small steps.

Question 1: under the starting line the triangle at 2 6 scores minus 3. It nudges the line at step size rr. What does it score after the nudge? Call that NN.
  1. the move: nudge the line

    the line:
    the line becomes1−3r, r and r\begin{gathered} \text{the line becomes} \\ 1 - 3r,\ r \text{ and } r \end{gathered}
    the line's numberbeforethe nudge addsafter
    a step right adds1r times -31 - 3r
    a step up adds0r times 1r
    every score starts at0rr
    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 rr times minus 3, rr times 1 and rr times 1 are added to the line's 1, 0 and 0.

  2. the move: score the point again

    the line:
    N=(1−3r)×(−3)+r×1+rN = (1 - 3r) \times ({-3}) + r \times 1 + r

    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.

  3. the move: multiply out

    the line:
    N=−3+9r+r+rN = {-3} + 9r + r + r
    step sizethe score afteron its own side
    0.1-1.9no
    0.2-0.8no
    0.30.3yes
    0.52.5yes
    18yes
    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 3r3r is 9r9r, as a minus times a minus is a plus.

  4. the move: gather the lots

    the line:
    N=11r−3N = 11r - 3

    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.

try it with a small rr: at r=1r = 1, line 2 gives N=8N = 8, which you can work out by hand

Question 2: section 1's six points at step size 0.5. After kk nudges, how high can the first number still stand? Call that FF.
  1. the move: one nudge

    the line:
    every nudge takes0.5 or more offthe first number\begin{gathered} \text{every nudge takes} \\ \text{0.5 or more off} \\ \text{the first number} \end{gathered}
    pointsteps rightits 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 41-0.5
    square 8 73-1.5
    square 7 12-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.

  2. the move: after k nudges

    the line:
    F=1−0.5kF = 1 - 0.5k

    why it is allowed: The first number starts at 1. By line 1, each of the kk nudges takes 0.5 or more off it.

try it with a small kk: at k=3k = 3, line 2 gives F=−0.5F = -0.5, which you can work out by hand

Question 3: square each of the line's three numbers and add the squares. After kk nudges at step size 0.5, how big can that sum be? Call that SS.
  1. the move: one nudge

    the line:
    a nudge adds to the sum atmost 0.25 times its point’sown numbers, squared and added\begin{gathered} \text{a nudge adds to the sum at} \\ \text{most 0.25 times its point's} \\ \text{own numbers, squared and added} \end{gathered}
    numberbefore, amounttwice before times amountamount squared
    first1, -1.5-32.25
    second0, 0.500.25
    third0, 0.500.25
    added-32.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.

  2. the move: the most of any point

    the line:
    no nudge here addsmore than 5.25\begin{gathered} \text{no nudge here adds} \\ \text{more than 5.25} \end{gathered}
    pointsteps right, steps upsquared and added, with 10.25 times that
    triangle 2 6-3, 1112.75
    triangle 4 9-1, 4184.5
    triangle 3 3-2, -292.25
    square 6 41, -130.75
    square 8 73, 2143.5
    square 7 12, -4215.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.

  3. the move: after k nudges

    the line:
    S=1+5.25kS = 1 + 5.25k

    why it is allowed: The sum starts at 1, the square of 1. By line 2, each of the kk nudges adds 5.25 at most.

try it with a small kk: at k=3k = 3, line 3 gives S=16.75S = 16.75, which you can work out by hand

Question 4: the same run. Take the most the sum of squares can be, less the least the first number's square can be, and call that room GG. After how many nudges does the room run out?
  1. the move: the first number's square

    the line:
    from 2 nudges on, the firstnumber’s square is at least(0.5k−1)2\begin{gathered} \text{from 2 nudges on, the first} \\ \text{number's square is at least} \\ (0.5k - 1)^2 \end{gathered}

    why it is allowed: By question 2 the first number is at most F=1−0.5kF = 1 - 0.5k. From 2 nudges on that is 0 or below, so the first number stands 0.5k−10.5k - 1 or more below 0. So its square is at least (0.5k−1)2(0.5k - 1)^2.

  2. the move: the room

    the line:
    G=1+5.25k−(0.5k−1)2G = 1 + 5.25k - (0.5k - 1)^2
    05010015025811141720232629nudges so farsquaresthe sum, at mostone square, at least
    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.
    nudgesfirst number, then Fsum of squares, then S
    01, 11, 1
    1-0.5, 0.50.75, 6.25
    2-2, 04.25, 11.5
    3-2.5, -0.58.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 S=1+5.25kS = 1 + 5.25k. So a run can reach kk nudges only while GG is 0 or more.

  3. the move: multiply out the square

    the line:
    G=1+5.25k−(0.25k2−k+1)G = 1 + 5.25k - (0.25k^2 - k + 1)

    why it is allowed: 0.5k−10.5k - 1 times itself is 0.25k20.25k^2, take away two lots of 0.5k0.5k, plus 1.

  4. the move: take the bracket away

    the line:
    G=6.25k−0.25k2G = 6.25k - 0.25k^2

    why it is allowed: Taking the bracket away flips each sign in it, so its kk is added. The 1s cancel, and 5.25k5.25k and one more kk make 6.25k6.25k.

  5. the move: take out what both parts share

    the line:
    G=0.25k(25−k)G = 0.25k(25 - k)

    why it is allowed: Both parts hold 0.25k0.25k, 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.

try it with a small kk: at k=3k = 3, line 2 gives G=16.5G = 16.5, which you can work out by hand

Question 5: nn points that no line can split, 3 or more. How many checks, CC, does the run make?
  1. the move: one pass

    the line:
    each pass checksn points\begin{gathered} \text{each pass checks} \\ n \text{ points} \end{gathered}

    why it is allowed: A pass works out the score of every point once, one check for each of the nn points.

  2. the move: count the passes

    the line:
    every pass nudges,so all 6 are made\begin{gathered} \text{every pass nudges,} \\ \text{so all 6 are made} \end{gathered}
    passnudges in itchecks so far
    133
    236
    339
    4312
    5215
    6218
    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.

  3. the move: add them up

    the line:
    C=n+n+⋯+nC = n + n + \dots + n

    why it is allowed: CC is the checks made. By lines 1 and 2, nn for each of the 6 passes.

  4. the move: six lots

    the line:
    C=6nC = 6n

    why it is allowed: Six lots of nn. For the three points, 18.

  5. the move: a ceiling

    the line:
    C≤6nC \le 6n

    why it is allowed: By line 4, CC is 6n6n, so it is at most 6n6n.

  6. the move: read it as a bound

    the line:
    C∈O(n)C \in O(n)

    why it is allowed: By line 5, CC is at most 6 times nn.

  7. the move: a floor

    the line:
    C≥6nC \ge 6n

    why it is allowed: By line 4, CC is at least 6n6n too.

  8. the move: read it as a bound

    the line:
    C∈Ω(n)C \in \Omega(n)

    why it is allowed: By line 7, CC never drops below 6 times nn.

  9. the move: ceiling and floor together

    the line:
    C∈Θ(n)C \in \Theta(n)

    why it is allowed: Lines 6 and 8 bound CC by the same growth, nn.

try it with a small nn: at n=3n = 3, line 3 gives C=18C = 18, which you can work out by hand

Question 6: nn points with every triangle right of the middle and every square left of it. How many checks, BB, does the run make?
  1. the move: the first pass

    the line:
    the first passnudges nothing\begin{gathered} \text{the first pass} \\ \text{nudges nothing} \end{gathered}
    02468100246810
    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.

  2. the move: count the passes

    the line:
    the run stopsafter 1 pass\begin{gathered} \text{the run stops} \\ \text{after 1 pass} \end{gathered}

    why it is allowed: The run stops at the first pass that nudges nothing, and by line 1 that is pass 1.

  3. the move: one pass

    the line:
    B=nB = n

    why it is allowed: BB is the checks made. By line 2 there is 1 pass, and it checks each of the nn points once.

  4. the move: a ceiling

    the line:
    B≤nB \le n

    why it is allowed: By line 3, BB is nn, so it is at most nn.

  5. the move: read it as a bound

    the line:
    B∈O(n)B \in O(n)

    why it is allowed: By line 4, BB is at most 1 times nn.

  6. the move: a floor

    the line:
    B≥nB \ge n

    why it is allowed: By line 3, BB is at least nn too.

  7. the move: read it as a bound

    the line:
    B∈Ω(n)B \in \Omega(n)

    why it is allowed: By line 6, BB never drops below 1 times nn.

  8. the move: ceiling and floor together

    the line:
    B∈Θ(n)B \in \Theta(n)

    why it is allowed: Lines 5 and 7 bound BB by the same growth, nn.

try it with a small nn: at n=3n = 3, line 3 gives B=3B = 3, 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.

2 5 t, 5 5 s, 8 5 t; 0.5, every step written down
stepthe rowwhat happenspoints checkednudges
13 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.00
20Pass 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.010
31Nudge 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.111
41Pass 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.121
52Nudge 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.222
62Pass 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.232
73Nudge 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.333
83Pass 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.333
93, 0Pass 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, 043
103, 1Nudge 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, 144
113, 1Pass 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, 154
123, 2Nudge 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, 255
133, 2Pass 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, 265
143, 3Nudge 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, 366
153, 3Pass 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, 366
163, 3, 0Pass 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, 076
173, 3, 1Nudge 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, 177
183, 3, 1Pass 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, 187
193, 3, 2Nudge 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, 288
203, 3, 2Pass 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, 298
213, 3, 3Nudge 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, 399
223, 3, 3Pass 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, 399
233, 3, 3, 0Pass 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, 0109
243, 3, 3, 1Nudge 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, 11010
253, 3, 3, 1Pass 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, 11110
263, 3, 3, 2Nudge 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, 21111
273, 3, 3, 2Pass 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, 21211
283, 3, 3, 3Nudge 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, 31212
293, 3, 3, 3Pass 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, 31212
303, 3, 3, 3, 0Pass 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, 01312
313, 3, 3, 3, 1Nudge: 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, 11313
323, 3, 3, 3, 1Pass 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, 11413
333, 3, 3, 3, 2Nudge 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, 21414
343, 3, 3, 3, 2Pass 5, point 3: the triangle at 8 5 scores 0.5. Over 0 is the triangles' side, where it belongs.3, 3, 3, 3, 21514
353, 3, 3, 3, 2Pass 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, 21514
363, 3, 3, 3, 2, 0Pass 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, 01614
373, 3, 3, 3, 2, 0Pass 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, 01714
383, 3, 3, 3, 2, 1Nudge 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, 11715
393, 3, 3, 3, 2, 1Pass 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, 11815
403, 3, 3, 3, 2, 2Nudge 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, 21816
413, 3, 3, 3, 2, 2Pass 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, 21816

In all, 18 points checked. The formula from section 4, 6n6n, gives C=18C = 18 at n=3n = 3: 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 sizenudges in each passnudgeschecksthe line it ends on
0.15, 2, 0718-0.3, 0.1, 0.1
0.23, 1, 0418-0.4, 0.2, 0
0.33, 0312-0.8, 0, 0.3
0.52, 1, 0318-2.5, 1.5, 0.5
11, 0112-2, 1, 1
Section 1's six points at five step sizes. Each run ends on a different line, and every one of them splits the points. A bigger step size is not always quicker. 0.3 stops after 2 passes and 0.5 after 3.
02468100246810
012345123passnudges in the passnudges
Step size 0.1 after pass 1. Five small nudges have turned the upright line level, and it still has 2 points on the wrong side. Pass 2 nudges twice more, and pass 3 nudges nothing.

race them on one row of your own