!7 cmodule PerceptronSpike > DynPrintLogAndEnabled { switchable int nExamples = 2000; L examples; transient Perceptron perceptron; switchable double c = 1; switchable bool randomizeC = false; switchable bool startWithRandomWeights = true; // function to be learned double f(double x) { ret x * 0.7 + 40; } start-thread { if (l(examples) != nExamples) setField(examples := repF(nExamples, () -> { int x = rand(640), y = rand(360); ret new Perceptron.Example(new double[] {x, y}, y > f(x)); })); perceptron = new Perceptron; copyAllFields(module(), perceptron); for ping (Double error : perceptron.trainingIterator()) { if (deleted) ret; if (!enabled) continue with sleepSeconds(1); if (error != null) perceptron.printWithWeights(); } } }