modify surrogateopt options -凯发k8网页登录
this example shows how to search for a global minimum by running surrogateopt
on a two-dimensional problem that has six local minima. the example then shows how to modify some options to search more effectively.
define the objective function sixmin
as follows.
sixmin = @(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);
plot the function.
[x,y] = meshgrid(linspace(-2.1,2.1),linspace(-1.2,1.2)); z = sixmin([x(:),y(:)]); z = reshape(z,size(x)); surf(x,y,z,'edgecolor','none') view(-139,31)
the function has six local minima and two global minima.
run surrogateopt
on the problem using the 'surrogateoptplot'
plot function in the region bounded in each direction by [-2.1,2.1]
. to understand the 'surrogateoptplot'
plot, see .
rng default lb = [-2.1,-2.1]; ub = -lb; opts = optimoptions('surrogateopt','plotfcn','surrogateoptplot'); [xs,fvals,eflags,outputs] = surrogateopt(sixmin,lb,ub,opts);
surrogateopt stopped because it exceeded the function evaluation limit set by 'options.maxfunctionevaluations'.
set a smaller value for the minsurrogatepoints
option to see whether the change helps the solver reach the global minimum faster.
opts.minsurrogatepoints = 4; [xs2,fvals2,eflags2,outputs2] = surrogateopt(sixmin,lb,ub,opts);
surrogateopt stopped because it exceeded the function evaluation limit set by 'options.maxfunctionevaluations'.
the smaller minsurrogatepoints
option does not noticeably change the solver behavior.
try setting a larger value of the minsampledistance
option.
opts.minsampledistance = 0.05; [xs3,fvals3,eflags3,outputs3] = surrogateopt(sixmin,lb,ub,opts);
surrogateopt stopped because it exceeded the function evaluation limit set by 'options.maxfunctionevaluations'.
changing the minsampledistance
option has a small effect on the solver. this setting causes the surrogate to reset more often, and causes the best objective function to be slightly higher (worse) than before.
try using parallel processing. time the execution both with and without parallel processing on the camelback
function, which is a variant of the sixmin
function. to simulate a time-consuming function, the camelback
function has an added pause of one second for each function evaluation.
type camelback
function y = camelback(x) y = (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); pause(1)
tic opts = optimoptions('surrogateopt','useparallel',true,'plotfcn','surrogateoptplot'); [xs4,fvals4,eflags4,outputs4] = surrogateopt(@camelback,lb,ub,opts);
surrogateopt stopped because it exceeded the function evaluation limit set by 'options.maxfunctionevaluations'.
toc
elapsed time is 43.142697 seconds.
time the solver when run on the same problem in serial.
opts.useparallel = false; tic [xs5,fvals5,eflags5,outputs5] = surrogateopt(@camelback,lb,ub,opts);
surrogateopt stopped because it exceeded the function evaluation limit set by 'options.maxfunctionevaluations'.
toc
elapsed time is 227.968689 seconds.
for time-consuming objective functions, parallel processing significantly improves the speed, without overly affecting the results.