This is a question about time series forecasting

2 views (last 30 days)
Hello everybody! this is my code, I don't know what's wrong with it! Would anyone help me ? Thank you!
% Solve an Autoregression Time-Series Problem with a NAR Neural Network
% Script generated by NTSTOOL
% Created Fri Mar 15 22:09:23 CST 2013
%
% This script assumes this variable is defined:
%
% Data - feedback time series.
targetSeries = tonndata(Data,false,false);
% Create a Elman neural Network
feedbackDelays = 1:7;
hiddenLayerSize = 5;
net = elmannet(feedbackDelays,hiddenLayerSize,'trainlm');
% Choose Feedback Pre/Post-Processing Functions
% Settings for feedback input are automatically applied to feedback output
% For a list of all processing functions type: help nnprocess
net.inputs{1}.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,targetSeries,targetSeries);
% Setup Division of Data for Training, Validation, Testing
% For a list of all data division functions type: help nndivide
net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'time'; % 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
net.trainFcn = 'trainlm'; % Levenberg-Marquardt
% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
net.performFcn = 'mse'; % Mean squared error
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
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 = 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)
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%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);
[xc,xic,aic,tc] = preparets(netc,targetSeries,targetSeries);
yc = netc(xc,xic,aic);
perfc = perform(net,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);
[xs,xis,ais,ts] = preparets(nets,targetSeries,{},targetSeries);
ys = nets(xs,xis,ais);
closedLoopPerformance = perform(net,tc,yc);
Now I will show you the warning of matlab software!
Error using removedelay (line 57)
Removing 1 to input delays would result in a negative input weight delay.
Error in elman (line 95)
nets = removedelay(netc);
Could anyone help me ?
  3 Comments
li
li on 19 Mar 2013
Edited: li on 19 Mar 2013
I think we should use the solar_dataset.My goal is to use Elman neural network to predict.There are 3 datasets. These are the Wolfs sunspots, the daily closing price of S & P 500 index and the exchange rates between US Dollar (USD) and Indian Rupee (INR) time series. These time series are obtained from the Time Series Data Library (TSDL) [18], the Yahoo! Finance [19] and the Pacific FX database [20], respectively and are described in Table 1. The natural logarithms of the S & P data are used in our analysis. Thanks for your help ! I will diliver the sunspots dataset to you!
Greg Heath
Greg Heath on 22 Mar 2013
MATLAB'S solar_data set has no input. Therefore it is not suitable for use with timedelaynet, elmannet or narxnet.

Sign in to comment.

Accepted Answer

Greg Heath
Greg Heath on 21 Mar 2013
1. Why are you using elmannet instead of narnet? Didn't you read the warning and recommendation in the elmannet documentation?
2. Did you determine FD = 1:7 from the autocorrelation function?
3. Did you determine H = 5 to avoid overfitting?
4. Why did you waste time and space explicitly specifying network defaults?
5. Why did you choose/accept the data division function 'dividerand' that destroys all correlations on which a lagged network depends?
6. After training the net you can avoid calculating most of what follows because it is already available in the training recored tr. Enter, without semicolon,
tr = tr
What is not there that you feel you have to calculate?
7. How did the training terminate? What is the coefficient of determination for the different trn/val/tst data divisions?
8. How many random weight intialization trials did you have for H = 5?
9. Did you try other values of H?
I'm not confident that 'dividerand' can give you the stability you need for using the closedloop configuration on test data.
Greg
  3 Comments
Greg Heath
Greg Heath on 21 Mar 2013
1. That doesn't answer the question. MATLAB says that Elman is inferior to Narxnet. So why use Elman if it is inferior?
4.It would be appreciated if you did not include assignments of default values.
5. It also makes life easier if you write and debug your code using one of the MATLAB nndatasets.
It is probably worthwhile to search in the NEWSGROUP and ANSWERS for what has been posted re narxnet, timedelaynnet and/or narnet. At this point, it may be more helpful than reading book theory.
Greg Heath
Greg Heath on 22 Mar 2013
2. The feedback is from the hidden layer, not the output. ALSO, the input is not delayed. Therefore, NEITHER the target autocorrelation function NOR the target/input crosscorrelation function are reliable for predicting significant delays.
Because of this and the approximate way that the elmannet is trained, I would take the advice of the documentation and use narxnet.
Afterwards, for curiosity sake, I would come back to Elman.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!