Main Content

Search and Poll

除了轮询网格点外,模式搜索算法还可以在每次迭代(称为搜索)执行一个可选步骤。在每次迭代中,搜索步骤将另一种优化方法应用于当前点。如果此搜索无法改善当前点,则将执行轮询步骤。

使用民意调查方法搜索

下面的示例说明了在描述的问题上使用搜索方法使用PatternSearch限制最小化并优化实时编辑器任务。在这种情况下,搜索方法是GSS阳性基础2N民意调查。为了进行比较,首先在没有搜索方法的情况下运行问题。

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];选项= optimoptions(“模式搜索”,,,,...'plotfcn',{@psplotbestf,@psplotfuncount});[x,fval,exitflag,output] = patternsearch(@lincontest7,x0,...Aineq,bineq,Aeq,beq,[],[],[],options);
Optimization terminated: mesh size less than options.MeshTolerance.

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

To use the GSS Positive Basis 2N poll as a search method, change the搜索FCNoption.

rng默认% For reproducibilityoptions.searchfcn = @gssposivebasis2n;[x2,fval2,exitflag2,output2] = patternsearch(@lincontest7,x0,...Aineq,bineq,Aeq,beq,[],[],[],options);
Optimization terminated: mesh size less than options.MeshTolerance.

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

两种优化都达到相同的目标函数值。使用搜索方法减少功能评估的数量和迭代次数。

table([output.funccount;output2.funccount],[output.iterations;output2.iterations],...'variablenames',,,,[“功能评估”“迭代”],,...'Rownames',,,,[“无搜索”“使用搜索”)))
ans =2×2桌Function Evaluations Iterations ____________________ __________ Without Search 714 78 With Search 777 182

使用其他求解器搜索

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

F (( X = 1 0 0 (( X 2 - X 1 2 2 + (( 1 - X 1 2

描述并绘制了Rosenbrock的功能解决受约束的非线性问题,基于求解器。Rosenbrock的最低功能为0,在该点达到[1,1]。因为patternsearchis not efficient at minimizing this function, use a different search method to help.

创建目标函数。

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

带有两个变量的模式搜索的默认默认迭代次数为200,默认的最大函数评估数为4000。将这些值增加到maxfunction evaluations=5000 and最大值=2000。

opts = optimoptions(“模式搜索”,,,,“ maxfunction evaluations',5000,“最大”,2000);

从开始运行模式搜索[-1.9 2]

[x,函数宏指令,eflag,输出]= patternsearch (dejong2fcn,...[-1.9,2],[],[],[],[],[],[],[],opts);
超出功能评估的最大数量:增加选项。maxFunctionEvaluations。
disp(feval)
0。8560
disp(output.funccount)
5000

即使经过5000个功能评估,优化也无法完成,因此结果并不是很接近最佳值0。

设置使用的选项fminsearchas the search method, using the default number of function evaluations and iterations.

opts = optimoptions(“模式搜索”,选择,'searchfcn',@searchneldermead);

重新运行优化。

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

使用此搜索方法时,解决方案的目标函数值要好得多(较低),并且功能评估的数量要低得多。fminsearchis more efficient at getting close to the minimum of Rosenbrock's function.

Related Topics