-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
34 lines (28 loc) · 1.07 KB
/
test.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
let History = require("./model/history");
let Event = require("./model/event");
let Model = require("./model/model");
let h = new History("test.db");
h.setup(function() {
for(var n=0; n<1000; n++) {
let weekend = Math.random() > (2/7) ? 1 : 0;
let uur = Math.round(Math.random() * 24);
let aan = (!weekend && (uur >= 8 && uur <= 9) || (uur >= 18 && uur <= 23)) || (weekend && (uur >= 10 && uur <=23));
let randomFlip = Math.random() < 0.01 ? !aan : aan;
console.log("Train", uur, weekend, randomFlip ? 1 : -1);
h.save(new Event("light", randomFlip ? 1 : -1, {uur: uur, weekend: weekend}));
}
h.save(new Event("light", -1, { "uur": 23, "weekend": 0 }), function() {
let model = new Model();
model.train("light", h, function() {
console.log('model is trained!', model.svm.toJSON());
var ys = [];
var wys = [];
for(var u=0; u<24; u++) {
ys.push(model.predict({uur: u, weekend: 0 })[0]);
wys.push(model.predict({uur: u, weekend: 1 })[0]);
}
console.log("Week\t\t", ys.join("\t"));
console.log("Weekends\t", wys.join("\t"));
});
});
});