The cat is a neural net

Seven small steps, about three minutes. Everything you see is computed live in your browser.

Step 1 of 7

Here's a tiny JavaScript function.

It decides how hard a cat should jump to land on a shelf. Drag the shelf and watch.

Fine print: what's measured, and what isn't
  • Everything is computed live in your browser. JavaScript runs the source shown, through new Function. The network is the same rule built with Handwired's builder: 41 operations, using emitCompare for shelf > 50 and emitClampExact for the min/max.
  • "Same answer" means the identical number with no tolerance, for all 3,201 shelves (0 to 100 cm in 1/32 cm steps). That holds because the inputs and constants are values 32-bit floats store exactly. For arbitrary fractions, JavaScript's 64-bit math and the network's 32-bit math can differ in the last digits.
  • The heavier cat is a simulation: its "right" powers come from the same rule with BASE 12, PER_CM 1 and EXTRA 16. A jump lands if the power is within 0.75% of what the cat needed.
  • Learning uses Adam on the gradients from circuit.backpropagateReference. Only BASE, PER_CM and EXTRA learn. The 50 cm threshold can't learn, because a comparison has no slope. The learned constants are shown rounded (whole numbers, quarters for PER_CM); the page re-checks the rounded code against the network.
  • The regular net is 1 → 16 → 1 with ReLUs (49 weights), run on the same Handwired runtime with the same training code. It starts from seed 7 and is pre-trained for 2,500 steps on random shelves priced by the original rule. Its results depend on that setup, and you could bolt a clamp onto it. The Handwired net is shaped like the rule, which is exactly why it learns this change quickly; it couldn't learn an unrelated pattern.

Loading Handwired…