我对使用递归神经网络进行时间序列分析的生成器函数有一个问题。我有一个包含5个不同CDS引号的数据集。我想用递归神经网络在多输入/多输出网络中分析这些问题。5个引号作为输入,5个引号作为输出。
因此,我有一个生成器,它可以将几个输入转换成一个输出,并且我不能为了我的目的而改变这段代码。
回顾是网络应该返回多远,延迟是要预测的时间范围,步长是1,因为我有每天的数据,没有更深层次的小时或分钟数据。有了索引,人们可以决定哪些行应该在子集内(训练、验证、测试)。
代码如下:
generator <- function(data, lookback, delay, min_index, max_index,
shuffle = FALSE, batch_size = 128, step = 1) {
if (is.null(max_index))
max_index <- nrow(data) - delay - 1
i <- min_index + lookback
function() {
if (shuffle) {
rows <- sample(c((min_index+lookback):max_index), size = batch_size)
} else {
if (i + batch_size >= max_index)
i <<- min_index + lookback
rows <- c(i:min(i+batch_size-1, max_index))
i <<- i + length(rows)
}
samples <- array(0, dim = c(length(rows),
lookback / step,
dim(data)[[-1]]))
targets <- array(0, dim = c(length(rows)))
for (j in 1:length(rows)) {
indices <- seq(rows[[j]] - lookback, rows[[j]]-1,
length.out = dim(samples)[[2]])
samples[j,,] <- data[indices,]
targets[[j]] <- data[rows[[j]] + delay, 1]
}
list(samples, targets)
}}
希望有人可以帮助我解决这个问题,或有一些其他有用的链接,建立一个时间序列金融数据的RNN。
谢谢你的帮忙
发布于 2018-06-06 02:45:45
好的,看起来我自己找到了解决方案。而不是
targets <- array(0, dim = c(length(rows)))这是一个向量,我用了
targets <- array(0, dim = c(length(rows),dim(data)[[-1]]))它现在是一个矩阵。
然后写下
targets[j,] <- data[rows[[j]] + delay, ]而不是
targets[[j]] <- data[rows[[j]] + delay, 1]此生成器为多个输出创建3D张量。
https://stackoverflow.com/questions/50639446
复制相似问题