2011年7月25日星期一

Linear search with simple back-tracking




function [y] = rosen(x)
% Rosenbrock function. Assume x is a 2-dimensional
% vector.
y = 100*(x(2)-x(1)^2)^2 + (1-x(1))^2 ;

function [Bnew] = bfgs(B,y,s)
% BFGS update
Bnew = B - (B*s*s'*B)/(s'*B*s) + y*y'/(y'*s) ;

function [Hnew] = dfp(H,y,s)
% DFP update
Hnew = H - (H*y*y'*H)/(y'*H*y) + s*s'/(y'*s) ;

function [g] = grad(x)
% gradient of rosenbrock function.
g = [-400*x(1)*(x(2)-x(1)^2)-2*(1-x(1)); 200*(x(2)-x(1)^2)] ;

function [H] = hessian(x)
% Hessian of rosenbrock function.
H = [1200*x(1)^2-400*x(2)+2, -400*x(1) ; -400*x(1), 200];

function [y] = linesearch(fun,x,d,g)
% Line-search along d with simple backtracking.
% Assume g = phi'(0) is also available.
alpha = 1 ;
c = 0.0001 ;
rho = 0.9 ;
while (feval(fun,x+alpha*d) > rosen(x) + c*alpha*g)
   alpha = rho*alpha ;
end ;
y = x+alpha*d ;

没有评论:

发表评论