具体请参考:http://lab.fs.uni-lj.si/lasin/wp/IMIT_files/neural/nn05_narnet/
神经网络预测时间序列数据,有三种模型,
这里是给出的是第二种NAR,即只有时间序列数据y(t),没有x(t)。具体训练和预测matlab代码如下:
format compact % data settings N = 249; % number of samples Nu = 224; % number of learning samples y = Data;% Input your data % prepare training data yt = con2seq(y(1:Nu)'); % prepare test data yv = con2seq(y(Nu+1:end)'); % Choose a Training Function % For a list of all training functions type: help nntrain % 'trainlm' is usually fastest. % 'trainbr' takes longer but may be better for challenging problems. % 'trainscg' uses less memory. NTSTOOL falls back to this in low memory situations. trainFcn = 'trainlm'; % Levenberg-Marquardt % Create a Nonlinear Autoregressive Network feedbackDelays = 1:5; hiddenLayerSize = 40; net = narnet(feedbackDelays,hiddenLayerSize,'open',trainFcn); [Xs,Xi,Ai,Ts] = preparets(net,{},{},yt); % train net with prepared training data net = train(net,Xs,Ts,Xi,Ai); % view trained net % close feedback for recursive prediction net = closeloop(net); % view closeloop version of a net view(net); %%%Recursive prediction on test data % prepare test data for network simulation yini = yt(end-max(feedbackDelays)+1:end); % initial values from training data % combine initial values and test data 'yv' [Xs,Xi,Ai] = preparets(net,{},{},[yini yv]);