突触js lstm rnn算法的死简单例子

Kar*_*son 5 javascript algorithm machine-learning

令人遗憾的是,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
];
Run Code Online (Sandbox Code Playgroud)

有些漂亮的心灵数据就在那里吗?

我想A)用数组训练算法然后B)使用以下数组测试算法:

const array = [
    0,
    0,
    0,
    1,
    0,
    0,
    0,
    1,
    0
];
Run Code Online (Sandbox Code Playgroud)

应该导致它预测a 0.

不幸的是,文档很糟糕,没有明确的代码示例.有人有任何例子吗?

Tho*_*s W 7

这个答案不是用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 Code Online (Sandbox Code Playgroud)

在JSFIDDLE上运行它以查看预测!要获得更多预测,请打开预测.

我做出的一些选择的解释:

  • 我将选项清除设置为true,因为您需要按时间顺序进行时间序列预测.这确保了网络从每次训练迭代的"开始"开始,而不是从最后一次迭代的"结束"继续.
  • 速率相当低,更高的速率将陷入MSE误差 ~0.2
  • LSTM有1个块的6个内存节点,较低的数量似乎也不起作用.

  • 注意,最新版本“newneaaptic.architect.LSTM(1,6,1);”,注意“A”和“a”。 (2认同)