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

📄 stprm2.m

📁 书籍“Regularization tools for training large feed-forward neural networks using Automatic Differentiat
💻 M
字号:
function [xny,X1,Y1,A1,X2,Y2,A2,stplen,eval, Fsq,fny]=...stprm2(P,T,W1,B1,f1,W2,B2,f2,x,p,mu,f0,Fsq0,Pf,alfin, xc)%NOTE! Only for NNs with one hidden layer. NOTE!%Call:% [xny,X1,Y1,A1,X2,Y2,A2,stplen,eval,Fsq,fny]=...%stprm2(P,T,W1,B1,f1,W2,B2,f2,x,p,mu,f0,Fsq0,Pf,alfin,xc)%This function computes the steplength (stplen) along the direction%p such that the objective is sufficiently reduced.%ON ENTRY:% P(r*q) holds the input data. (r input nodes and q data points)% T(s2*q) holds the target values.% W1(s1*r) holds the weights corresponding to the hidden layer% B1(s1*1) holds the offsets for the hidden layer% f1 is the name of the transfer function used in the hidden layer% W2(s2*s1) holds the weights corresponding to the output layer% B2(s2*1) holds the offsets for the output layer% f2 is the name of the transfer function used in the output layer% x holds the current point packed as [W1(:); B1(:); W2(:); B2(:)]% p holds the search direction packed as x is packed% mu holds the current regularization parameter% f0 holds the error vector corresponding to the current point% Fsq0 holds the current value of the augmented objective% Pf holds the projection of faug onto the range of the Jacobian Jaug% alfin holds the suggested steplength% xc holds the centre of the unknowns in packed form%ON RETURN:%xny = x + stplen*p%X1 = the new value of the weights in the hidden layer%Y1 = the new value of the biases in the hidden layer%A1 = the new value comming out from the hidden layer%X2 = the new value of the weights in the output layer%Y2 = the new value of the biases in the output layer%A2 = the new value comming out from the output layer%stplen = the computed steplength%eval = the number of evaluations of the actual NN inside this function%Fsq = the new value of the augmented objective%fny = the new error value (A2-T)faug=[f0;mu*(x-xc)];v0 = faug;v1 = Pf;F0 = faug;alfa=alfin;tau=0.1;xny=x+alfa*p;nrmaug=(xny-xc)'*(xny-xc)*mu^2/2;%Don't use the suggested alfa if p is unreasonable largeindc=0;while nrmaug > Fsq0  alfa=alfa/2;  indc=indc+1;  xny=x+alfa*p;  nrmaug=(xny-xc)'*(xny-xc)*mu^2/2;end % of whileif indc >0  indc  pauseend[X1,Y1,X2,Y2]=unpack2(xny,W1,B1,W2,B2);[A1,A2]=simuff(P,X1,Y1,f1,X2,Y2,f2);ny=A2-T;fny=ny(:);Fsq=0.5*sumsqr(fny)+nrmaug;i=1;F2 = [fny;mu*(xny-xc)];alf2= alfa;sec = 0;while (Fsq0-Fsq)<tau*(Fsq0-0.5*norm(faug+alfa*Pf)^2)  if sec == 0	FDIFF = F2-F0;	v2 = FDIFF-v1;	[alfa] = parrm(v0, v1, v2,alfa);  	xny=x+alfa*p;  	[X1,Y1,X2,Y2]=unpack2(xny,W1,B1,W2,B2);	[A1,A2]=simuff(P,X1,Y1,f1,X2,Y2,f2);	ny=A2-T;	fny=ny(:);  	Fsq=0.5*(sumsqr(fny)+mu^2*(xny-xc)'*(xny-xc));  	i=i+1;	alf1 = alfa;	F1 = [fny;mu*(xny-xc)];  end  if sec == 1	U1 = (F1-F0) / alf1;	U2 = ((F2-F1)/(alf2-alf1) - (F1-F0)/alf1) / alf2;	v1 = U1-alf1*U2;	v2 = U2;	[alfa] = parrm(v0, v1, v2,alfa);  	xny=x+alfa*p;  	[X1,Y1,X2,Y2]=unpack2(xny,W1,B1,W2,B2);	[A1,A2]=simuff(P,X1,Y1,f1,X2,Y2,f2);	ny=A2-T;	fny=ny(:);  	Fsq=0.5*(sumsqr(fny)+mu^2*(xny-xc)'*(xny-xc));	alf2 = alf1;	F2 = F1;	alf1 = alfa;	F1 = [fny;mu*(xny-xc)];	i = i + 1;  end  sec = 1;endeval=i;stplen=alfa;

⌨️ 快捷键说明

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