神经网络开发和模拟结果及解释

时间:2017-04-28 04:52:39

标签: r neural-network time-series

我一直致力于开发一个向后传播(BP)神经网络来进行时间序列数据预测(过去两年的数据预测第三个).RORE中的AMORE包和神经网络包都有已经应用了,我在AMORE得到了我的输出。然而,最大的问题是我给出的输入值的所有测试样本最终共享完全相同的输出,这可能真的是灾难性的。我会在这里粘贴我的代码,希望有人会帮我一个忙。我真的很担心这个解释,非常感谢你的帮助。摆布!

library(AMORE)
tbincidence<-c(22.37,52.22,73.99,83.51,74.25,79.10,81.19,81.98,80.76,69.29,78.94,80.04,65.80,58.12,116.71,127.01,115.74,116.08,102.58,101.71,94.25,80.27,89.88,89.37,68.37,79.33,113.04,110.72,101.01,102.88,94.41,97.17,88.01,82.37,84.77,86.93,87.80,69.35,107.51,113.10,103.19,102.27,102.16,98.86,90.24,84.33,88.21,90.38,84.49,76.90,118.43,116.34,107.71,99.42,102.91,92.72,93.49,90.30,83.54,91.20,67.86,95.68,105.28,105.19,96.50,106.80,97.26,95.24,93.15,82.00,78.55,90.18,79.31,66.46,103.72,100.13,96.17,95.35,91.61,87.56,83.84,75.73,82.44,78.33,74.26,73.14,101.19,96.31,93.13,88.79,83.77,85.59,79.45,74.57,82.17,77.72,65.21,91.96,102.80,95.35,97.22,87.91,86.85,85.09,78.52,73.98,77.77,72.60,76.95,66.10,92.61,89.73,90.04,78.49,83.61,78.80,77.42,73.74,74.69,73.99,70.57,65.02,82.18,87.19,78.14,74.37,77.50,71.07,70.20,65.12,62.96,67.99,69.54,55.18,82.69,78.82,74.47,74.67,75.07,69.77,69.25,62.63,64.13,65.34,62.70,60.77,83.40,75.24,73.14,68.46,67.54,69.82,65.03,60.49,64.04,65.24,58.91,67.02)
tbincidence
lagtwo<-c(22.37,52.22,73.99,83.51,74.25,79.10,81.19,81.98,80.76,69.29,78.94,80.04,65.80,58.12,116.71,127.01,115.74,116.08,102.58,101.71,94.25,80.27,89.88,89.37,68.37,79.33,113.04,110.72,101.01,102.88,94.41,97.17,88.01,82.37,84.77,86.93,87.80,69.35,107.51,113.10,103.19,102.27,102.16,98.86,90.24,84.33,88.21,90.38,84.49,76.90,118.43,116.34,107.71,99.42,102.91,92.72,93.49,90.30,83.54,91.20,67.86,95.68,105.28,105.19,96.50,106.80,97.26,95.24,93.15,82.00,78.55,90.18,79.31,66.46,103.72,100.13,96.17,95.35,91.61,87.56,83.84,75.73,82.44,78.33,74.26,73.14,101.19,96.31,93.13,88.79,83.77,85.59,79.45,74.57,82.17,77.72,65.21,91.96,102.80,95.35,97.22,87.91,86.85,85.09,78.52,73.98,77.77,72.60,76.95,66.10,92.61,89.73,90.04,78.49,83.61,78.80,77.42,73.74,74.69,73.99,70.57,65.02,82.18,87.19,78.14,74.37,77.50,71.07,70.20,65.12,62.96,67.99,69.54,55.18,82.69,78.82,74.47,74.67,75.07,69.77,69.25,62.63,64.13,65.34,62.70,60.77,83.40,75.24,73.14,68.46,67.54,69.82,65.03,60.49,64.04,65.24)
lagone<-c(52.22,73.99,83.51,74.25,79.10,81.19,81.98,80.76,69.29,78.94,80.04,65.80,58.12,116.71,127.01,115.74,116.08,102.58,101.71,94.25,80.27,89.88,89.37,68.37,79.33,113.04,110.72,101.01,102.88,94.41,97.17,88.01,82.37,84.77,86.93,87.80,69.35,107.51,113.10,103.19,102.27,102.16,98.86,90.24,84.33,88.21,90.38,84.49,76.90,118.43,116.34,107.71,99.42,102.91,92.72,93.49,90.30,83.54,91.20,67.86,95.68,105.28,105.19,96.50,106.80,97.26,95.24,93.15,82.00,78.55,90.18,79.31,66.46,103.72,100.13,96.17,95.35,91.61,87.56,83.84,75.73,82.44,78.33,74.26,73.14,101.19,96.31,93.13,88.79,83.77,85.59,79.45,74.57,82.17,77.72,65.21,91.96,102.80,95.35,97.22,87.91,86.85,85.09,78.52,73.98,77.77,72.60,76.95,66.10,92.61,89.73,90.04,78.49,83.61,78.80,77.42,73.74,74.69,73.99,70.57,65.02,82.18,87.19,78.14,74.37,77.50,71.07,70.20,65.12,62.96,67.99,69.54,55.18,82.69,78.82,74.47,74.67,75.07,69.77,69.25,62.63,64.13,65.34,62.70,60.77,83.40,75.24,73.14,68.46,67.54,69.82,65.03,60.49,64.04,65.24,58.91)
predict<-cbind(lagtwo,lagone)
predict<-matrix(predict,ncol=2,byrow=F)
predict
output<-c(73.99,83.51,74.25,79.10,81.19,81.98,80.76,69.29,78.94,80.04,65.80,58.12,116.71,127.01,115.74,116.08,102.58,101.71,94.25,80.27,89.88,89.37,68.37,79.33,113.04,110.72,101.01,102.88,94.41,97.17,88.01,82.37,84.77,86.93,87.80,69.35,107.51,113.10,103.19,102.27,102.16,98.86,90.24,84.33,88.21,90.38,84.49,76.90,118.43,116.34,107.71,99.42,102.91,92.72,93.49,90.30,83.54,91.20,67.86,95.68,105.28,105.19,96.50,106.80,97.26,95.24,93.15,82.00,78.55,90.18,79.31,66.46,103.72,100.13,96.17,95.35,91.61,87.56,83.84,75.73,82.44,78.33,74.26,73.14,101.19,96.31,93.13,88.79,83.77,85.59,79.45,74.57,82.17,77.72,65.21,91.96,102.80,95.35,97.22,87.91,86.85,85.09,78.52,73.98,77.77,72.60,76.95,66.10,92.61,89.73,90.04,78.49,83.61,78.80,77.42,73.74,74.69,73.99,70.57,65.02,82.18,87.19,78.14,74.37,77.50,71.07,70.20,65.12,62.96,67.99,69.54,55.18,82.69,78.82,74.47,74.67,75.07,69.77,69.25,62.63,64.13,65.34,62.70,60.77,83.40,75.24,73.14,68.46,67.54,69.82,65.03,60.49,64.04,65.24,58.91,67.02)
output<-matrix(output,ncol=1)
output
trainPmatrix<-predict[1:130,]
trainTmatrix<-output[1:130,]
testPmatrix<-predict[131:156,]
testTmatrix<-output[131:156,]
net<-newff(n.neurons=c(2,5,1),learning.rate.global=1e-3,momentum.global=0.5,error.criterium="LMS",Stao=NA,hidden.layer="tansig",output="purelin",method="ADAPTgdwm")
result<-        train(net,trainPmatrix,trainTmatrix,error.criterium="LMS",report=TRUE,show.step=100,n.shows=10)
y<-sim(result$net,testPmatrix)
y

