-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraph.js
79 lines (72 loc) · 2.59 KB
/
Graph.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
{
let content = document.currentScript.parentElement;
let canvas = content.getElementsByTagName("canvas")[0];
let start = content.getElementsByClassName("startButton")[0];
start.onclick = startButton;
let clear = content.getElementsByClassName("clearButton")[0];
clear.onclick = clearArea;
let accuracy = content.getElementsByClassName("accuracy")[0];
let cost = content.getElementsByClassName("cost")[0];
let ctx = canvas.getContext("2d");
let points = new Array();
function addPoint(num) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
points.push(num);
if (points.length === 1) {
ctx.beginPath();
ctx.arc(0, (canvas.height * (1 - num)), 2, 0, 2 * Math.PI);
ctx.fillStyle = "#7D9DDF";
ctx.fill();
ctx.strokeStyle = "#7D9DDF";
ctx.stroke();
}
else {
// for (let i = 0; i < points.length; i++) {
// let x = canvas.width / (points.length - 1) * i;
// let y = (canvas.height * (1 - points[i]));
// ctx.beginPath();
// ctx.arc(x, y, 1.5, 0, 2 * Math.PI);
// ctx.fillStyle = "#7D9DDF";
// ctx.fill();
// ctx.strokeStyle = "#7D9DDF";
// ctx.stroke();
// }
ctx.beginPath();
for (let i = 0; i < points.length; i++) {
let x = canvas.width / (points.length - 1) * i;
let y = (canvas.height * (1 - points[i]));
if (i === 0) {
ctx.moveTo(x, y);
} else {
ctx.lineTo(x, y);
}
}
ctx.strokeStyle = "#7D9DDF";
ctx.stroke();
}
}
function clearArea() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
points = new Array();
}
let timer;
function startButton() {
timer = setInterval(function () {
if (dl.batchindex == 0) return;
addPoint(dl.totalcorrect / dl.batchindex);
}, 2000);
start.innerHTML = "Stop Graphing";
start.onclick = stopButton;
dl.onEpoch = function (correct, total) {
accuracy.innerHTML = "The network got "+correct+" out of "+total+" in the most recent epoch."
}
dl.onCost = function (value) {
cost.innerHTML = "Cost: "+value;
}
}
function stopButton() {
clearInterval(timer);
start.innerHTML = "Start Graphing";
start.onclick = startButton;
}
}