Search and Poll

Using a Search Method

In addition to polling the mesh points, the pattern search algorithm can perform an optional step at every iteration, called search. At each iteration, the search step applies another optimization method to the current point. If this search does not improve the current point, the poll step is performed.

The following example illustrates the use of a search method on the problem described in Linearly Constrained Problem. To set up the example, enter the following commands at the MATLAB® prompt to define the initial point and constraints.

x0 = [2 1 0 9 1 0];
Aineq = [-8 7 3 -4 9 0];
bineq = 7;
Aeq = [7 1 8 3 3 3; 5 0 -5 1 -5 8; -2 -6 7 1 1 9; 1 -1 2 -2 3 -3];
beq = [84 62 65 1];

Then enter the settings shown in the following figures in the Optimization app.

For comparison, click Start to run the example without a search method. This displays the plots shown in the following figure.

To see the effect of using a search method, select MADS Positive Basis 2N in the Search method field in Search options.

This sets the search method to be a pattern search using the pattern for MADS Positive Basis 2N. Then click Start to run the pattern search. This displays the following plots.

Note that using the search method reduces the total function evaluations—from 1462 to 1256—and reduces the number of iterations from 106 to 97.

To run this problem using command-line functions:

x0 = [2 1 0 9 1 0];
Aineq = [-8 7 3 -4 9 0];
bineq = 7;
Aeq = [7 1 8 3 3 3; 5 0 -5 1 -5 8; -2 -6 7 1 1 9; 1 -1 2 -2 3 -3];
beq = [84 62 65 1];
options = optimoptions('patternsearch',...
    'PlotFcn',{@psplotbestf,@psplotfuncount});
[x,fval] = patternsearch(@lincontest7,x0,...
    Aineq,bineq,Aeq,beq,[],[],[],options);

To use the MADS search method, change the SearchFcn option.

options.SearchFcn = @MADSPositiveBasis2N;
[x,fval] = patternsearch(@lincontest7,x0,...
    Aineq,bineq,Aeq,beq,[],[],[],options);

Search Using a Different Solver

patternsearch takes a long time to minimize Rosenbrock's function. The function is f(x)=100(x2x12)2+(1x1)2.

Rosenbrock's function is described and plotted in Solve a Constrained Nonlinear Problem, Solver-Based (Optimization Toolbox).

  1. Create the objective function.

    dejong2fcn = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
  2. Set patternsearch options to MaxFunctionEvaluations = 5000 and MaxIterations = 2000:

    opts = optimoptions('patternsearch','MaxFunctionEvaluations',5000,'MaxIterations',2000);
  3. Run patternsearch starting from [-1.9 2]:

    [x,feval,eflag,output] = patternsearch(dejong2fcn,...
        [-1.9,2],[],[],[],[],[],[],[],opts);
    Maximum number of function evaluations exceeded: increase options.MaxFunctionEvaluations.
    feval
    
    feval =
        0.8560

    The optimization did not complete, and the result is not very close to the optimal value of 0.

  4. Set the options to use fminsearch as the search method:

    opts = optimoptions('patternsearch',opts,'SearchFcn',@searchneldermead);
  5. Rerun the optimization, the results are much better:

    [x2,feval2,eflag2,output2] = patternsearch(dejong2fcn,...
        [-1.9,2],[],[],[],[],[],[],[],opts);
    Optimization terminated: mesh size less than options.MeshTolerance.
    
    feval2
    
    feval2 =
      4.0686e-010

fminsearch is not as closely tied to coordinate directions as the default GPS patternsearch poll method. Therefore, fminsearch is more efficient at getting close to the minimum of Rosenbrock's function. Adding the search method in this case is effective.

Related Topics