-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
29 lines (24 loc) · 896 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
const mlp = require('./lib/index');
const trainingSamples = [
new mlp.TrainingSample([0, 0], [0]),
new mlp.TrainingSample([0, 0], [0]),
new mlp.TrainingSample([0, 0], [0]),
new mlp.TrainingSample([0, 1], [1]),
new mlp.TrainingSample([1, 0], [1]),
new mlp.TrainingSample([1, 1], [1])
]
for(let sample of trainingSamples) {
sample.addBiasValue(1);
}
numFeatures = trainingSamples[0].inputVector.length;
numOutputs = trainingSamples[0].outputVector.length;
network = new mlp.MLP([numFeatures, 2, numOutputs], ['sigmoid', 'linear']);
network.train(trainingSamples, 0.5, 500, 0.25);
for(let sample of trainingSamples) {
const output = network.getOutput(sample.inputVector);
for(let i = 0; i < numOutputs; i++) {
const predicted = output[i] > 0.5;
const correct = sample.outputVector[i] > 0.5;
console.log(predicted === correct);
}
}