Neural Network Times Series ahead prediction in Matlab, how to build input and output data

4 visualizaciones (últimos 30 días)
My goal is to predict N steps ahead with neuaral network in matlab. In order to do that first I train some part of the data and use trained values to predict the future behavior of it.
My question is based on Neural Network Times Series prediction on matlab. I was confused on how should I separate my Input and Output data and based on the difference between feedbackDelays and inputDelays.
As an Example: My Data is: [values are actually index values within the data] [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] And I want to predict 5 point ahead of each 10 input which is:
[1,2,3,4,5,6,7,8,9,10] => [15]
[2,3,4,5,6,7,8,9,10,11] => [16]
[3,4,5,6,7,8,9,10,11,12] => [17]
and so on...
Matlab isn't like octave, I won't able to see the and analysis the Input data set and double check. In order to to this, how should my following code should be for function narxnet:
**delay** = 5; % //Does delay means number of input??
neuronsHiddenLayer = 50;
% Network Creation
net = narxnet(1:delay,1:delay,neuronsHiddenLayer); %=> Does is really do what I want to do as I decribed on above.
=====
X = S(1:length(S)-N); T = S(N:length(S));
for example length(S) is 5 X = [1,2,3,4,5] T = [6,7,8,9,10,11,12 ...]
I want to do that from the data of X if my input is *3*:
[1,2,3] => [6] //first data of T which is my output
[2,3,4] => [7] //second data of T which is from my output
=> On my code did I able to perform this solution, if not what should I do to achieve this solution?
=>If my output are in between [0-100], it predicts beyond that, larger values than 100, how it possible? I couldn't find where I make mistakes...
*My code:* My code come ups with a solution but I am not sure that it build the input and output values as I described above.
S = load('newDataSet.txt'); %//sequence of numbers as time series.(attached)
N = 5; %//5 points ahead will be predicted
X = S(1:length(S)-N); %//I think that it separates my input and output
T = S(N:length(S));
X = X';
T = T';
X = num2cell(X);
T = num2cell(T);
%%2. Data preparation
% 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:length(X)-N);
targetSeries = T(1:length(X)-N);
% 2nd 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 = X(length(X)-N+1:length(X));
targetSeriesVal = T(length(X)-N+1:length(X)); % This is generally not available
%%3. Network Architecture
delay = 5;
neuronsHiddenLayer = 50;
% Network Creation
net = narxnet(1:delay,1:1,neuronsHiddenLayer); *%1:1 correct for 1 output?*
%%4. Training the network
[Xs,Xi,Ai,Ts] = preparets(net,inputSeries,{},targetSeries);
net = train(net,Xs,Ts,Xi,Ai);
view(net);
Y = 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
inputSeriesPred = [inputSeries(end-delay+1:end),inputSeriesVal];
targetSeriesPred = [targetSeries(end-delay+1:end), con2seq(nan(1,N))];
netc = closeloop(net);
view(netc);
[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')

Respuesta aceptada

Greg Heath
Greg Heath el 8 de Dic. de 2013
Perhaps you did not understand me:
I do not understand what you want.
An example using a MATLAB data would clarify the issue.
However, since you have submitted a single series example, there is only one function to use:
help narnet
doc narnet
A selection of effective feedback delays can be obtained from the significant values of the series autocorrelation function. For examples search using
greg nncorr
Thank you for formally accepting my answer
Greg
  1 comentario
Avatar@ Wonderland
Avatar@ Wonderland el 8 de Dic. de 2013
Thank you for your answer.
My goal is to come up with a predictor that will able to predict (N) points ahead on my Single Series of data.In order to do that as I learned neural networks I need to train inputs by N point ahead of output. I have done it manually in octave to achieve this solution but I couldn't had a good result so I am trying to do it under matlab with it's functions that why they are new to me.
I couldn't solve and understand the way that how can I achieve the following situation. if I want to train my data as: (t is the time)
[t] [t+1] [t+2] [t+3] => [t+3+N]
[t+1] [t+2] [t+3] [t+4] => [t+4+N]
how can I achieve this with NARX or as you recommended narnet. please help me to figure out this situation. I have search your recommendations but they are like a black box to me to figure out how matlab's narnet function maintains the input and output's, and how can I force function to do what I want to do as I decribed above.
Thanks for further assistance.

Iniciar sesión para comentar.

Más respuestas (1)

Greg Heath
Greg Heath el 7 de Dic. de 2013
Editada: Greg Heath el 7 de Dic. de 2013
This is a poor data set for a realistic time-series example. Find a more appropriate example and code using
help nndatasets
doc nndatasets
help narxnet (or timedelaynet or narnet)
doc narxnet
Notice that there are various multi-dimensional examples for each of the three types of time-series.
If you have problems, post relevant code with comments and error messages.
Thank you for formally accepting my answer
Greg
P.S. Search for relevant code using
greg nncorr
  4 comentarios
Greg Heath
Greg Heath el 14 de Abr. de 2014
The amount of time that you can predict ahead is limited by the length of the significant autocorrelation lags. If they are [ 1 3 5 7] and you want to predict 21 steps ahead it might be possible by using a multi-step closed loop approach.
So, your 1st task is to find the significant lags.
Greg Heath
Greg Heath el 25 de Mzo. de 2016
Editada: Greg Heath el 25 de Mzo. de 2016
IMPORTANT POINT:
All of the time series documentation uses default delays ID=1:2 and/or FD=1:2 with H = 10.
However, this is just a guess that it is a good place to start your search for a successful design. Personally, I would add 0 to ID (FD=0 is not allowed in a CL design);
For serious work you have to look at the significant correlation lengths. It is very unlikely that you can confidently predict beyond the longest SCL.
Hope this helps.
Greg

Iniciar sesión para comentar.

Categorías

Más información sobre Sequence and Numeric Feature Data Workflows en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by