-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaccuracy.js
35 lines (24 loc) · 882 Bytes
/
accuracy.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
var brain = require("brain");
var NN = brain.NeuralNetwork;
var args = require("yargs").argv;
// get arguments from console.
var n_bits = args.bits || args.b;
var path = args.path || args.p;
var data = require("./Data/"+ ( n_bits || 4 ) +"bit_add_in_out.json");
var D = [];
for (var i = 0; i < data.inputs.length; i++) {
D.push({ input: data.inputs[i], output: data.outputs[i] });
}
var precompute = require( path || "./precomputed-net.json");
// generate our NN from json
var Net = new NN(precompute.networkData).fromJSON(precompute);
var accuracy = 0;
D.forEach(function(data) {
var O = activate(Net.run(data.input));
if(O.sort().toString() === data.output.sort().toString()) accuracy = accuracy + 1;
}, this);
accuracy = (accuracy/ D.length) * 100;
console.log("accuracy is " + accuracy);
function activate(arr) {
return arr.map(e => (e > 0.5 ? 1 : 0));
}