[WIP] fix perceptron

Fix an embarrassing bug, add a test, simplify averaging a bit.

TODO: perform moving average to prevent overflow (failing test)