timeseries forecasting for 10 years ahead ANN
Hi,
i would like to forecast the Cl parameter for 10 years ahead. But keep getting error : Index in position 2 exceeds array bounds. Index must not exceed 1. by the way , when running the code, i have remove the heading, words from the excel. but still getting the error
Error in preparets (line 317)
xi = xx(:,FBS+((1-net.numInputDelays):0));
Error in timee (line 25)
[X,inputStates,layerStates,T] = preparets(net,inputSeries,{},targetSeries);
Please help to check which part that i did wrong.
data = readmatrix ("104CPr.csv");
Input = data(:,1:(end-1));
Target = data(:,end);
X = con2seq(Input)’;
T = con2seq(Target)’;
%% Data Preparation
N = 10; % Multi-step ahead prediction
% Input and target series are divided in two groups of data:
% 1st group: used to train the network
inputSeries = X(1:end-N);
targetSeries = T(1:end-N);
%% Network architecture
delay = 2;
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = 10;
trainFcn = ‘trainbr’;
% Network Creation
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,’open’, trainFcn);
[X,inputStates,layerStates,T] = preparets(net,inputSeries,{},targetSeries);
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
[net,Y] = train(net,X,T,inputStates,layerStates);
outputs = net(X,inputStates,layerStates);
errors = gsubtract(T,Y);
performance = perform(net,T,Y);
view(net)
delay = 2;
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);
% Early Prediction Network
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);
%%5. Multi-step ahead prediction
inputSeriesPred = [inputSeries(end-delay+1:end),inputSeriesVal];
targetSeriesPred = [targetSeries(end-delay+1:end), con2seq(nan(1,N))];
[Xs,Xi,Ai,Ts] = preparets(netc,inputSeriesPred,{},targetSeriesPred);
yPred = netc(Xs,Xi,Ai);
perf = perform(net,yPred,targetSeriesVal);
figure;
plot([cell2mat(targetSeries),nan(1,N);
nan(1,length(targetSeries)),cell2mat(yPred);
nan(1,length(targetSeries)),cell2mat(targetSeriesVal)]’)
legend(‘Original Targets’,’Network Predictions’,’Expected Outputs’);Hi,
i would like to forecast the Cl parameter for 10 years ahead. But keep getting error : Index in position 2 exceeds array bounds. Index must not exceed 1. by the way , when running the code, i have remove the heading, words from the excel. but still getting the error
Error in preparets (line 317)
xi = xx(:,FBS+((1-net.numInputDelays):0));
Error in timee (line 25)
[X,inputStates,layerStates,T] = preparets(net,inputSeries,{},targetSeries);
Please help to check which part that i did wrong.
data = readmatrix ("104CPr.csv");
Input = data(:,1:(end-1));
Target = data(:,end);
X = con2seq(Input)’;
T = con2seq(Target)’;
%% Data Preparation
N = 10; % Multi-step ahead prediction
% Input and target series are divided in two groups of data:
% 1st group: used to train the network
inputSeries = X(1:end-N);
targetSeries = T(1:end-N);
%% Network architecture
delay = 2;
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = 10;
trainFcn = ‘trainbr’;
% Network Creation
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,’open’, trainFcn);
[X,inputStates,layerStates,T] = preparets(net,inputSeries,{},targetSeries);
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
[net,Y] = train(net,X,T,inputStates,layerStates);
outputs = net(X,inputStates,layerStates);
errors = gsubtract(T,Y);
performance = perform(net,T,Y);
view(net)
delay = 2;
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);
% Early Prediction Network
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);
%%5. Multi-step ahead prediction
inputSeriesPred = [inputSeries(end-delay+1:end),inputSeriesVal];
targetSeriesPred = [targetSeries(end-delay+1:end), con2seq(nan(1,N))];
[Xs,Xi,Ai,Ts] = preparets(netc,inputSeriesPred,{},targetSeriesPred);
yPred = netc(Xs,Xi,Ai);
perf = perform(net,yPred,targetSeriesVal);
figure;
plot([cell2mat(targetSeries),nan(1,N);
nan(1,length(targetSeries)),cell2mat(yPred);
nan(1,length(targetSeries)),cell2mat(targetSeriesVal)]’)
legend(‘Original Targets’,’Network Predictions’,’Expected Outputs’); Hi,
i would like to forecast the Cl parameter for 10 years ahead. But keep getting error : Index in position 2 exceeds array bounds. Index must not exceed 1. by the way , when running the code, i have remove the heading, words from the excel. but still getting the error
Error in preparets (line 317)
xi = xx(:,FBS+((1-net.numInputDelays):0));
Error in timee (line 25)
[X,inputStates,layerStates,T] = preparets(net,inputSeries,{},targetSeries);
Please help to check which part that i did wrong.
data = readmatrix ("104CPr.csv");
Input = data(:,1:(end-1));
Target = data(:,end);
X = con2seq(Input)’;
T = con2seq(Target)’;
%% Data Preparation
N = 10; % Multi-step ahead prediction
% Input and target series are divided in two groups of data:
% 1st group: used to train the network
inputSeries = X(1:end-N);
targetSeries = T(1:end-N);
%% Network architecture
delay = 2;
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = 10;
trainFcn = ‘trainbr’;
% Network Creation
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,’open’, trainFcn);
[X,inputStates,layerStates,T] = preparets(net,inputSeries,{},targetSeries);
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
[net,Y] = train(net,X,T,inputStates,layerStates);
outputs = net(X,inputStates,layerStates);
errors = gsubtract(T,Y);
performance = perform(net,T,Y);
view(net)
delay = 2;
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);
% Early Prediction Network
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);
%%5. Multi-step ahead prediction
inputSeriesPred = [inputSeries(end-delay+1:end),inputSeriesVal];
targetSeriesPred = [targetSeries(end-delay+1:end), con2seq(nan(1,N))];
[Xs,Xi,Ai,Ts] = preparets(netc,inputSeriesPred,{},targetSeriesPred);
yPred = netc(Xs,Xi,Ai);
perf = perform(net,yPred,targetSeriesVal);
figure;
plot([cell2mat(targetSeries),nan(1,N);
nan(1,length(targetSeries)),cell2mat(yPred);
nan(1,length(targetSeries)),cell2mat(targetSeriesVal)]’)
legend(‘Original Targets’,’Network Predictions’,’Expected Outputs’); ann, time series MATLAB Answers — New Questions