-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketchv3.js
81 lines (75 loc) · 2.15 KB
/
sketchv3.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
let nn;
let trainSetLen = 200;
let c = trainSetLen;
let disabled = true;
let trainingRate = 1;
let trainSet = [];
function setup() {
nn = new NN([7, 11, 10]);
createCanvas(400, 400);
colorMode(RGB, 1, 1, 1);
background(0);
for (let i = 0; i < trainSetLen; i++) {
trainSet.push(new sevenSeg(floor(random(10))));
}
}
function toggDis() {
for (let b of document.getElementsByTagName('BUTTON')) {
disabled = b.disabled = !b.disabled;
}
}
function test() {
loop();
}
function trainNN(n) {
c = 0;
trainingRate = n;
toggDis();
loop();
}
function draw() {
background(0);
if (c < trainSet.length) {
for (let i = 0; i < trainingRate; i++) {
let set = random(trainSet);
nn.train(set.arr, set.corr);
}
nn.display();
push();
let progress = c / (trainSetLen);
translate(0, height);
rotate(-PI / 2);
noStroke();
fill(255);
textSize(40);
textAlign(CENTER);
text("Training NN", width/2, height * 0.12);
textSize(20);
textAlign(RIGHT);
fill(0, 255, 255);
rect(width*0.05 , height * 0.9, width * 0.8 * progress, height * 0.05);
text(floor(progress * 100) + '%', width - 5, height * 0.948);
// noStroke();
// strokeWeight(5);
// stroke(0,255,255);
// fill(0,255,255);
// arc(width/2,height/2,width/3,height/3,-PI/2,3*PI/2 - 2*PI*c/(trainSet.length));
// noStroke();
// alph = (sin(2* PI * c/(trainSet.length)))**2;
// fill(0,255,255,255*alph);
// textAlign(CENTER);
// textSize(75);
// text("Training...",width/2,height*0.6);
pop();
c++;
} else {
if (disabled) { toggDis(); }
let tester = random(trainSet);
nn.test(tester.arr);
nn.print();
nn.display();
nn.showOutput();
tester.display(10, height - 60, 25, 50);
noLoop();
}
}