突触js lstm rnn算法的死简单例子 [英] Dead simple example of synaptic js lstm rnn algorithm
问题描述
LSTM RNN预测时间序列数据的死简单示例非常疯狂。
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?
我想A)使用数组训练算法然后B)使用以下数组测试算法:
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
];
应该导致它预测 0
。
不幸的是文档非常糟糕,没有明确的代码示例。有人有任何例子吗?
Unfortunately the documentation is pretty bad, no clear code examples exist. Anyone have any examples?
推荐答案
这个答案不是用Synaptic写的,而是用 Neataptic 。我决定快速回答一下,我将很快将其纳入文档中。这是代码,它工作9/10次:
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,
});
在JSFIDDLE上运行它以查看预测!要获得更多预测,请打开这一个。
Run it on JSFIDDLE to see the prediction! For more predictions, open this one.
我做出的一些选择的解释:
Explanation to some choices I made:
- 我设定选项清除为true,因为您需要按时间顺序进行时间序列预测。这可确保网络从每次训练迭代的开始开始,而不是从最后一次迭代的结束继续。
- 费率相当低,将获得更高的费率卡在MSE错误
~0.2
- LSTM有1块6个内存节点,较低的数量似乎不起作用还有。
- 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.
这篇关于突触js lstm rnn算法的死简单例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!