xxxxxxxxxx
45
var points = [];
var brain;
var t = 1;
function setup() {
createCanvas(windowWidth, windowHeight);
brain = new NeuralNetwork(3);
//points.push(new Point(50, 50, 1));
//points.push(new Point(350, 350, -1));
background(31);
strokeWeight(4);
}
function mousePressed() {
points.push(new Point(mouseX, mouseY, t));
for (let epoch = 0; epoch < 10000; epoch++)
for (let i = 0; i < points.length; i++)
brain.train([points[i].x, points[i].y, points[i].bias], points[i].t);
noStroke();
for (let i = 0; i < width; i+=10)
for (let j = 0; j < height; j+=10) {
let pred = brain.predict([i, j, 1]);
if (pred == 1) fill(0, 0, 255, 100);
else fill(255, 0, 0, 100);
ellipse(i, j, 32, 32);
}
stroke(0);
for (let i = 0; i < points.length; i++)
points[i].display();
}
function keyPressed() {
if (keyCode == 83) {
if (t == 1) t = -1;
else t = 1;
}
}