-
Notifications
You must be signed in to change notification settings - Fork 1
/
learners.js
57 lines (53 loc) · 1.54 KB
/
learners.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
#!/usr/bin/env node
/*
A module which provides a single API for multiple learning modules.
*/
/**
* pickLearner
*
* Provides a learner based on the given parameter, each learner has a
* guaranteed simple API (as far as motion-logger requires).
*
* @param learner
*/
function pickLearner(learner) {
return learners[learner];
}
var learners = {
brain: {
newLearner: function() {
var brain = require('brain');
return new brain.NeuralNetwork();
}
},
synaptic: {
newLearner: function() {
return new this.learner();
},
learner: function() {
var synaptic = require('synaptic');
this.network = new synaptic.Architect.Perceptron(40, 25, 3);
this.train = function(set, opts) {
var realOpts = (opts.log === true) ? {log: 10} : {};
return this.network.trainer.train(set, realOpts);
}
this.run = function(set) {
var result = this.network.activate(set);
var overall = 0;
for (var i in result) {
overall += result[i]
}
return overall/result.length;
}
this.toJSON = this.network.toJSON.bind(this.network);
this.fromJSON = this.network.fromJSON.bind(this.network);
}
},
duff: {
newLearner: function() {
var duff = require("./duff-learner.js");
return new duff();
}
}
}
module.exports = pickLearner;