It's pretty crazy that there isn't a dead simple example of the LSTM RNN predicting time series data.
https://github.com/cazala/synaptic
https://github.com/cazala/synaptic/wiki/Architect#lstm
I'd like to use the historical data in the following array:
const array = [
0,
0,
0,
1,
0,
0,
0,
1
];
Some pretty mind blowing data right there right?
I'd like to A) train the algorithm with the array then B) test the algorithm with the following array:
const array = [
0,
0,
0,
1,
0,
0,
0,
1,
0
];
Should result in it predicting a 0
.
Unfortunately the documentation is pretty bad, no clear code examples exist. Anyone have any examples?
Long short-term memory (LSTM) networks are an extension of RNN that extend the memory. LSTM are used as the building blocks for the layers of a RNN. LSTMs assign data “weights” which helps RNNs to either let new information in, forget information or give it importance enough to impact the output.
It difficult to train RNN that requires long-term memorization meanwhile LSTM performs better in these kinds of datasets it has more additional special units that can hold information longer. LSTM includes a 'memory cell' that can maintain information in memory for long periods of time.
As it is said, everything in this world comes with its own advantages and disadvantages, LSTMs too, have a few drawbacks which are discussed as below: LSTMs became popular because they could solve the problem of vanishing gradients. But it turns out, they fail to remove it completely.
This answer is not written with Synaptic, but with Neataptic. I decided to make a quick answer that I will include in the documentation soon. This is the code, it works 9/10 times:
var network = new neataptic.architect.LSTM(1,6,1);
// when the timeseries is [0,0,0,1,0,0,0,1...]
var trainingData = [
{ input: [0], output: [0] },
{ input: [0], output: [0] },
{ input: [0], output: [1] },
{ input: [1], output: [0] },
{ input: [0], output: [0] },
{ input: [0], output: [0] },
{ input: [0], output: [1] },
];
network.train(trainingData, {
log: 500,
iterations: 6000,
error: 0.03,
clear: true,
rate: 0.05,
});
Run it on JSFIDDLE to see the prediction! For more predictions, open this one.
Explanation to some choices I made:
~0.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With