Please help with narnext time serie prediction error .????

2 vues (au cours des 30 derniers jours)
SONGBIAN ZIME
SONGBIAN ZIME le 22 Mai 2014
Réponse apportée : Jan le 1 Juin 2014
I need really help, 2 months ago I can't fix the error,My goal is to predict the GDPA for next 5 years using narxnet on matlab. The data is time serie 23 rows ( 1990-2012), the input 17 attributes , 17 colums (1 to 17), the output is the last colum, the GDPA (18 th) I have the following error. ??? Subscripted assignment dimension mismatch.
Error in ==> preparets at 230 xx(inputFeedbackInd,TSind) = openFeedback; please here my code. and screenshot of Data.
if true
% % %%Transform Raw Data into Time Series for the Model
data_inputs=xlsread('GDPA.xlsx');
% input the data;
x1=data_inputs(1,1:17);
x2=data_inputs(2,1:17);
x3=data_inputs(3,1:17);
x4=data_inputs(4,1:17);
x5=data_inputs(5,1:17);
x6=data_inputs(6,1:17);
x7=data_inputs(6,1:17);
x8=data_inputs(7,1:17);
x9=data_inputs(9,1:17);
x10=data_inputs(10,1:17);
x11=data_inputs(11,1:17);
x12=data_inputs(12,1:17);
x13=data_inputs(13,1:17);
x14=data_inputs(14,1:17);
x15=data_inputs(15,1:17);
x16=data_inputs(16,1:17);
x17=data_inputs(17,1:17);
x18=data_inputs(18,1:17);
x19=data_inputs(19,1:17);
x20=data_inputs(20,1:17);
x21=data_inputs(21,1:17);
x22=data_inputs(22,1:17);
x23=data_inputs(23,1:17);
y=data_inputs(:,18);
%Transform into Neural Network Data
X1 = num2cell(x1);
X2 = num2cell(x2);
X3 = num2cell(x3);
X4 = num2cell(x4);
X5 = num2cell(x5);
X6 = num2cell(x6);
X7 = num2cell(x7);
X8 = num2cell(x8);
X9 = num2cell(x9);
X10 = num2cell(x10);
X11 = num2cell(x11);
X12 = num2cell(x12);
X13 = num2cell(x13);
X14 = num2cell(x14);
X15 = num2cell(x15);
X16 = num2cell(x16);
X17 = num2cell(x17);
X18 = num2cell(x18);
X19 = num2cell(x19);
X20 = num2cell(x20);
X21 = num2cell(x21);
X22 = num2cell(x22);
X23 = num2cell(x23);
yt = num2cell(y)';
%%Inputs and target
Input = catelements(X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13,X14,X15,X16,X17,X18,X19,X20,X21,X22,X23);
Target=yt;
%%2 Data preparation
N = 5; % Multi-step ahead prediction
% Input and target series are divided in two groups of data:
% 1st group: used to train the network
inputSeries = Input(:,1:end-N);
%inputSeries = Input(1:end-N);
targetSeries = Target(1:end-N);
%second group this is the new data used for simulation. inputSeriesVal will be used for predicting new targets. targetSeriesVal will be used for network validation after prediction
inputSeriesVal = Input(:,end-N+1:end);
targetSeriesVal = Target(end-N+1:end); % This is generally not available
inputDelays = 1:3;
feedbackDelays = 1:3;
hiddenLayerSize = 50;
%%3-Network Creation
%Create a Nonlinear Autoregressive Network with External Input
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize);
delay = 4;
neuronsHiddenLayer = 25;
net = narxnet(1:delay,1:delay,neuronsHiddenLayer);
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
net.inputs{2}.processFcns = {'removeconstantrows','mapminmax'};
%%4 Training the network
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
net.inputs{2}.processFcns = {'removeconstantrows','mapminmax'};
% Prepare the Data for Training and Simulation
% The function PREPARETS prepares timeseries data for a particular network,
% shifting time by the minimum amount to fill input states and layer states.
% Using PREPARETS allows you to keep your original time series data unchanged, while
% easily customizing it for networks with differing numbers of delays, with
% open loop or closed loop feedback modes.
[inputs,inputStates,layerStates,targets] = preparets(net,inputSeries(1,:),{},targetSeries);
% Setup Division of Data for Training, Validation, Testing
% The function DIVIDERAND randomly assigns target values to training,
% validation and test sets during training.
% For a list of all data division functions type: help nndivide
net.divideFcn = 'dividerand'; % Divide data randomly
% The property DIVIDEMODE set to TIMESTEP means that targets are divided
% into training, validation and test sets according to timesteps.
% For a list of data division modes type: help nntype_data_division_mode
net.divideMode = 'value'; % Divide up every value
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Choose a Training Function
% For a list of all training functions type: help nntrain
% Customize training parameters at: net.trainParam
net.trainFcn = 'trainlm'; % Levenberg-Marquardt
% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
% Customize performance parameters at: net.performParam
net.performFcn = 'mse'; % Mean squared error
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
% Customize plot parameters at: net.plotParam
net.plotFcns = {'plotperform','plottrainstate','plotresponse', ...
'ploterrcorr', 'plotinerrcorr'};
%%Train the Network
[net,tr] = train(net,inputs,targets,inputStates,layerStates)
%%Test the Network
outputs = net(inputs,inputStates,layerStates);
errors = gsubtract(targets,outputs);
% Performance for the series-parallel implementation, only
% one-step-ahead prediction
performance = perform(net,targets,outputs)
% Recalculate Training, Validation and Test Performance
trainTargets = gmultiply(targets,tr.trainMask);
valTargets = gmultiply(targets,tr.valMask);
testTargets = gmultiply(targets,tr.testMask);
trainPerformance = perform(net,trainTargets,outputs)
valPerformance = perform(net,valTargets,outputs)
testPerformance = perform(net,testTargets,outputs)
% View the Network
view(net)
Y = net(inputs,inputStates,layerStates);
%%Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, plotregression(targets,outputs)
%figure, plotresponse(targets,outputs)
%figure, ploterrcorr(errors)
%figure, plotinerrcorr(inputs,errors)
% Closed Loop Network
% Use this network to do multi-step prediction.
% The function CLOSELOOP replaces the feedback input with a direct
% connection from the outout layer.
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
% 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)
%%5- Multi-step ahead prediction
inputSeriesPred = [inputSeries(1,end-delay+1:end),inputSeriesVal(1,:)];
targetSeriesPred = [targetSeries(end-delay+1:end), con2seq(nan(1,N))];
netc = closeloop(net);
view(netc)
%%6-Neural Network Prediction Compared against Actual Market Price
[inputs,inputStates,layerStates,targets] = preparets(netc,inputSeriesPred,{},targetSeriesPred);
yPred = netc(inputs,inputStates,layerStates);
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')
end
  2 commentaires
Greg Heath
Greg Heath le 30 Mai 2014
you might get some help if your data is made readily accessible for cut ans paste or uncomplicated downloading.
Greg Heath
Greg Heath le 1 Juin 2014
Don't need help anymore?

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 1 Juin 2014
This is a job for the debugger. Set a breakpoint in your code and step through the code line by line until the failing line. Now inspect the variables to understand, what's going on.
Adding the index to the name of the variables line "x1", "x2" etc. is ugly and prone to typos. You could omit 40 lines of code if you avoid such numbering.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by