Interruption in the plotted data

Hi all,
I use a neural network toolbox to predict the values of the last week in the used data year. When I plot the figure, the Interruption in the plotted data are appearing! Knowing that, the data are interpolated and there is no NaN in it.
SEE the attached figure
Please anyone can help I will appreciate it. Thank you

 Respuesta aceptada

Walter Roberson
Walter Roberson el 5 de Dic. de 2015
Editada: Walter Roberson el 5 de Dic. de 2015
I loaded the figure and examined the data, and there certainly are NaN in it.
h = openfig('predicted.fig');
L = findobj(h, 'type', 'line');
L7y = get(L(7), 'YData');
find(~isnan(L7y(1:8594))
ans =
8594
In other words, the first 8593 Y values of Expected Outputs are NaN and position 8594 is the first non-NaN. The same holds true for L(8), Network Predictions. The data for L(9), Original Targets, on the other hand, is valid only up to point 8593, and is NaN from 8594 onwards.
With the last non-NAN point from the left being 8593 and the first non-NaN point from the right being 8594, you will have a gap between 8593 and 8594, exactly like you are seeing.

15 comentarios

Lilya
Lilya el 5 de Dic. de 2015
In the original data there are no NaN values, it's only appeared after plotting. Here is the part of code which contain the problem
inputSeriesVal = X(end-N+1:end);
targetSeriesVal = T(end-N+1:end);
%%3. Network Architecture
delay = 3;
neuronsHiddenLayer = 30;
% Create a Nonlinear Autoregressive Network with External Input
% net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize);
net = narxnet(1:delay,1:delay,neuronsHiddenLayer);
%%4. Training the network
[Xs,Xi,Ai,Ts] = preparets(net,inputSeries,{},targetSeries);
net = train(net,Xs,Ts,Xi,Ai);
view(net)
[Y,xf,af] = net(Xs,Xi,Ai);
% Performance for the series-parallel implementation, only
% one-step-ahead prediction
perf = perform(net,Ts,Y);
%%5. Multi-step ahead prediction
[netc,xi,ai] = closeloop(net,xf,af);
[yPred,xf,af] = netc(inputSeriesVal,xi,ai);
view(netc)
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')
Look at your plot call:
plot([cell2mat(targetSeries),nan(1,N);
nan(1,length(targetSeries)),cell2mat(yPred);
nan(1,length(targetSeries)),cell2mat(targetSeriesVal)]')
You use nan in the first line, nan in the second line, nan in the third line. You are adding the NaN. And NaN are not plotted.
In the first of those lines, you have length(targetSeries) valid data points and then N Nan. In the second line, you have length(targetSeries) Nan and then N data points. In order for there to be no gap, you would need overlap
XXXX000
0000XXX
To get a line with no gap you would need
XXXXX00
0000XXX
or
XXXX000
000XXXX
some position at which there is non-NaN data for both rows.
Lilya
Lilya el 5 de Dic. de 2015
I tried to solve it, but I can't :( How can I change the plotting commands to avoid this?
Thank you Mr. Roberson
You can get it to draw the line connections, but they will not be valid line connections unless you ask it to predict the value at length(targetSeries)
Suppose I gave you data for points 1, 2, 3, and 4, and asked you to predict points 5 and 6, and then I drew a line through points 1 through 4 (the known) and I drew a line through points 5 and 6 (what you predicted) and then I complained that there is no line between points 4 and points 5. But I never asked you to predict anything between 4 and 5, so there is no data for that line to work with. I would have to give you points 1, 2, 3, and 4 and ask you to predict points 4, 5, and 6 in order to validly draw a line from 1 through 4 and a line from 4 through 6. (Of course if your prediction of those known values is not the same as the actual values, there may be a visual gap anyhow...)
You will find it easier if you change the way you are plotting.
ntarg = length(targetSeries);
plot(1:ntarg, mat2cell(targetSeries), ...
ntarg : length(X), cell2mat(yPred_2), ...
ntarg : length(X), cell2mat(targetSeriesVal_2) );
Here yPred_2 is like your current yPred except that it would have to be formed starting from x(ntarg) instead of from x(ntarg+1) like it is at present (that is, you need to ask to predict an existing value.) Likewise targetSeriesVal_2 would be starting from T(ntarg) instead of from T(ntarg+1) -- one value overlapping.
Lilya
Lilya el 6 de Dic. de 2015
Thank you very much Roberson. But It is still a problem in dim. The first line in the plot command is working, but the others it did not.
Walter Roberson
Walter Roberson el 6 de Dic. de 2015
Did you create yPred_2 as starting from a pointer earlier than you used to start it?
What is length(X), length(targetSeries), size(yPred_2), size(targetSeriesVal_2) ?
Lilya
Lilya el 6 de Dic. de 2015
yes I am. I actully did
yPred_2=cell2mat(yPred)-1;
targetSeriesVal_2=cell2mat(targetSeriesVal)+1;
figure;
ntarg = length(targetSeries);
plot(1:ntarg, cell2mat(targetSeries), ...
ntarg : length(X), yPred_2, ...
ntarg : length(X), targetSeriesVal_2 );
Going back to basics:
I question your choice of delays and number of hidden nodes.
Why 1:3, 1:3, 30 ???
Did you try your NARXNET code on
[ X T ] = simpleseries_dataset;
Search
greg narxnet
Like this: notice the change to start the prediction data from exactly 1 point earlier than you had before
inputSeriesVal = X(end-N+0:end); %CHANGED
targetSeriesVal = T(end-N+0:end); %CHANGED
%%3. Network Architecture
delay = 3;
neuronsHiddenLayer = 30;
% Create a Nonlinear Autoregressive Network with External Input
% net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize);
net = narxnet(1:delay,1:delay,neuronsHiddenLayer);
%%4. Training the network
[Xs,Xi,Ai,Ts] = preparets(net,inputSeries,{},targetSeries);
net = train(net,Xs,Ts,Xi,Ai);
view(net)
[Y,xf,af] = net(Xs,Xi,Ai);
% Performance for the series-parallel implementation, only
% one-step-ahead prediction
perf = perform(net,Ts,Y);
%%5. Multi-step ahead prediction
[netc,xi,ai] = closeloop(net,xf,af);
[yPred,xf,af] = netc(inputSeriesVal,xi,ai);
view(netc)
figure;
ntarg = length(targetSeries);
plot(1:ntarg, mat2cell(targetSeries), ...
ntarg : length(X), cell2mat(yPred), ...
ntarg : length(X), cell2mat(targetSeriesVal) );
legend('Original Targets','Network Predictions','Expected Outputs')
Lilya
Lilya el 6 de Dic. de 2015
THANK YOU AS A HUGE UNIVERSE :'(
Lilya
Lilya el 7 de Dic. de 2015
Dr. Heath, I see the NARXNET examples. The best result I had gotten when the number of HN =30. Is it right?
Greg Heath
Greg Heath el 7 de Dic. de 2015
Editada: Greg Heath el 7 de Dic. de 2015
It does not predict as desired. It would help if you posted all code and results using the simpleseries_dataset.
I recommend starting a new thread for this because it is a separate problem.
Greg
Lilya
Lilya el 8 de Dic. de 2015
Dr. Heath, according to simpleseries_dataset code there is a difference between it and NAREXNET. Is it in the coding or in the implementation of the function itself?
Walter Roberson
Walter Roberson el 8 de Dic. de 2015
Please start a new question.
Lilya
Lilya el 8 de Dic. de 2015
I apologize

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Deep Learning Toolbox en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 5 de Dic. de 2015

Comentada:

el 8 de Dic. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by