Question about preparing data for closed loop NarX

1 view (last 30 days)
Good, and I posted the problem that I have made, I return it to post to indicate that I have not yet found a solution to this problem and have if someone can help me. The boot files are twofold:
-One contains the inputs and consists of 2272 rows by 13 columns -the other file is composed of 2272 rows by 1 column.
The code already imported the split data for direct use.
I think the problem is that the network has been trained with dimensions and to create a new input data and targets, I do not meet those dimensions and still gives me error.
The code you posted I think it works correctly because I tested with some data in compliance with the network size and predicts well.
I will try to put the code used as clear as possible to see if you can give me some idea. I continued to test and I get the same error.
if true
% code
% PREDICTION %
xlsread p1; %matrix 1136x13
xlsread p2; %matrix 1136x13
xlsread t1; %matrix 1136x1
xlsread t2; %matrix 1136x1
p1=p1'; %matrix 13x1136
p2=p2'; %matrix 13X1136
t1=t1'; %matrix 1X1136
t2=t2'; %matrix 1x1136
nputSeries = tonndata(p1,true,false); %cell 1x1136
targetSeries = tonndata(t1,true,false); %cell 1x1136
% Create a Nonlinear Autoregressive Network with External Input
inputDelays = 1:1;
feedbackDelays = 1:1;
hiddenLayerSize = 16;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize);
[inputs,inputStates,layerStates,targets] = preparets(net,inputSeries,{},targetSeries);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/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);
% Closed Loop Network
netc = closeloop(net);
netc.name = [net.name ' - Closed Loop'];
NumberOfPredictions = 3;
% Creating a new input series
newInputSeries = p2(1:NumberOfPredictions); %here I built the array must be
%dimensioned 13x3
newInputSeries = [cell2mat(inputSeries(end-1:end) ) (newInputSeries)]; %
%matrix 13x5
newInputSeries = num2cell(newInputSeries); %cell 13x5
%Creating a new target
newTargetSet = nan(size(newInputSeries)); %matrix 13x5
newTargetSet = num2cell(newTargetSet );
newTargetSet (1:1) = targetSeries(end:end); %cell 13x5
[xc,xic,aic,tc] = preparets(netc,newInputSeries,{},newTargetSet);
I tried to apply to normalize newInputSeries tonndata newTargetSet and out and in both cases a 1x5 matrix. Applying preparets out well but I simulate values for prediction makes me the following error:
"Error using network/sim (line 130) Layer state sizes does not match net.layers{:}.size."
If someone comes to how to fix it, or where it can refer to appreciate it.
Thank you very much
  8 Comments
Shashank Prasanna
Shashank Prasanna on 8 Feb 2013
FRANCISCO, I have already shared a perfectly working prediction code in your previous post. At this point all you have to do is make sure that your inputs are in the same form as the one in the working example. From you are error message it is extremely clear that your inputs are not as expected by the function. Even if you feel that the documentation is unclear the ONLY thing you have to do is to make sure that the dimensions are in order compared to the working example.
FRANCISCO
FRANCISCO on 9 Feb 2013
Thank you very much for your response and collaboration. I have still some doubts and I'd like to indicases, thus better understand the operation of the network. In the joint use for the training of the network is formed by a matrix for inputSeries 1x1136 and 1x1136 for another targetSeries matrix. In the group that used to make new inputs and new targets consists of two 1x5 matrices to perform again on newInputSeries and newTargetSet tonndata. To simulate the network closeloop 1x1136 should be shown? But I did a first simulation code size data you've posted and simulate network closeloop sample everything was different and so I pretended new data network. Is this what you do not understand, except that in the example posted, when I perform and apply the command newinputseries newInputSeries = p2 (1: NumberOfPredictions); matlab I rightly divided, That is, as I have a row the result is a matrix 1x30, but my data to be 13 rows and I only use this command divides the front row and I think that's wrong. These are the questions that I posed because I can not think where I can make more mistakes because the network here works well.

Sign in to comment.

Accepted Answer

Greg Heath
Greg Heath on 9 Feb 2013
0. I USED YOUR CODE ON THE POLLUTION_DATASET
1. VARIABLES ON DIFFERENT SCALES;. SHOULD NORMALIZE
2. PLOT INPUT AND OUPUTS
3. NARXNET INPUTS ARE NOT OPTIMAL. FIND SIGNIFICANT AUTO
AND CROSSCORRELATIONS. VARY H IF NEEDED
4.DO NOT USE THE DEFAULT DIVIDERAND; IT DESTROYS CORRELATIONS
5. INITIALIZE THE RNG SO THAT RUNS CAN BE DUPLICATED
6. NORMALIZE THE MSE WITH THE AVERAGE TARGET VARIANCE AND
OBTAIN THE COEFFICIENT OF DETERMINATION R^2 (See Wikipedia)
7. CAN OBTAIN INDIVIDUAL TRN/VAL/TST STATS FROM TR
==> 8. WHEN CREATING NEW SERIES, USE MATRIX INDEXING INSTEAD OF
VECTOR INDEXING
9. TRY THE 8-INPUT/3-OUTPUT POLLUTION_DATASET. I GET R2 = 0.72 on
all of the data (508 timesteps) using your parameter settings (1:1, 1:1, 16,
0.7 / 0.15 / 0.15 ) on 356 timesteps.
10. Will next implement some of the above suggestions.
Hope this helps.
Thank you for formally accepting my answer
Greg
  3 Comments
Greg Heath
Greg Heath on 10 Feb 2013
Edited: Greg Heath on 10 Feb 2013
1. Run your original data through netc.
2. When you create the new series, use matrix indexing instead of vector indexing.
3. Put cell series, not matrix series into preparets.
4. If you still have problems, we can compare numbers on the pollution_dataset.
5. Note that the pollution data set has 3 outputs.
6. Don't forget to accept my answer (;>)
FRANCISCO
FRANCISCO on 11 Feb 2013
Thank you very much. I've gone a step further and simulate the network've known. It was a problem in netc sizing. Now I propose to improve the accuracy of the network and ask for help when you do not understand something. Thank you very much.

Sign in to comment.

More Answers (0)

Categories

Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!