-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
100 lines (88 loc) · 2.11 KB
/
index.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const getFullData2 = require('./readText');
const synaptic = require("synaptic"); // this line is not needed in the browser
const { Layer, Network, Architect, Trainer } = synaptic;
const myPerceptron = new Architect.Perceptron(3,1000, 1);
let trainer = new Trainer(myPerceptron);
let trainingSet = [];
let testSet = [];
let validationSet = [];
// let fullData = getFullData([2014, 2015]);
// let testData = getFullData([2017]);
// let validationData = getFullData([2016]);
let scoresFull = getFullData2(2014, 'Fluminense');
let scores = scoresFull.ts;
let midAndTotal = calcMidAndTotal(scores);
let mid = midAndTotal.mid;
let total = midAndTotal.total;
console.log(mid.length);
console.log(total.length);
for(i = 0; i < (scores.length -1); i++){
trainingSet.push({
input: [
scores[i],
mid[i],
total[i]
],
output: [
scores[i+1]
]
});
}
trainer.train(trainingSet, {
rate: 0.0005,
iterations: 30,
shuffle: true,
cost: Trainer.cost.CROSS_ENTROPY,
schedule: {
every: 1, // repeat this task every 500 iterations
do: function(data) {
// custom log
console.log(
data.iterations +
" " +
trainingSet[data.iterations].output +
" " +
myPerceptron.activate(trainingSet[data.iterations].input) +
" " +
data.error
);
//console.log(
// " ",
// data.error,
// " ",
// data.iterations,
// " ",
// data.rate
//);
}
}
});
function calcMidAndTotal(scores){
const mid = [];
const total = [];
let buffer;
for(let i =0; i< scores.length; i++){
if(i>0){
buffer = 0;
for(j = 0; j <i; j++){
buffer += scores[j];
}
mid.push(buffer/(i + 1));
total.push(buffer);
}
else{
mid.push(scores[i]);
total.push(scores[i]);
}
}
return {mid: mid, total: total};
}
//myNetwork.setOptimize(false);
//let neurons = myNetwork.neurons();
//for(let j =0; j<neurons.length; j++){
// neuron.squash;
//}
//var customFunction = function(x){
// return x
//};
// train the network - learn XOR