Main Content

Surrogate Optimization of Multidimensional Function

R2026b

This example shows the behavior of three recommended solvers on a minimization problem. The objective function is the multirosenbrock function:

function F = multirosenbrock(x)
% This function is a multidimensional generalization of Rosenbrock's
% function. It operates in a vectorized manner, assuming that x is a matrix
% whose rows are the individuals.

% Copyright 2014 by The MathWorks, Inc.

N = size(x,2); % assumes x is a row vector or 2-D matrix
if mod(N,2) % if N is odd
    error("Input rows must have an even number of elements")
end

odds  = 1:2:N-1;
evens = 2:2:N;
F = zeros(size(x));
F(:,odds)  = 1-x(:,odds);
F(:,evens) = 10*(x(:,evens)-x(:,odds).^2);
F = sum(F.^2,2);
end

The multirosenbrock function has a single local minimum of 0 at the point [1,1,...,1]. See how well the three best solvers for general nonlinear problems work on this function in 20 dimensions with a challenging maximum function count of only 300.

Set up the problem.

N = 20; % Any even number
mf = 300; % max fun evals
fun = @multirosenbrock;
lb = -3*ones(1,N);
ub = -lb;
rng default
x0 = -3*rand(1,N);

Set options for surrogateopt to use only 200 function evaluations, and then run the solver.

options = optimoptions("surrogateopt",MaxFunctionEvaluations=mf);
[xm,fvalm,~,~,pop] = surrogateopt(fun,lb,ub,options);

Surrogateopt best value dropping from 150000 to near 9 over 300 iterations

surrogateopt stopped because it exceeded the function evaluation limit set by 
'options.MaxFunctionEvaluations'.

Set similar options for patternsearch, including a plot function to monitor the optimization.

psopts = optimoptions("patternsearch",PlotFcn="psplotbestf",MaxFunctionEvaluations=mf);
[psol,pfval] = patternsearch(fun,x0,[],[],[],[],lb,ub,[],psopts);
patternsearch stopped because it exceeded options.MaxFunctionEvaluations.

Patternsearch best value decreasing from 45000 to 540 over 50 iterations

Set similar options for fmincon.

opts = optimoptions("fmincon",PlotFcn="optimplotfval",MaxFunctionEvaluations=mf);
[fmsol,fmfval,eflag,fmoutput] = fmincon(fun,x0,[],[],[],[],lb,ub,[],opts);

Fmincon current function value decreasing from 45000 to 100 over 13 iterations

Solver stopped prematurely.

fmincon stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 3.000000e+02.

For this extremely restricted number of function evaluations, the surrogateopt solution is closest to the true minimum value of 0.

table(fvalm,pfval,fmfval,VariableNames=["surrogateopt","patternsearch","fmincon"])
ans = 1×3 table
    surrogateopt    patternsearch    fmincon
    ____________    _____________    _______

       8.682           539.57        99.869 

Allowing another 300 function evaluations shows that the other solvers make good progress toward the true solution, while surrogateopt does not improve significantly. Restart the solvers from their previous solutions, which adds 300 function evaluations to each optimization.

options = optimoptions(options,InitialPoints=pop);
[xm,fvalm,~,~,pop] = surrogateopt(fun,lb,ub,options);

Surrogateopt best value at 7.9, staircase decrease over 300 additional iterations

surrogateopt stopped because it exceeded the function evaluation limit set by 
'options.MaxFunctionEvaluations'.
[psol,pfval] = patternsearch(fun,psol,[],[],[],[],lb,ub,[],psopts);
patternsearch stopped because it exceeded options.MaxFunctionEvaluations.

Patternsearch best value decreasing from 540 to 216 over 17 additional iterations

[fmsol,fmfval,eflag,fmoutput] = fmincon(fun,fmsol,[],[],[],[],lb,ub,[],opts);

Fmincon current function value decreasing from 100 to 9.4 over 12 additional iterations

Solver stopped prematurely.

fmincon stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 3.000000e+02.
table(fvalm,pfval,fmfval,VariableNames=["surrogateopt","patternsearch","fmincon"])
ans = 1×3 table
    surrogateopt    patternsearch    fmincon
    ____________    _____________    _______

       7.8981          215.99        9.4401 

See Also

Topics