From: david on 26 Mar 2010 12:42 Hello all, Does anyone use the NNSYSID neural networks toolbox for time series prediction ? i have a problem about how to use the data of time series in the model NNAR (the function nnarx in NNSYSID) . where the output lag is 4 ,this means that y(t) =f( y(t-1),y(t-2),y(t-3),y(t-4) ). and the time series data that i will use for training y1 and for the test y2 i write the program as following; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% y1=[60;80;100;40;0;140;40;40;100;40;140;200;340;200;320;140;180;120;380;600;680;500;1040;1520;1560;1940;4340;4880;3900;4000;3480;3200;2020;2040;2460;1740;2080;2240;2000;1980;1760;1730;2440;3460;3620;2060;1800;2120;2020;3920;3820;4260;2940;2400;2680;2300;2080;2460;2580]; y2=[2640;2780;2720;3040;3660;3740;3580;3720;3060;3140;2500;2600;1940;1800;1800;1480;1240;1420;1440;1040;800;310;380;460;620;720;580;300;340;420;260;80;280]; y1=y1'; y2=y2'; subplot(211), plot(y1) title('training sequence') subplot(212), plot(y2) title('test sequence') subplot(111) %% First the training set is scaled to zero mean and variance one and then the test % set is scaled with the same constants: [y1s,yscales] = dscale(y1); y2s = dscale(y2,yscales); % -------------------------------------- % Choose a Nonlinear Model Structure % -------------------------------------- %% Initially a fully connected network architecture with 10 hidden hyperbolic tangent units is selected: %% Define the model structure: forth order model and 10 tanh units in hidden layer: NetDef = ['HHHHHHHHHH';'L---------']; NN =4; %% The network now has to be trained. Let the function initialize the weights, try max. 300 iterations %% and use a small weight decay. Select the field skip to 10 to reduce the influence of the unknown %% initial conditions: trparms = settrain; trparms = settrain(trparms,'maxiter',300,'D',1e-3,'skip',10); [W1,W2,NSSEvec]=nnarx(NetDef,NN,[],[],trparms,y1s); % ------------------------------------------- % Validation of the trained network % ------------------------------------------- %% The function nnvalid is called to validate the generated NNOE-model. First the validation is %% performed on the training set (only the comparison plot is shown here): [w1,w2] = wrescale('nnarx',W1,W2,[],yscales,NN); % Rescale the weights [yhat,NSSE] = nnvalid('nnarx',NetDef,NN,w1,w2,y1,[]); [yhat,NSSE] = nnvalid('nnarx',NetDef,NN,w1,w2,y2,[]); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% is this code true or there is an error on how to introduce the training data and test data with nnarx model ? thanks in advance David
|
Pages: 1 Prev: Function definition in a script. Next: Resizing images pasted into Word using activex |