-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
119 lines (113 loc) · 4.11 KB
/
index.html
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<script type="text/javascript" src="Neuron.js" charset="utf-8"></script>
<script type="text/javascript" src="Network.js" charset="utf-8"></script>
</head>
<body>
<h1>XOR - ANN</h1>
<div style="width:1000px;height:400px;">
<h3>Errors for different hidden neurons</h3>
<canvas id="errors" width="1000" height="400"></canvas>
<h3>Actual and predicted outputs with 1 hidden neuron</h3>
<canvas id="chart1HiddenNeuron" width="1000" height="400"></canvas>
<h3>Actual and predicted outputs with 2 hidden neurons</h3>
<canvas id="chart2HiddenNeuron" width="1000" height="400"></canvas>
<h3>Actual and predicted outputs with 3 hidden neurons</h3>
<canvas id="chart3HiddenNeuron" width="1000" height="400"></canvas>
<h3>Actual and predicted outputs with 4 hidden neurons</h3>
<canvas id="chart4HiddenNeuron" width="1000" height="400"></canvas>
<h3>Actual and predicted outputs with 5 hidden neurons</h3>
<canvas id="chart5HiddenNeuron" width="1000" height="400"></canvas>
<h3>Actual and predicted outputs with 6 hidden neurons</h3>
<canvas id="chart6HiddenNeuron" width="1000" height="400"></canvas>
<h3>Actual and predicted outputs with 7 hidden neurons</h3>
<canvas id="chart7HiddenNeuron" width="1000" height="400"></canvas>
<h3>Actual and predicted outputs with 8 hidden neurons</h3>
<canvas id="chart8HiddenNeuron" width="1000" height="400"></canvas>
<h3>Actual and predicted outputs with 9 hidden neurons</h3>
<canvas id="chart9HiddenNeuron" width="1000" height="400"></canvas>
<h3>Actual and predicted outputs with 10 hidden neurons</h3>
<canvas id="chart10HiddenNeuron" width="1000" height="400"></canvas>
</div>
<script type="text/javascript">
$(function() {
var xorData = [
[0, 0, 0],
[1, 0, 1],
[0, 1, 1],
[1, 1, 0]
];
var labelsForErrors = [];
var labelsForDifferentNeurons = [];
var testErrors = [];
var trainingErrors = [];
var rSquareValues = [];
for(var i = 0; i < 10; i++){
var network = new Network(xorData, i+1, 1, 0.0001, 1500, 0.15);
network.init();
// If you don't set momentum and weight decay values network automatically ignore these processes
network.setWeightDecay(0.001);
network.setMomentum(0.1);
// Training process
network.train();
trainingErrors.push(network.trainingError);
// Test process
network.setTestData(xorData);
network.test();
testErrors.push(network.testError);
// calculate rSquare and handle chart data
var rSquare = network.getRSquare();
labelsForErrors.push(i+1);
rSquareValues.push(rSquare[0]);
if(labelsForDifferentNeurons.length == 0){
for(var j = 0; j < rSquare[1].length; j++){
if(j % 10 == 0 || j == rSquare[1].length - 1)
labelsForDifferentNeurons.push(j);
else
labelsForDifferentNeurons.push("");
}
}
var mychart = new Chart($("#chart"+(i+1)+"HiddenNeuron"), {
type: 'line',
data: {
labels: labelsForDifferentNeurons,
datasets: [
getDataset("Actual", "rgba(75,192,192,1)", rSquare[1]),
getDataset("Output", "rgba(200,182,182,1)", rSquare[2])
]}
});
}
new Chart($("#errors"), {
type: 'line',
data: {
labels: labelsForErrors,
datasets: [
getDataset("Training Error", "rgba(75,192,192,1)", trainingErrors),
getDataset("Test Error", "rgba(200,182,182,1)", testErrors),
getDataset("R Square", "rgba(200,50,182,1)", rSquareValues)
]}
});
function getDataset(label, color, data){
return {
label: label,
fill: false,
lineTension: 0,
backgroundColor: color,
borderColor: color,
pointBorderWidth: 2,
pointHoverRadius: 2,
pointHoverBackgroundColor: color,
pointHoverBorderColor: color,
pointHoverBorderWidth: 2,
pointRadius: 1,
pointHitRadius: 2,
data: data,
};
}
});
</script>
</body>
</html>