Actual source code: ProblemFinalize.m

petsc-3.13.4 2020-08-01
Report Typos and Errors
  1: % Sample calling syntax for testing taopounders and comparing to fminsearch
  2: % ProblemFinalize is called after solving the instance

  4: % Pad the histroy if there are remaining evaluations or truncate if too many
  5: if nfev < nfmax
  6:   fvals = [fvals(1:nfev);ones(nfmax-nfev,1)*fvals(nfev)];
  7: else
  8:   fvals = fvals(1:nfmax);
  9:   fvecs = fvecs(1:nfmax,:);
 10:   X_hist = X_hist(1:nfmax,:);
 11: end

 13: % Store the history and results for taopounders
 14: SolverNumber = 1;
 15: Results{SolverNumber,np}.alg = 'TAO Pounders';
 16: Results{SolverNumber,np}.problem = ['problem ' num2str(np) ' from More/Wild'];
 17: Results{SolverNumber,np}.H = fvals;
 18: Results{SolverNumber,np}.X = X_hist;
 19: Results{SolverNumber,np}.fvecs = fvecs;

 21: % Initialize the function handle for evaluating the norm of the residuals
 22: func = @(x)dfovec_wrap(m,n,x,nprob,0);

 24: % Initialize the algorithmic parameters for fminsearch
 25: rand('seed',0);
 26: options = optimset('MaxFunEvals',nfmax,'MaxIter',nfmax);

 28: % Reset the global history of the evaluations
 29: nfev = 0;
 30: fvals = zeros(nfmax,1);
 31: fvecs = zeros(nfmax,m);
 32: X_hist = zeros(nfmax,n);

 34: % Call fminsearch
 35: fminsearch(func,X0,options);

 37: % Pad the histroy if there are remaining evaluations or truncate if too many
 38: if nfev < nfmax
 39:   fvals = [fvals(1:nfev);ones(nfmax-nfev,1)*fvals(nfev)];
 40: else
 41:   fvals = fvals(1:nfmax);
 42:   fvecs = fvecs(1:nfmax,:);
 43:   X_hist = X_hist(1:nfmax,:);
 44: end

 46: % Store the history and results for taopounders
 47: SolverNumber = 2;
 48: Results{SolverNumber,np}.alg = 'fminsearch';
 49: Results{SolverNumber,np}.problem = ['problem ' num2str(np) ' from More/Wild'];
 50: Results{SolverNumber,np}.H = fvals;
 51: Results{SolverNumber,np}.X = X_hist;
 52: Results{SolverNumber,np}.fvecs = fvecs;