突触js lstm rnn算法

时间:2017-04-23 18:18:01

标签: 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
];

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

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

const array = [
    0,
    0,
    0,
    1,
    0,
    0,
    0,
    1,
    0
];

应该导致它预测0

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

1 个答案:

答案 0 :(得分:6)

这个答案不是用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

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

  • 我将选项清除设置为true,因为您需要执行按时间顺序排列的时间序列预测。这可以确保网络从“开始”开始。每次训练迭代,而不是继续从结束'最后一次迭代。
  • 费率相当低,更高的费率将会遇到MSE错误~0.2
  • LSTM有1块6个内存节点,较低的数量似乎也无法正常工作。
相关问题