搜索和民意调查
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);
优化终止:网格尺寸小于选项。
要使用GSS阳性基础2N民意调查作为搜索方法,请更改SearchFcn
选项。
RNGdefault%可再现性options.SearchFcn = @GSSPositiveBasis2N; [x2,fval2,exitflag2,output2] = patternsearch(@lincontest7,x0,...aineq,bineq,aeq,beq,[],[],[],options);
优化终止:网格尺寸小于选项。
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的功能。功能是
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 usefminsearch
as 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功能的最低限度方面更有效。