forked from BrainJS/brain.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredict-numbers.js
56 lines (50 loc) · 1.01 KB
/
predict-numbers.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
const assert = require('assert');
const brain = require('../../dist/brain');
const net = new brain.recurrent.LSTMTimeStep({
inputSize: 2,
hiddenLayers: [10],
outputSize: 2,
});
// Same test as previous, but combined on a single set
const trainingData = [
[
[1, 5],
[2, 4],
[3, 3],
[4, 2],
[5, 1],
],
];
net.train(trainingData, { log: true, errorThresh: 0.09 });
const closeToFiveAndOne = net.run([
[1, 5],
[2, 4],
[3, 3],
[4, 2],
]);
assert(
Math.round(closeToFiveAndOne[0]) === 5,
`${closeToFiveAndOne[0]} does not round to 5`
);
assert(
Math.round(closeToFiveAndOne[1]) === 1,
`${closeToFiveAndOne[1]} does not round to 1`
);
console.log(closeToFiveAndOne);
// now we're cookin' with gas!
const forecast = net.forecast(
[
[1, 5],
[2, 4],
],
3
);
assert(
Math.round(forecast[2][0]) === 5,
`${forecast[2][0]} does not round to 5`
);
assert(
Math.round(forecast[2][1]) === 1,
`${forecast[2][1]} does not round to 1`
);
console.log('next 3 predictions', forecast);