Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



CLOSELOOP FEEDBACK TIMESERIES DESIGN EXAMPLE
Posted:
Apr 2, 2013 4:07 AM


% 1234567890123456789012345678901234567890123456789012345 % This design uses as many defaults as possible. In general, % 1. The input delay vector, ID, should be chosen from the significant % T/X crosscorrelation lags of the training set . For regression, include % ID = 0. For prediction, ID > 0. The default value is ID = [ 1:2 ] (prediction) % 2. The output feedback delay vector FD > 0 should be chosen from % the significant autocorrelation lags of the training targets. The default % value is FD = [ 1:2 ] % 3. The number of hidden nodes, H, should be obtained by trial and % error. The optimum value is the smallest one that achieves the % specified error goal. When searching for Hopt, start with the range % 0<= H <= Hub that results in the number of unknown weights, Nw, % being less than the number of training equations, Ntrneq. The default % value is H = 10. If H > Hub, Nw > Ntrneq, and the net is OVERFIT. % There are several mitigation methods to prevent the overfit net from % being OVERTRAINED and memorizing the training data so closely % that the net performs poorly on nontraining data. The default method % is "Validation set stopping" where the error of a nontraining validation % set is monitored. Training is stopped if the validation error reaches a % minimum before the training set error reaches the specified goal. % 4. Closeloop training with feedack delays can be very time consuming. % As an alternative, an openloop design is obtained first by replacing the % feedback connection with an extra input that contains target values. % When the openloop design is satisfactory, the extra input is connected % to the output to form the closeloop configuration. If the closeloop % configuration does not perform as well as the openloop configuration, % it can be trained further. Initializing the closeloop configuration with the % openloop design saves a considerable amount of time; especially when % a search for Hopt is needed. % 5. There are 8 timeseries data sets that are available for experimentation % via the command help nndatasets. You can also linearly combine data % sets if you need more fun.
clear all, close all, clc tic [ X, T ] = simplenarx_dataset; [I N ] = size(X) [O N ] = size(T) Ntrn = N2*round(0.15*N) % default 0.7/0.15/0.15 trn/val/tst ratios trnind = 1:Ntrn; Ttrn = T(trnind); Ntrneq = prod(size(Ttrn))
%ID = 1:2 %default for Prediction ID = 0:2 % Regression FD = 1:2 % default NID = length(ID) NFD = length(FD) LDB = max([ID,FD]) % Length of the delay buffer Hub = 1 + ceil( (NtrneqO) / (NID*I + NFD*O+1)) H =5 % <= Hub (default is H = 10) Nw = (NID*I+NFD*O)*H +(H+1)*O
%THE OPENLOOP DESIGN AND PERFORMANCE
net = narxnet(ID,FD,H); net.divideFcn = 'divideblock'; % Overrides the default 'dividerand' [ Xs Xi Ai Ts] = preparets( net, X, {},T ); [net tr Ys Es Xf Af ] = train(net,Xs,Ts,Xi,Ai); view(net) whos Xs Ts Xi Ai Ys Es Xf Af ts = cell2mat(Ts); ys = cell2mat(Ys); figure(1) hold on plot(ts, 'k') plot(ys,'b')
%% THE CLOSELOOP DESIGN AND PERFORMANCE
netc = closeloop(net); view(netc) [ Xsc Xic Aic Ts] = preparets( netc, X, {},T ); ysc1 = cell2mat(netc(Xsc,Xic,Aic)); figure(2) hold on plot(ts,'k') plot(ysc1,'g') [ netc trc Ysc2 Esc2 Xfc Afc ] = train(netc, Xsc,Ts,Xic,Aic); ysc2 = cell2mat(Ysc2); figure(3) hold on plot(ts, 'k') plot(ysc2,'r') trc = trc toc
Have fun with the other nndatasets.
Greg



