-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
46 lines (44 loc) · 871 Bytes
/
Copy pathindex.js
File metadata and controls
46 lines (44 loc) · 871 Bytes
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
const Perceptron = require('./neuron_stub');
const set = [
{
inputs: [32, 175],
expected: 1
},
{
inputs: [24, 170],
expected: 1
},
{
inputs: [20, 50],
expected: 1
},
{
inputs: [30, 10],
expected: 0
},
{
inputs: [24, 340],
expected: 1
},
{
inputs: [64, 250],
expected: 0
},
{
inputs: [34, 120],
expected: 0
}
];
const perceptron = new Perceptron();
const maxX = Math.max(...set.map(({ inputs }) => inputs[0]));
const maxY = Math.max(...set.map(({ inputs }) => inputs[1]));
const trainSet = set.map(({ inputs, expected }) => ({
inputs: [inputs[0]/maxX, inputs[1]/maxY],
expected
}));
const testSet = set.map(({ inputs }) => [inputs[0]/maxX, inputs[1]/maxY]);
perceptron.learn(() => {
testSet.forEach((test) => {
console.log(test, perceptron.predict(test));
});
}, trainSet);