example26.m

来自「是一个用MATLAB编的一个系统」· M 代码 · 共 40 行

M
40
字号
%
%==============
%==============
figure('name','训练过程图示','numbertitle','off');

P=[1 1.5 1.2 -0.3; -1 2 3 -0.5; 2 1 -1.6 0.9];
T=[0.5 3 -2.2 1.4; 1.1 -1.2 1.7 -0.4; 3 0.2 -1.8 -0.4; -1 0.1 -1.0 0.6];

disp_freq=5;
max_epoch=str2num(max_epoch);
err_goal=str2num(err_goal);
lr=0.9*maxlinlr(P);

[R,Q]=size(P);
[S,Q]=size(T);
W=rands(S,R);
B=rands(S,1);
%calculate the error
SSE=sumsqr(T-purelin(W*P,B));
fprintf('Before training ,sum squared error=%g.\n',SSE)

%train the network
flops(0);

tp=[disp_freq  max_epoch  err_goal  lr];
[W,B,epochs,errors]=trainwh(W,B,P,T,tp);
W;B;
SSE= sumsqr(T-purelin(W*P,B));

%show the results and the conclusions
ploterr(errors);
fprintf('\n After %0f epochs,sum squared error=%g.\n\n',epochs,SSE);
fprintf('Training took %0f flops.\n',flops);
fprintf('Trained network operates:');
if SSE < err_goal
   disp('Adequately.')
else
   disp('Inadequately.')
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?