请高手帮忙!!关于BP实现
<P>为什么我编的程序运算速度刚刚开始还可以 但是到了后面的速度就比较慢了?<BR><BR>谢谢帮忙!!!<BR><BR>clear<BR>% clc<BR>tic<BR>PP =;<BR>TT = ;<BR>HiddenUnitNum = 2;<BR> = size(PP);<BR> = size(TT);<BR>SamIn=PP;<BR>SamOut=TT;</P><P>MaxEpochs=30000;<BR>lr=0.5;<BR>E0=0.001;<BR>TotalEpochs = 0;</P>
<P>for n = 0:29<BR>%rand('seed',1);<BR>%rand('state',sum(100*clock));<BR>W1=0.6*rand(HiddenUnitNum,InDim)-0.3; %初始化权值[-0.3,0.3]<BR>B1=0.6*rand(HiddenUnitNum,1)-0.3;<BR>W2=0.6*rand(OutDim,HiddenUnitNum)-0.3;<BR>B2=0.6*rand(OutDim,1)-0.3;<BR>W1Ex=;<BR>W2Ex=;<BR>w1=0; %<BR>w2=0;<BR>alpha=0.7;% I_H权值的动量因子<BR>beta=0.7; %H_O权值的动量因子</P>
<P>SamInEx='; % 扩展输入矩阵<BR>ErrHistory=[];</P>
<P>for i=1:MaxEpochs <BR> HiddenOut=logsig(W1Ex*SamInEx);%隐层输出<BR> HiddenOutEx=';<BR> NetworkOut=logsig(W2Ex*HiddenOutEx); % 输出层输出<BR> Error=SamOut-NetworkOut; % 误差<BR> SSE=(1/(2*SamNum))*sumsqr(Error); % sumsqr(): Sum squared elements of a matrix <BR> ErrHistory=;<BR> if SSE<E0,break,end<BR> <BR> %Delta2=Error; %%<BR> Delta2 = Error.*NetworkOut.*(1-NetworkOut); %%隐层神经元的误差信号<BR> Delta1=W2'*Delta2.*HiddenOut.*(1-HiddenOut); %% <BR> dW2Ex=Delta2*HiddenOutEx'; % 调整量<BR> dW1Ex=Delta1*SamInEx';<BR>% %%%%%%%%%%%%%标准BP算法%%%%%%%%%%%<BR>% W1Ex=W1Ex+lr*dW1Ex;<BR>% W2Ex=W2Ex+lr*dW2Ex;<BR> %%%%%%%%%%%%%%%%%%%%加入动量项的BP算法%%%%%%%%%%%<BR> a=W1Ex;<BR> b=W2Ex;<BR> W1Ex=W1Ex+lr*dW1Ex+alpha*w1;<BR> W2Ex=W2Ex+lr*dW2Ex+beta*w2;<BR> w1=W1Ex-a;<BR> w2=W2Ex-b;<BR> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%<BR>%W2=W2Ex(:,1:HiddenUnitNum);<BR> %%W1=W1Ex(:,1:InDim);<BR>end<BR> TotalEpochs =TotalEpochs + i;%TotalEpochs=TotalEpochs+1; <BR>end</P>
<P>% 输出结果<BR>AverageEpochs = TotalEpochs/30<BR>W1=W1Ex(:,1:InDim)<BR>B1=W1Ex(:,InDim+1)<BR>W2=W2Ex(:,1:HiddenUnitNum)<BR>B2=W2Ex(:,1+HiddenUnitNum)</P>
<P>=size(ErrHistory);<BR>plot(1:Num,ErrHistory,'k--');<BR>title('训练误差')<BR>toc </P>
回复:(akyi)请高手帮忙!!关于BP实现
什么叫做刚开始还可以,到后来就慢了,请说的具体点
页:
[1]