⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adaptlr.m

📁 新的神经网络算法源程序
💻 M
字号:
function [t,d,w,c,b,SSE] = adaptlr(x,y,t,d,w,c,b, SSE)%Adaptlr: Adaptive learning rate%%	[t,d,w,c,b,SSE] = adaptlr(x,y,t,d,w,c,b, SSE)%%	By Qinghua Zhang. April 10, 1992.%First call. updatewn returns hessien and gradient only for the first calllr = 0;[t_tmp,d_tmp,w_tmp,c_tmp,b_tmp, hess_t, hess_d, dt, dd] ...		 			= updatewn(x,y,t,d,w,c,b,lr);if length(b_tmp) > 0 		% not bad matrix condition g = wavenet(x,t_tmp,d_tmp,w_tmp,c_tmp,b_tmp); E = y-g; SSE_current = sum(E .* E); %Sum of Squared Errors if SSE_current <= SSE % Good step   t = t_tmp; d = d_tmp; w = w_tmp; c = c_tmp; b = b_tmp;   SSE = SSE_current;   return; endend% A bad step was made, then go on!!%==================================lr = 0.1; % start value for Learning Rateinc_dec = 0; % set indicator for increase or decrease  lrwhile 1  [t_tmp,d_tmp,w_tmp,c_tmp,b_tmp] ...   = updatewn(x,y,t,d,w,c,b,lr, hess_t, hess_d, dt, dd); %send back hessien   							 % and gradient  if length(b_tmp) > 0 		% not bad matrix condition    g = wavenet(x,t_tmp,d_tmp,w_tmp,c_tmp,b_tmp);    E = y-g;    SSE_current = sum(E .* E); %Sum of Squared Errors    if SSE_current <= SSE    %good, stop or decrease lr      if inc_dec == 1 % lr increased for last step, so stop        break;      else 	      % should decrease lr, hoping to do better        SSE = SSE_current; % next step should compare with this SSE        lr = 0.5 * lr;        inc_dec = -1;        %Prepare to come back to this step        t_last=t_tmp; d_last=d_tmp; w_last=w_tmp; c_last=c_tmp; b_last=b_tmp;        SSE_last=SSE;      end    else		     %bad, so increase lr go back to the last step      if inc_dec == -1  % lr decreased for last step, go back to the last step        t_tmp=t_last; d_tmp=d_last; w_tmp=w_last; c_tmp=c_last; b_tmp=b_last;        SSE = SSE_last;        break;      else	        % lr increased for last step, still needs to increase        if (lr > 10) & (SSE_current < 1.01*SSE_current) % RISK of infinite loop          disp(' Slightly increasing error.'); break        end        lr = 2.0 * lr;        inc_dec = 1;      end    end  else				% bad matrix condition, should increase lr    lr = 2.0 * lr;    inc_dec = 1;  endend%Return the good result%======================t=t_tmp; d=d_tmp; w=w_tmp; c=c_tmp; b=b_tmp;SSE = SSE_current;

⌨️ 快捷键说明

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