没有一个非常简单的 LSTM RNN 预测时间序列数据的例子真是太疯狂了。
https://github.com/cazala/synaptic
https://github.com/cazala/synaptic/wiki/Architect#lstm
我想使用以下数组中的历史数据:
const array = [
0,
0,
0,
1,
0,
0,
0,
1
];
一些非常令人兴奋的数据,对吗?
我想 A) 使用数组训练算法,然后 B) 使用以下数组测试算法:
const array = [
0,
0,
0,
1,
0,
0,
0,
1,
0
];
应该导致它预测 0
。
不幸的是文档很糟糕,没有清晰的代码示例存在。谁有任何例子?
最佳答案
这个答案不是用 Synaptic 写的,而是用 Neataptic 写的.我决定快速回答,我将很快将其包含在文档中。这是代码,它运行了 9/10 次:
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!更多预测,打开this one .
对我所做的一些选择的解释:
- 我将选项 clear 设置为 true,因为您希望进行时间序列预测。这可确保网络从每次训练迭代的“开始”开始,而不是从上一次迭代的“结束”继续。
- 速率相当低,更高的速率将卡在
~0.2
的 MSE 错误处
- LSTM 有 1 个 block ,每 block 6 个内存节点,数量较少似乎效果不佳。
关于javascript - 突触js lstm rnn算法的死简单例子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43574799/