主要内容

搜索和民意调查

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.

Search Using a Poll Method

The following example illustrates the use of a search method on the problem described inConstrained 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.

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,exitflag,output] = patternsearch(@lincontest7,x0,...aineq,bineq,aeq,beq,[],[],[],options);
优化终止:网格尺寸小于选项。

图模式搜索包含2个轴对象。轴对象1具有标题最佳功能值:1919.54包含一个类型行的对象。轴对象2具有标题总功能评估:714包含一个类型行的对象。

要使用GSS阳性基础2N民意调查作为搜索方法,请更改SearchFcn选项。

RNGdefault%可再现性options.SearchFcn = @GSSPositiveBasis2N; [x2,fval2,exitflag2,output2] = patternsearch(@lincontest7,x0,...aineq,bineq,aeq,beq,[],[],[],options);
优化终止:网格尺寸小于选项。

图模式搜索包含2个轴对象。轴对象1具有标题最佳功能值:1919.54包含一个类型行的对象。Axes object 2 with title Total Function Evaluations: 777 contains an object of type line.

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

表([output.funccount; output2.funccount],[output.Iterations; output.2.Iterations],...'VariableNames',[["Function Evaluations""Iterations"],...'RowNames',[["Without Search""With Search"])
ans=2×2 table功能评估迭代____________________ __________毫无搜索714 78与搜索777 182

Search Using a Different Solver

patternsearch花费很长时间才能最大程度地减少Rosenbrock的功能。功能是

f ( x ) = 1 0 0 ( x 2 - x 1 2 ) 2 + ( 1 - x 1 ) 2 .

Rosenbrock's function is described and plotted inSolve a Constrained Nonlinear Problem, Solver-Based. The minimum of Rosenbrock's function is 0, attained at the point[1,1]. Becausepatternsearch在最小化此功能方面不高效,使用其他搜索方法来帮助。

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 toMaxFunctionEvaluations= 5000和MaxIterations= 2000。

opts = optimoptions('patternsearch',“MaxFunctionEvaluations”,5000,'MaxIterations', 2000);

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.
disp(feval)
0.8560
disp(output.funccount)
5000

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

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

opts = optimoptions('patternsearch'选择,'SearchFcn',@searchneldermead);

Rerun the optimization.

[x2,feval2,eflag2,output2] = patternsearch(dejong2fcn,...[-1.9,2],[],[],[],[],[],[],[],[],opts);
优化终止:网格尺寸小于选项。
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在接近Rosenbrock功能的最低限度方面更有效。

相关话题