WARNING Changes are currently being made. (as of Mar 11/10) The following file can be tried runtrs.m which uses:

[xopt,fopt,lopt,lambdamin,flag] = newtrust4b(a,s,dgaptol) Here is a tarfile with the matlab files %

%

Call: [xopt,fopt,lopt,lambdamin,muup,mulow,iter,flag] = ... % newtrust(a,s,dgaptol);

%% files needed: Afun.m,Dfun.m, and this file newtrust.m %%% option file conj_grad.m, see commented out part below %% % BEFORE USING NEWTRUST, THE FOLLOWING INSTRUCTION MUST BE ENTERED % > global A D counter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Trust Region Subroutine Algorithm

Trust Region Subroutine Algorithm

Algorithm with Links to Documentation

Charles Fortin and Henry Wolkowicz
Dept. Comb. & Opt., Univ. of Waterloo %

This file is available with URL http://orion.math.uwaterloo.ca/~hwolkowi/henry/software/trustreg.d/newtrust.html %
In Documentation: Complete Documentation File, Variable Definitions,
In Algorithm: Tolerances, Initialization, While Loop, End of While Loop,

% %

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % solves: min q(x) = x'Ax - 2a'x % such that s^2-x'x >= 0 (Lagr. mult. lopt <=0) % %% which is the trust region subproblem. This can be used within %% a trust region algorithm for min f(x). % % The algorithm returns an approx .optimum xopt and corresp. value qopt so that: % % norm(xopt) <= (1+dgaptol)s % % and two constants so that % % mulow <= qopt <= muup, mulow <= fopt <= muup, AND % |qopt - fopt| <= |muup-mulow| <= |2*dgaptol*muup| <= |2*dgaptol*fopt| % So that qopt >= (1-2*dgaptol)*fopt % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%% % %%%%%%%%%%%%%%%%%%%%%%%%%%%GLOBAL VARIABLES%%%%%%%%%%%%%%%%%%%%%%% % global A D counter % % %%%%%%%%%%%%%%%%%%%%%% TOLERANCES%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Back to Top of algorithm page. % Tolerances - these can and should be changed by the user. % %dgaptol % duality gap for stopping criteria (input) intol= dgaptol; normtol =intol; % allowable error in feasibility for stopping n = size( A,1); % problem size zerotol=intol/log(n^10); % tolerance for zero for y(1) for hard case % since y is norm 1, tolerance decreases with dim. kzerotol=intol; % tolerance for zero for k(t) hzerotol= 1e-4; % hard case detection ??? iterbnd=30; % upper bound on iterations %%%%%%%%%%%%%%%%%%%%%%%%%%%END TOLERANCES%%%%%%%%%%%% % % %%%%%%%%%%%%%%%%%%%%%%%%%%%INITIALIZATION%%%%%%%%%%%%%% % Back to Top of algorithm page. t0=cputime; % saved to get total cputime usage counter = 0; % counts matrix mults a=full(a); % set to full to avoid conflicts na=norm(a); % vector norm if na < zerotol, disp('WARNING: linear part -a- is approximately 0'); end %%%First eigenvalue calculation OPTIONS.tol= 1e-13; % convergence tolerance OPTIONS.issym = 1; % because we know the matrices A and D are symmetric OPTIONS.disp = 0; % no display of the output for eigs.m v=full(sum(A))';v=-v/norm(v); % good/cheap normalized estimate ??? %i.e. largest eig of -A using v=-Ae, e=ones OPTIONS.v0 =v ; % initial eigenvector estimate for sparse A tarn10=cputime; % keep for the first eig calc time [va,lambda,flageigs]=eigs('Afun',n,1,'SR',OPTIONS); % computes smallest tarn1f=cputime-tarn10; % save initial eig calc cputime for statistics disp(['elapsed time for first eig calc: ',num2str(tarn1f)]); if (flageigs>0), disp('WARNING INITIAL EIGENVALUE CALCULATION BAD'); disp(['condition est. of eigs: ',num2str(condest(A))]); end %eigenvalue (lambda) and corresponding eigenvector (va) for A avnorm=norm(A*va-lambda*va); if avnorm > zerotol*(abs(lambda)+1), % ???zerotol???check??? disp(['USING eig, output from eigs norm error ',num2str(avnorm)]); [V,Lam]=eig(full(A)); lambda=min(diag(Lam)); indx=find(lambda==diag(Lam) );va=V(:,indx);va=va/norm(va); avnorm=norm(A*va-lambda*va); disp(['USING eig new norm error is ',num2str(avnorm)]); end lambdamin = lambda; % save the min eigenvalue of A vaa=va'*a; % ensure va'*a is not negative if (vaa < 0) va = -va;vaa=-vaa; end y=[0;va];y=y/norm(y); % initial normalized estimate eigenv. D(t^*) flag = 0; %flag will change value if the almost hard case (case 2) occurs alow=lambda;aup=lambda; % lower estimate on mu* if lambda < 0 mulow = alow*s^2-2*na*s; % lower estimate for optimal value else % mulow = -2*na*s; % replaced by min on boundary or interior % since interior opt value is a'invAa-2a'invAa=-a'invAa mulow = min(alow*s^2-2*na*s,-na*s); end % upper estimate on mu* if lambda > 0 if (( (vaa)/(lambda ) <= s)), % optimum may be on boundary or interior testmu = s^2*lambda - 2*s*na; muup = -(vaa)^2/lambda; if muup < testmu, % apply conj grad - opt interior a=sparse(a); %xopt = conj_grad((vaa/lambda)*va,a); % apply conjugate gradient method to find the optimum. xopt=A\a; % use matlab function for now or uncomment conj_grad fopt = -a'*xopt; % optimal value since A xopt = a lopt = 0; topt = 99999; muup=99999; mulow=99999;iter=0; gap=[topt topt lopt lopt topt topt ]; t0f=cputime-t0; flag = 2; % To know answer is the unconstrained minimum disp(['elapsed time: ', num2str(t0f)]); disp(['Problem solved using conjugate gradients ']); return; %OPTIMALITY - PROBLEM IS SOLVED end bestxf = ((vaa)/lambda)*va; % vaa is >=0 now else muup = s^2*lambda - 2*s*(vaa); % <=0 by above if bestxf = s*va; end else [muup,indice] = min([0,lambda*s^2-2*s*(vaa)]); if indice == 1 bestxf = zeros(size(a,1),1); else bestxf = s*va; end end bestfxf=muup; % current best opt value corresp to bestxf % bestxf is feasible (possibly interior) mubnds=[mulow muup]; % keep history of bounds - latest at top % This is only for debugging help. gap=[mulow muup]; % duality gap - gets updated when a bound changes if (lambda > 0) low = min(alow - na/s,-na*s); %lower bound on t else low = alow - na/s; end high = aup + na*s; % upper bound on t newlow=low;newhigh=high; %new points found by vertical cuts vertflag=0; % to prevent 2 vertical cuts in a row ss1=s^2+1; D = [ 0 -a' -a A]; % augmented matrix ystar = 1 / sqrt( s*s +1); % this is value we are after for y0(t) iter=0; % iteration count b6 = ' '; % define 6 blanks % ptgood, ptbad variables: used for saving interpolation data on the % good (easy) and bad (hard) side of maximum of k(t). % gy,by saves last y vector on good and bad side % The latest data is put into row 1. % Only two rows are needed. The rest is saved for debugging help. % t, y(1), lambda, valid-data-indicator ; is data saved. ptbad=[]; ptgood=[]; gy=[];by=[]; % The latest vectors y from the good and bad side resp. side=0; % indicator for consecutive t found % -i for i bad sides and +i for i good sides tslopes=[]; % Save slopes of kt on the [bad good] sides - for % debugging and for case where kt is almost piecewise linear. kts=[]; % saving kt bounds and t value - for debugging t=99999;indexg=0;indexb=0; % initialize in case of 0 iterations tind=[]; % follow trail of t changes - for debugging % disp('iter ----- t ---- rel dual gap -- rel. primal opt cond'); %txt=[int2str(iter),b6,num2str(t),b6,num2str(dgap),b6,num2str(dbestgap)]; % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%NOTES on ALGORITHM%%%%%%%%%%%%%% % Following are the functions of interest: % h(lambda) = s^2lambda -a'(A-lambda I)^{-1} a; maximize - concave % hp(lambda) = s^2 -a'(A-lambda I)^{-2} a;solve = 0 - concave, nonincreasing % phi(lambda) = 1/s-1/||(A-lambda I)^{-1} a||;solve = 0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % k(t) = (s^2+1)lambda -t maximize - concave % k'(t) = (s^2+1)y0^2(t) -1 solve = 0 - same sign as f(t) % psi(t) = -1/y0(t) + sqrt(s^2+1) solve = 0 - concave, nonincreasing % y0(t) = first component of y normalized - nonincreasing, 1to0 % lambda=lambda(t) concave function % % The algorithm is based on maximizing k(t). % We interpolate on psi(t) whenever possible. % % The general iteration interpolates psi(t) whenever % possible. Duality is used to calculate bounds, i.e. the function k(t) is % used when problems with the hard case occur. % Initialize the stopping criteria t1=abs( 1-y(1)^2*(1+s^2))>( (2*normtol+normtol^2) *y(1)^2*s^2 ); dbestgap= (bestfxf-mulow)/(abs(bestfxf)+1); t2= dbestgap > 2*dgaptol; dgap= abs(muup-mulow)/(abs(muup)+1) ; t3= (muup-mulow) >= -2*dgaptol*muup; %t3= dgap > dgaptol; % Duality gap criteria - old way t4=iter <=iterbnd; % iteration bound t5=abs(high-low)/(abs(high)+1) > zerotol; %interval of uncertainty for t %%%%%%%%%%%%%%%%%%%END INITIALIZATION%%%%%%%%%%%%% %% % %%%%%%%%%%%%%%%%%%%%%%%WHILE LOOP%%%%%%%%%%% % %%%%%%%%%%%%%%%%%%%%%Back to Top of algorithm page., % PART 1. Find New Point t, % Vertical Cut, % Triangle Interpolation, % Good Side Interpol., % Bad Side Interpol., % PART 2. Updating Begins., % Lambda has wrong sign, % Bad Side Update, % Good Side Update, % PART 3.Tolerance Updates, End of While Loop, Start of Output, % %% check feasibility and iteration count and duality gap while ( (t1&t2) | t3) & (t4 & t5), % end of while loop end % end of while for gap and iteration check % %%%%%%%%%%%%%%%%%%%%%Back to Top of algorithm page., % %%%%%%%%%%%%%%%%%%%%%%%%%END GENERAL ITERATION%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%OUTPUT DATA%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% fopt=(muup+mulow)/2; if ~t2, % bestxf is almost feasible xopt=bestxf; fopt=bestfxf; else xopt = y(2:n+1)/y(1); end topt=t;lopt=lambda; if indexg ==0, ptgood=[99999 99999 99999 0]; end if indexb ==0, ptbad=[-99999 -99999 -99999 0]; end t0f=cputime-t0; gap=[gap % lower and upper bound for mu^* ptbad(1,3) ptgood(1,3) % lower and upper bound for lambda^* low high % lower and upper bound for t^* tarn1f t0f ]; % tarn1f is elapsed time for first eigs call % t0f is total computation time disp(['elapsed time: ', num2str(t0f)]); % t0f is total computation time disp(['number of matrix-vector multiplications: ', num2str(counter)]) disp(['number of iterations: ', num2str(iter)]) relopt=-norm( (A-lopt*eye(size(A,1)))*xopt-a)/fopt; %rel opt cond. norm of grad of Lagrangian / value of Lagrang. at opt. format long e disp(['relative opt. condition: ', num2str(relopt)]) disp(['interval of optimal value: [ ',num2str(mulow),' to ',... num2str(muup),' ]']); disp('final results for '); disp('iter ----- t ---- rel dual gap -- rel. dual opt cond'); txt=[int2str(iter),b6,num2str(t),b6,num2str(reldgap),b6,num2str(dbestgap)]; disp( txt); if (abs(lambdamin - lopt)/(abs(lambdamin)+1) < 1e-2) flag = 1; end % Top of algorithm page.
[ DIR]This directory on orion