Main Content

Search and Poll, Problem-Based

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 objective function, lincontest7, is available when you run this example.

Search Using a Poll Method

The following example illustrates the use of a search method on the problem described in Constrained Minimization Using patternsearch and Optimize Live Editor Task. In this case, the search method is the GSS Positive Basis 2N poll. For comparison, first run the problem without a search method.

x = optimvar("x",1,6);
prob = optimproblem("Objective",lincontest7(x));
x0.x = [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];
prob.Constraints.Aineq = Aineq*x' <= bineq;
prob.Constraints.Aeq = Aeq*x' == beq';
options = optimoptions('patternsearch',...
    'PlotFcn',{@psplotbestf,@psplotfuncount});
[x,fval,exitflag,output] = solve(prob,x0,...
    "Options",options,"Solver","patternsearch");
Solving problem using patternsearch.
patternsearch stopped because the mesh size was less than options.MeshTolerance.

Figure Pattern Search contains 2 axes objects. Axes object 1 with title Best Function Value: 1919.54, xlabel Iteration, ylabel Function value contains an object of type scatter. Axes object 2 with title Total Function Evaluations: 696, xlabel Iteration, ylabel Function evaluations contains an object of type scatter.

To use the GSS Positive Basis 2N poll as a search method, change the SearchFcn option.

rng default % For reproducibility
options.SearchFcn = @GSSPositiveBasis2N;
[x2,fval2,exitflag2,output2] = solve(prob,x0,...
    "Options",options,"Solver","patternsearch");
Solving problem using patternsearch.
patternsearch stopped because the mesh size was less than options.MeshTolerance.

Figure Pattern Search contains 2 axes objects. Axes object 1 with title Best Function Value: 1919.54, xlabel Iteration, ylabel Function value contains an object of type scatter. Axes object 2 with title Total Function Evaluations: 777, xlabel Iteration, ylabel Function evaluations contains an object of type scatter.

Both optimizations reached the same objective function value. Using the search method reduces the number of function evaluations, though not the number of iterations.

table([output.funccount;output2.funccount],[output.iterations;output2.iterations],...
    'VariableNames',["Function Evaluations" "Iterations"],...
    'RowNames',["Without Search" "With Search"])
ans=2×2 table
                      Function Evaluations    Iterations
                      ____________________    __________

    Without Search            696                 76    
    With Search               777                182    

Search Using a Different Solver

patternsearch takes a long time to minimize Rosenbrock's function. The function is

f(x)=100(x2-x12)2+(1-x1)2.

Rosenbrock's function is described and plotted in Constrained Nonlinear Problem Using Optimize Live Editor Task or Solver. The minimum of Rosenbrock's function is 0, attained at the point [1,1]. Because patternsearch is not efficient at minimizing this function, use a different search method to help.

Create the objective function.

dejong2fcn = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;

The default maximum number of iterations for patternsearch with two variables is 200, and the default maximum number of function evaluations is 4000. Increase these values to MaxFunctionEvaluations = 5000 and MaxIterations = 2000.

opts = optimoptions("patternsearch","MaxFunctionEvaluations",5000,"MaxIterations",2000);

Run patternsearch starting from [-1.9 2].

x = optimvar("x",1,2);
prob = optimproblem("Objective",dejong2fcn(x));
x0.x = [-1.9,2];
[sol,feval,eflag,output] = solve(prob,x0,...
    "Options",opts,"Solver","patternsearch");
Solving problem using patternsearch.
patternsearch stopped because it exceeded options.MaxFunctionEvaluations.
disp(feval)
    0.8560
disp(output.funccount)
        5000

The optimization did not complete even after 5000 function evaluations, and the result is not very close to the optimal value of 0.

Set the options to use fminsearch as the search method, using the default number of function evaluations and iterations.

opts = optimoptions("patternsearch","SearchFcn",@searchneldermead);

Rerun the optimization.

[sol2,feval2,eflag2,output2] = solve(prob,x0,...
    "Options",opts,"Solver","patternsearch");
Solving problem using patternsearch.
patternsearch stopped because the mesh size was less than options.MeshTolerance.
disp(feval2)
   4.0686e-10
disp(output2.funccount)
   291

The objective function value at the solution is much better (lower) when using this search method, and the number of function evaluations is much lower. fminsearch is more efficient at getting close to the minimum of Rosenbrock's function.

See Also

|

Related Topics