上一个博文中介绍了globalsearch和multistart的异同,以及选择时的参考,本文着重介绍multistart。
④multistart(全局最优)(找多个局部最小值)
下面这个例子在globalsearch中使用过,在这里可以只是换一下符号,再次使用。可以看出两个函数设置基本相同。
实例(六驼峰最小值问题)
rng default %对于再现性
gs = multistart ;
fun6 = @(x)(4 * x(1)^ 2 - 2.1 * x(1)^ 4 + x(1)^ 6/3 ...
+ x(1)* x(2) - 4 * x(2)^ 2 + 4 * x(2)^ 4);
problem = createOptimProblem('fmincon','x0',[ - 1,2],...
'objective',fun6,'lb',[ - 3,-3],'ub',[3,3]) ;
[x,fval] = run(gs,problem)
另一种表示
构造函数
function f = fun6(x)
f = (4 * x(1)^ 2 - 2.1 * x(1)^ 4 + x(1)^ 6/3 ...
+ x(1)* x(2) - 4 * x(2)^ 2 + 4 * x(2)^ 4);
end
主优化程序
x0=[-1,2];
LB=[-3,-3];
UB=[3,3];
f = @(data)fun6(data);
problem = createOptimProblem('fmincon','objective',f,'x0',x0,'lb',LB,'ub',UB,'options',optimset('Algorithm','SQP','DISP','none');
gs = multistart;
[x,fval] = run(gs,problem);