forked from BrainJS/brain.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
predict-numbers.ts
27 lines (21 loc) · 935 Bytes
/
predict-numbers.ts
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
import * as assert from 'assert';
import * as brain from '../index';
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);