Main Content

ModifysurrogateoptOptions

This example shows how to search for a global minimum by runningsurrogateopton 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 functionsixminas 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.

Runsurrogateopton the problem using the'surrogateoptplot'plot function in the region bounded in each direction by[-2.1,2.1]. To understand the'surrogateoptplot'plot, seeInterpret surrogateoptplot.

rngdefaultlb = [-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 theMinSurrogatePointsoption 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 smallerMinSurrogatePointsoption does not noticeably change the solver behavior.

Try setting a larger value of theMinSampleDistanceoption.

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 theMinSampleDistanceoption 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 thecamelbackfunction, which is a variant of thesixminfunction. To simulate a time-consuming function, thecamelbackfunction has an added pause of one second for each function evaluation.

typecamelback
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
厉螨ed 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
厉螨ed time is 227.968689 seconds.

For time-consuming objective functions, parallel processing significantly improves the speed, without overly affecting the results.

See Also

Related Topics