A rule that keeps learning

Start from a rule written by hand, then let it learn.

Click to place a point, click again to remove it.

mistakes after each round of learningclick a bar to see that round

start (the rule)16
xy1out
h180-32-16
h2-80-32-16
h308-32-16
h40-8-32-16
out64 (bias)

The rule's 17 numbers. Small grey: as written by hand. Blue: changed by learning.

How it works (for the curious)

How it trains

StepCSS, per point p and hidden unit k
forwardh = max(0, calc(x·a + y·b + c)), s = calc(Σ v·h + d)
lossg = t · clamp(0, 57 − t·s, 1): the point's colour if it's wrong or within the margin
through the ReLUf = clamp(0, h, 1), the derivative [z > 0]
updatev += Σ g·h / 31, a += v · Σ g·f·x / 151, b += v · Σ g·f·y / 151, c += v · Σ 2·g·f / 31, d += 4·Σ g, each clamped

Integers throughout. Every divisor is odd, so CSS's rounding matches Python's exactly, and the clamps keep every sum under 2²⁴. The first layer's step is five times smaller than the rest: with a big step a box edge overshoots, flips, and its ReLU dies.

The browser test places the demo sets from handwired/scripts/unfrozen.py from both starts and checks all 17 numbers at every epoch, and every error count, against the numpy reference in Chromium, Firefox and WebKit.