-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
47 lines (34 loc) · 828 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
let points = new Array();
let brain = new Perceptron();
function draw()
{
points.push(new Point());
clear();
//draw cartesian and line
line(width/2,0,width/2,height);
stroke('lightgray');
line(0,height/2,width,height/2);
stroke('lightgray');
let p1 = new Point(-1, f(-1));
let p2 = new Point(1, f(1));
strokeWeight(3);
line(p1.getX(), p1.getY(), p2.getX(), p2.getY());
stroke("black");
let pp1 = new Point(-1,brain.guessY(-1));
let pp2 = new Point(1,brain.guessY(1));
line(pp1.getX(), pp1.getY(), pp2.getX(), pp2.getY());
stroke('blue');
for (let p of points)
{
p.show();
let inputs = [p.x, p.y, 1];
let target = p.label;
circle(p.getX(), p.getY(), 5);
if(brain.guess(inputs) == p.label)
fill('green');
else
fill('red');
brain.train(inputs, target);
}
}
setInterval(draw, 50);