Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Neural Network Times Series ahead prediction in Matlab, how to build input and output data
Replies: 4   Last Post: Dec 9, 2013 7:13 PM

 Messages: [ Previous | Next ]
 Greg Heath Posts: 6,387 Registered: 12/7/04
Re: Neural Network Times Series ahead prediction in Matlab, how to build input and output data
Posted: Dec 7, 2013 6:10 PM

"Alper Alimoglu" <aalimog1@binghamton.edu> wrote in message <l7u7ca\$qef\$1@newscl01ah.mathworks.com>...
> 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:
> [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?
>
>
> **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('MYDATA.txt'); %//sequence of numbers as time series.
> 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);
>
> %% 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')
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I recall answering this. Did you submit the same question to ANSWERS?

IF SO, BAD MOVE!

Date Subject Author
12/6/13 Alper Alimoglu
12/7/13 Greg Heath
12/9/13 Alper Alimoglu
12/9/13 Alper Alimoglu
12/9/13 Greg Heath