MATLAB: Neural Net: Saving Trained Net

MATLABnarxnarxnetneural net tool box

I will explain my problem. My code is given below.
% ********************* Plant ************************
s = 5000; u = zeros(1, s);
y = zeros(1, s); yhat = zeros(1, s);
for k=1:s
u(k)= unifrnd(-1,1);
if (k==1),
y(k)=0;
elseif (k==2),
y(k)=0.3*y(k-1)+u(k)+0.3*u(k);
else
y(k)=0.3*y(k-1)+0.6*y(k-2)+u(k)+0.3*u(k);
end
end
% **************** NN Modelling ********************* % Creating Neural Net
[yn,ys] = mapminmax(y);
net = newcf( u, yn, [20 10 ], 'tansig', 'tansig',...
'purelin'},'trainscg');
% Training Neural Net
net.trainParam.lr = 0.05; net.trainParam.lr_inc =1.05;
net.trainParam.lr_dec = 0.7; net.trainParam.hide = 50;
net.trainParam.mc = 0.9; net.trainParam.epochs = s;
net.trainParam.goal = 1e-5; net.trainParam.max_fail = s;
net.trainParam.time = 3*3600; trainInd = 1:1:s;
valInd = 2:50:s; testInd = 3:50:s;
[trainu,valu,testu] = divideind,u,trainInd,valInd,testInd);
[trainy,valy,testy] = divideind(yn,trainInd,valInd,testInd);
net = init(net); net = train(net,u,yn);
The actual problem is different. The above program is written in an m-file and takes about 15 minutes to converge. Can you go through the program and tell me if I am correct in programming? I wish to use this net for another set of inputs. For this, I need to access the trained net. How the trained net is saved external to this m file and how to access it? Please help. Thanks in advance.

Best Answer

I am not sure why you used a cascade forward net. That net has no feedack loops.
The generating equations indicate that a narxnet is more appropriate.
Is u(k)+ *0.3*u(k) a misprint? Should the latter be u(k-1)?
When you change to a narxnet, check the significant values (>0.21) of the crosscorrelation function nncorr(U,Y,N-1)and the autocorrelation function nncorr(Y,Y,N-1) to determine good values for the delays. The capitals indicate zscore transformations (i.e., U = zscore(u), etc).
Also change the divide function from dividerand (destroys u-y and y-y correlations) to either 'divideblock' or another choice.
As for your CFnet, you have 2 hidden layers with 30 nodes resulting in Nw = (1+1)*20+(20+1)*10+(10+1)*1 = 261 weights. A narxnet will probably need fewer hidden nodes and weights.
Hope this helps.
Thank you for accepting my answer.
Greg