Dead simple example of synaptic js lstm rnn algorithm

后端 未结 1 726
孤街浪徒
孤街浪徒 2021-01-01 03:16

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://g

相关标签:
1条回答
  • 2021-01-01 03:42

    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:

    • I set option clear to true, as you want do a chronological timeseries prediction. This makes sure that the network starts from the 'beginning' every training iteration, instead of continuing on from the 'end' of the last iteration.
    • Rate is fairly low, higher rates will get stuck at an MSE error of ~0.2
    • The LSTM has 1 block of 6 memory nodes, lower amounts don't seem to work as well.
    0 讨论(0)
提交回复
热议问题