-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (28 loc) · 927 Bytes
/
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
var synaptic = require('synaptic');
const {Layer, Network} = synaptic;
var inputLayer = new Layer(2);
var hiddenLayer = new Layer(3);
var outputLayer = new Layer(1);
inputLayer.project(hiddenLayer);
hiddenLayer.project(outputLayer);
var myNetwork = new Network({
input: inputLayer,
hidden: [hiddenLayer],
output: outputLayer
});
var learningRate = .3;
for (var i = 0; i < 20000; i++) {
console.log(`Training Network - Iteration: ${i+1}`)
myNetwork.activate([0,0]);
myNetwork.propagate(learningRate, [0]);
myNetwork.activate([0,1]);
myNetwork.propagate(learningRate, [1]);
myNetwork.activate([1,0]);
myNetwork.propagate(learningRate, [1]);
myNetwork.activate([1,1]);
myNetwork.propagate(learningRate, [0]);
}
console.log(myNetwork.activate([0,0]));
console.log(myNetwork.activate([0,1]));
console.log(myNetwork.activate([1,0]));
console.log(myNetwork.activate([1,1]));