作者yt123 (哈)
看板MATLAB
标题[讨论] narx 类神经网路-时间序列预测
时间Thu Sep 13 12:35:03 2012
各位前辈~~
我以ntstool产生一个narx的时间序列预测
但因每次执行,所产生的结果都不一样
也不知道哪一个结果比较好
不知道大家在做类神经网路的时候都怎麽修改这样的问题
我的想法是
先做一次执行,若预测值与目标值误差太大,则继续训练
但不知道在narx这样的时间序列预测要怎麽修改??
可否教我怎麽改
clear all
clc
rawInputData=xlsread('BundDaily.xlsx','sheet1','B2:AG30');
rawTargetData=xlsread('BundDaily.xlsx','sheet2','E2:E30');
% rawTargetData - feedback time series.
inputSeries = tonndata(rawInputData,false,false);
targetSeries = tonndata(rawTargetData,false,false);
% Create a Nonlinear Autoregressive Network with External Input
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = 10;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize);
[inputs,inputStates,layerStates,targets] = preparets(net,inputSeries,{},targetSeries);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 60/100;
net.divideParam.valRatio = 20/100;
net.divideParam.testRatio = 20/100;
% Train the Network
[net,tr] = train(net,inputs,targets,inputStates,layerStates);
% Test the Network
outputs = net(inputs,inputStates,layerStates);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs);
% View the Network
view(net)
netc = closeloop(net);
netc.name = [net.name ' - Closed Loop'];
view(netc)
[xc,xic,aic,tc] = preparets(netc,inputSeries,{},targetSeries);
yc = netc(xc,xic,aic);
closedLoopPerformance = perform(netc,tc,yc)
%=============================
% figure(1)
% plot([cell2mat(yc)' cell2mat(tc)'])
% Early Prediction Network
% For some applications it helps to get the prediction a timestep early.
% The original network returns predicted y(t+1) at the same time it is given y(t+1).
% For some applications such as decision making, it would help to have predicted
% y(t+1) once y(t) is available, but before the actual y(t+1) occurs.
% The network can be made to return its output a timestep early by removing one delay
% so that its minimal tap delay is now 0 instead of 1. The new network returns the
% same outputs as the original network, but outputs are shifted left one timestep.
nets = removedelay(net);
nets.name = [net.name ' - Predict One Step Ahead'];
view(nets)
[xs,xis,ais,ts] = preparets(nets,inputSeries,{},targetSeries);
ys = nets(xs,xis,ais);
earlyPredictPerformance = perform(nets,ts,ys)
figure(1)
plot([cell2mat(ys)' cell2mat(ts)'])
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.124.90.158