输出将是这样的。

y
          [,1]
 [1,] 84.81958
 [2,] 84.81958
 [3,] 84.81957
 [4,] 84.81958
 [5,] 84.81958
 [6,] 84.81958
 [7,] 84.81958
 [8,] 84.81958
 [9,] 84.81958
[10,] 84.81958
[11,] 84.81958
[12,] 84.81958
[13,] 84.81958
[14,] 84.81958
[15,] 84.81958
[16,] 84.81958
[17,] 84.81958
[18,] 84.81958
[19,] 84.81958
[20,] 84.81958
[21,] 84.81958
[22,] 84.81958
[23,] 84.81958
[24,] 84.81958
[25,] 84.81958
[26,] 84.81958

怎么可能!! [/ p>

非常感谢您的敏锐想法!

1 个答案:

答案 0 :(得分:0)

我使用R已经有一段时间了,而且我对AMORE并不熟悉。但是,你是否以任何方式规范你的输入?它看起来并不像。您正在为隐藏图层使用tansig函数,该函数返回介于-1和1之间的值。如果您的输入位于该范围内,则可能会更好。对于时间序列,您可以使用从一个值到下一个值而不是原始值的百分比变化(表示为-1和1之间),然后根据需要进行缩放。我确定R库中的一个功能可以为你做到这一点。然后,您以反向方式转换输出以获得预测。

您可能不得不继续调整网络(学习率,动力等),但这可能是一个开始的地方。