MATLAB: Problem in training the feed-forward network.

Deep Learning Toolboxneural networks

Using 'simout' options in my simulink model, I saved the input and output data in workspace, which were then called in my program. The input and output are matrix of dimensions "3988*1 double"
My MATLAB program is as follows:
————
load input
load output
p=input';
t=output';
net=newff(10,30, [10,1], {'tansig', 'purelin'}, 'traingd')
net.trainParam.show=50;
net.trainParam.epochs=1000;
net.trainParam.lr=0.05;
net.trainParam.goal=1e-3;
net1=train(net,p,t)
—————–
Everytime I run this program, the following error is generated.
??? Error using ==> plus
Matrix dimensions must agree.
Error in ==> calcperf2 at 163
N{i,ts} = N{i,ts} + Z{k};
Error in ==> trainlm at 253
[perf,El,trainV.Y,Ac,N,Zb,Zi,Zl]= calcperf2(net,X,trainV.Pd,trainV.Tl,trainV.Ai,Q,TS);
Error in ==> network.train at 216
[net,tr] = feval(net.trainFcn,net,tr,trainV,valV,testV);
Error in ==> Ann1 at 16
net1=train(net,p,t);
>>
—–
But I don't understand, How to debug it. Kindly help.

Best Answer

load input
load output
p=input';
t=output';
[ I N } = size(p) % [ 1 3988 ]
[ O N } = size(t) % [ 1 3988 ]
Neq = N*O % No. of training equations
H = 10 % trial No. of hidden nodes for I-H-O node topology
Nw =(I+1)*H+(H+1)*O % 31 = No. of unknown weights to estimate from Neq =3998 eqs.
Ndof = Neq-Nw % No. of estimation DOF (degrees of freedom, (see Wikipedia))
% Since Neq/Nw ~ 128 >> 10, do not need validation data.
Ntrn = N
Ntrneq = Neq
MSEtrn00 = mean(var(t',1)) % Biased Reference MSEtrn
MSEtrn00a = mean(var(t',0)) % Unbiased Reference: DOF "a"djusted
% Choose one depending on your version of NNTBX:
%net = newff(minmax(p),[ H O ]); % VERY OBSOLETE
%net = newfit(p, t, H); % OBSOLETE
net = fitnet(H); net = configure(net,p,t); % CURRENT
MSEgoal = 0.01*Ndof*MSEtrn00a/Ntrneq % R2agoal = 0.99
net.trainParam.goal= MSEgoal;
net.trainParam.min_grad = MSEtrn00/200;
net.divideFcn = '';
[ net tr Y E ] = train(net,p,t);
stopcrit = tr.stop
bestepoch = tr.best_epoch
MSEtrn = tr.perf(bestepoch)
MSEtrna = Ntrneq*MSEtrn/Ndof
NMSEtrn = MSEtrn/MSEtrn00
NMSEtrna = MSEtrna/MSEtrn00a
R2 = 1 -NMSE % ( R^2 = coefficient of determination ... See Wikipedia)
R2a = 1 - NMSEa % ( DOFA R^2)
If you are not satisfied with the R2a estimate of the fraction of target variance that is modeled, change H.
Hope this helps.
Thank you for formally accepting my answer
Greg
P.S. It is worthwhile to study the results of the following commands (no semocolon)
net = net
tr = tr