Main Content

surrogateopt

Surrogate optimization for global minimization of time-consuming objective functions

Description

surrogateoptis a global solver for time-consuming objective functions.

surrogateoptattempts to solve problems of the form

min x f ( x ) such that { lb x ub A · x b Aeq · x = beq c ( x ) 0 x i integer, i intcon .

The solver searches for the global minimum of a real-valued objective function in multiple dimensions, subject to bounds, optional linear constraints, optional integer constraints, and optional nonlinear inequality constraints.surrogateoptis best suited to objective functions that take a long time to evaluate. The objective function can be nonsmooth. The solver requires finite bounds on all variables. The solver can optionally maintain a checkpoint file to enable recovery from crashes or partial execution, or optimization continuation after meeting a stopping condition. The objective functionf(x) can be empty ([]), in which casesurrogateoptattempts to find a point satisfying all the constraints.

example

x= surrogateopt(objconstr,lb,ub)searches for a global minimum ofobjconstr(x)in the regionlb <= x <= ub. Ifobjconstr(x)returns a structure, thensurrogateoptsearches for a minimum ofobjconstr(x).Fval, subject toobjconstr(x).Ineq <= 0.

Note

Passing Extra Parametersexplains how to pass extra parameters to the objective function, if necessary.

example

x= surrogateopt(objconstr,lb,ub,intcon)requires that the variables listed inintcontake integer values.

example

x= surrogateopt(objconstr,lb,ub,intcon,A,b,Aeq,beq)requires that the solutionxsatisfy the inequalitiesA*x <= band the equalitiesAeq*x = beq. If no inequalities exist, setA = []andb = []. Similarly, if no equalities exist, setAeq = []andbeq = [].

example

x= surrogateopt(___,options)modifies the search procedure using the options inoptions. Specifyoptionsfollowing any input argument combination in the previous syntaxes.

example

x= surrogateopt(problem)searches for a minimum forproblem, a structure described inproblem.

example

x= surrogateopt(checkpointFile)continues running the optimization from the state in a saved checkpoint file. SeeWork with Checkpoint Files.

example

x= surrogateopt(checkpointFile,opts)continues running the optimization from the state in a saved checkpoint file, and replaces options incheckpointFilewith those inopts. SeeCheckpoint File.

example

[x,fval] = surrogateopt(___)also returns the best (smallest) value of the objective function found by the solver, using any of the input argument combinations in the previous syntaxes.

example

[x,fval,exitflag,output] = surrogateopt(___)also returnsexitflag, an integer describing the reason the solver stopped, andoutput, a structure describing the optimization procedure.

example

[x,fval,exitflag,output,trials] = surrogateopt(___)返回一个结构,其中包含所有的伊娃luated points and the objective function values at those points.

Examples

collapse all

Search for a minimum of the six-hump camel back function in the region-2.1 <= x(i) <= 2.1. This function has two global minima with the objective function value-1.0316284...and four local minima with higher objective function values.

rngdefault% For reproducibilityobjconstr = @(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); lb = [-2.1,-2.1]; ub = -lb; x = surrogateopt(objconstr,lb,ub)

Figure Optimization Plot Function contains an axes object. The axes object with title Best Function Value: -1.03163 contains an object of type line. This object represents Best function value.

surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'.
x =1×20.0895 - -0.7130

Find the minimum of Rosenbrock's function

1 0 0 ( x ( 2 ) - x ( 1 ) 2 ) 2 + ( 1 - x ( 1 ) ) 2

subject to the nonlinear constraint that the solution lies in a disk of radius 1/3 around the point [1/3,1/3]:

( x ( 1 ) - 1 / 3 ) 2 + ( x ( 2 ) - 1 / 3 ) 2 ( 1 / 3 ) 2 .

To do so, write a function objconstr(x)that returns the value of Rosenbrock's function in a structure fieldFval, and returns the nonlinear constraint value in the form c ( x ) 0 in the structure fieldIneq.

typeobjconstr
function f = objconstr(x) f.Fval = 100*(x(2) - x(1)^2)^2 + (1 - x(1))^2; f.Ineq = (x(1)-1/3)^2 + (x(2)-1/3)^2 - (1/3)^2;

Callsurrogateoptusing lower bounds of 0 and upper bounds of 2/3 on each component.

lb = [0,0]; ub = [2/3,2/3]; [x,fval,exitflag] = surrogateopt(@objconstr,lb,ub)

Figure Optimization Plot Function contains an axes object. The axes object with title Best Function Value: 0.119659 contains 2 objects of type line. These objects represent Best function value (infeasible), Best function value.

surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'.
x =1×20.6541 0.4279
fval = 0.1197
exitflag = 0

非线性约束的检查价值solution.

disp(objconstr(x).Ineq)
7.0843e-04

The constraint function value is near zero, indicating that the constraint is active at the solution.

Find the minimum of theps_examplefunction for a two-dimensional variablexwhose first component is restricted to integer values, and all components are between –5 and 5.

intcon = 1; rngdefault% For reproducibilityobjconstr = @ps_example; lb = [-5,-5]; ub = [5,5]; x = surrogateopt(objconstr,lb,ub,intcon)

Figure Optimization Plot Function contains an axes object. The axes object with title Best Function Value: -1.91774 contains an object of type line. This object represents Best function value.

surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'.
x =1×2-5.0000 0.0001

Minimize the six-hump camel back function in the region-2.1 <= x(i) <= 2.1. This function has two global minima with the objective function value-1.0316284...and four local minima with higher objective function values.

To search the region systematically, use a regular grid of starting points. Set 120 as the maximum number of function evaluations. Use the'surrogateoptplot'plot function. To understand the'surrogateoptplot'plot, seeInterpret surrogateoptplot.

rngdefault% For reproducibilityobjconstr = @(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); lb = [-2.1,-2.1]; ub = -lb; [Xpts,Ypts] = meshgrid(-3:3); startpts = [Xpts(:),Ypts(:)]; options = optimoptions('surrogateopt','PlotFcn','surrogateoptplot',...'InitialPoints',startpts,'MaxFunctionEvaluations',120); x = surrogateopt(objconstr,lb,ub,options)

Figure Optimization Plot Function contains an axes object. The axes object with title Best: -1.03163 Incumbent: -0.124304 Current: -0.124304 contains 6 objects of type line. These objects represent Best, Incumbent, Initial Samples, Adaptive Samples, Random Samples, Surrogate Reset.

surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'.
x =1×2-0.0904 0.7127

Minimize a nonlinear objective function subject to linear inequality constraints. Minimize for 200 function evaluations.

objconstr = @multirosenbrock; nvar = 6; lb = -2*ones(nvar,1); ub = -lb; intcon = []; A = ones(1,nvar); b = 3; Aeq = []; beq = []; options = optimoptions('surrogateopt','MaxFunctionEvaluations',200); [sol,fval,exitflag,output] =...surrogateopt(objconstr,lb,ub,intcon,A,b,Aeq,beq,options)

Figure Optimization Plot Function contains an axes object. The axes object with title Best Function Value: 2.06444 contains an object of type line. This object represents Best function value.

surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'.
sol =1×60.1404 0.0203 0.3112 0.1215 0.1271 0.0329
fval = 2.0644
exitflag = 0
output =struct with fields:elapsedtime: 19.0752 funccount: 200 constrviolation: 0 ineq: [1x0 double] rngstate: [1x1 struct] message: 'surrogateopt stopped because it exceeded the function evaluation limit set by ...'

Create a problem structure representing the six-hump camel back function in the region-2.1 <= x(i) <= 2.1. Set 120 as the maximum number of function evaluations.

rngdefault% For reproducibilityobjconstr = @(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); options = optimoptions('surrogateopt','MaxFunctionEvaluations',120); problem = struct('objective',objconstr,...'lb',[-2.1,-2.1],...'ub',[2.1,2.1],...'options',options,...'solver','surrogateopt'); x = surrogateopt(problem)

Figure Optimization Plot Function contains an axes object. The axes object with title Best Function Value: -1.03163 contains an object of type line. This object represents Best function value.

surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'.
x =1×20.0895 - -0.7130

Minimize the six-hump camel back function and return both the minimizing point and the objective function value. Set options to suppress all other display.

rngdefault% For reproducibilityobjconstr = @(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); lb = [-2.1,-2.1]; ub = -lb; options = optimoptions('surrogateopt','Display','off','PlotFcn',[]); [x,fval] = surrogateopt(objconstr,lb,ub,options)
x =1×20.0895 - -0.7130
fval = -1.0316

Monitor the surrogate optimization process by requesting thatsurrogateoptreturn more outputs. Use the'surrogateoptplot'plot function. To understand the'surrogateoptplot'plot, seeInterpret surrogateoptplot.

rngdefault% For reproducibilityobjconstr = @(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); lb = [-2.1,-2.1]; ub = -lb; options = optimoptions('surrogateopt','PlotFcn','surrogateoptplot'); [x,fval,exitflag,output] = surrogateopt(objconstr,lb,ub,options)

Figure Optimization Plot Function contains an axes object. The axes object with title Best: -1.03163 Incumbent: 0.750489 Current: 12.2879 contains 6 objects of type line. These objects represent Best, Incumbent, Random Samples, Adaptive Samples, Surrogate Reset.

surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'.
x =1×20.0895 - -0.7130
fval = -1.0316
exitflag = 0
output =struct with fields:elapsedtime: 45.0007 funccount: 200 constrviolation: 0 ineq: [1x0 double] rngstate: [1x1 struct] message: 'surrogateopt stopped because it exceeded the function evaluation limit set by ...'

Conclude a surrogate optimization quickly by setting a small maximum number of function evaluations. To prepare for the possibility of restarting the optimization, request all solver outputs.

rngdefault% For reproducibilityobjconstr = @(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); lb = [-2.1,-2.1]; ub = -lb; options = optimoptions('surrogateopt','MaxFunctionEvaluations',20); [x,fval,exitflag,output,trials] = surrogateopt(objconstr,lb,ub,options);

Figure Optimization Plot Function contains an axes object. The axes object with title Best Function Value: -0.124304 contains an object of type line. This object represents Best function value.

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

Optimize for another 20 function evaluations, starting from the previously evaluated points.

options.InitialPoints = trials; [x,fval,exitflag,output,trials] = surrogateopt(objconstr,lb,ub,options);

Figure Optimization Plot Function contains an axes object. The axes object with title Best Function Value: -0.99861 contains an object of type line. This object represents Best function value.

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

By comparing the plots of these 40 function evaluations to those inSearch for Global Minimum, you see that restarting surrogate optimization is not the same as having the solver run continuously.

To enable restarting surrogate optimization due to a crash or any other reason, set a checkpoint file name.

opts = optimoptions('surrogateopt','CheckpointFile','checkfile.mat');

Create an optimization problem and set a small number of function evaluations.

rngdefault% For reproducibilityobjconstr = @(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); lb = [-2.1,-2.1]; ub = -lb; opts.MaxFunctionEvaluations = 30; [x,fval,exitflag,output] = surrogateopt(objconstr,lb,ub,opts)

Surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'.
x =1×20.0067 -0.7343
fval = -0.9986
exitflag = 0
output =struct with fields:elapsedtime: 28.7221 funccount: 30 constrviolation: 0 ineq: [1×0 double] rngstate: [1×1 struct] message: 'Surrogateopt stopped because it exceeded the function evaluation limit set by ↵'options.MaxFunctionEvaluations'.'

Set options to use 100 function evaluations (which means 70 more than already done) and restart the optimization.

opts.MaxFunctionEvaluations = 100; [x2,fval2,exitflag2,output2] = surrogateopt('checkfile.mat',opts)

Surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'.
x2 =1×20.0895 - -0.7130
fval2 = -1.0316
exitflag2 = 0
output2 =struct with fields:elapsedtime: 159.2411 funccount: 100 constrviolation: 0 ineq: [1×0 double] rngstate: [1×1 struct] message: 'Surrogateopt stopped because it exceeded the function evaluation limit set by ↵'options.MaxFunctionEvaluations'.'

Input Arguments

collapse all

Objective function and nonlinear constraint, specified as a function handle or function name.objconstraccepts a single argumentx, wherexis typically a row vector. However, when theVectorizedoption istrue,xis a matrix containingoptions.BatchUpdateIntervalrows; each row represents one point to evaluate.objconstrreturns one of the following:

  • Real scalarfval = objconstr(x).

  • Structure. If the structure contains the fieldFval, thensurrogateoptattempts to minimizeobjconstr(x).Fval. If the structure contains the fieldIneq, thensurrogateoptattempts to make all components of that field nonpositive:objconstr(x).Ineq <= 0for all entries.objconstr(x)must include either theFvalorIneqfields, or both.surrogateoptignores other fields.

When theVectorizedoption istrueand theBatchUpdateIntervalis greater than one,objconstroperates on each row ofxand returns one of the following:

  • Real vectorfval = objconstr(x).fvalis a column vector withoptions.BatchUpdateIntervalentries (or fewer for the last function evaluation whenBatchUpdateIntervaldoes not evenly divideMaxFunctionEvaluations).

  • Structure with vector entries. If the structure contains the fieldFval, thensurrogateoptattempts to minimizeobjconstr(x).Fval, andobjconstr(x).Fvalis a vector of lengthBatchUpdateInterval(or less). If the structure contains the fieldIneq, thensurrogateoptattempts to make all components of that field nonpositive:objconstr(x).Ineq <= 0for all entries, andobjconstr(x).Ineqcontains up toBatchUpdateIntervalentries.

The objective functionobjconstr.Fvalcan be empty ([]), in which casesurrogateoptattempts to find a point satisfying all the constraints. SeeSolve Feasibility Problem.

使用nonli为例子near constraint, seeSolve Problem with Nonlinear Constraints,Surrogate Optimization with Nonlinear Constraint, andSolve Feasibility Problem. For information on converting between thesurrogateoptstructure syntax and other solvers, seepackfcnandConvert Nonlinear Constraints Between surrogateopt Form and Other Solver FormsFor an example using vectorized batch evaluations, seeVectorized Surrogate Optimization for Custom Parallel Simulation.

Data Types:function_handle|char|string

Lower bounds, specified as a finite real vector.lbrepresents the lower bounds element-wise inlbxub. The lengths oflbandubmust be equal to the number of variables thatobjconstraccepts.

Caution

Althoughlbis optional for most solvers,lbis a required input forsurrogateopt.

Note

surrogateoptallows equal entries inlbandub. For eachiinintcon, you must haveceil(lb(i)) <= floor(ub(i)). SeeConstruct Surrogate Details.

Example:lb = [0;-20;4]meansx(1) ≥ 0,x(2) ≥ -20,x(3) ≥ 4.

Data Types:double

Upper bounds, specified as a finite real vector.ubrepresents the upper bounds element-wise inlbxub. The lengths oflbandubmust be equal to the number of variables thatobjconstraccepts.

Caution

Althoughubis optional for most solvers,ubis a required input forsurrogateopt.

Note

surrogateoptallows equal entries inlbandub. For eachiinintcon, you must haveceil(lb(i)) <= floor(ub(i)). SeeConstruct Surrogate Details.

Example:ub = [10;-20;4]meansx(1) ≤ 10,x(2) ≤ -20,x(3)≤4.

Data Types:double

Integer variables, specified as a vector of positive integers with values from1to the number of problem variables. Each value inintconrepresents anxcomponent that is integer-valued.

Example:To specify that the even entries inxare integer-valued, setintconto2:2:nvars.

Data Types:double

Linear inequality constraints, specified as a real matrix.Ais anM-by-nvarsmatrix, whereMis the number of inequalities.

Aencodes theMlinear inequalities

A*x <= b,

wherexis the column vector ofnvarsvariablesx(:), andbis a column vector withMelements.

For example, to specify

x1+ 2x2≤ 10
3x1+ 4x2≤ 20
5x1+ 6x2≤ 30,

give these constraints:

A = [1,2;3,4;5,6]; b = [10;20;30];

Example:To specify that the control variables sum to 1 or less, give the constraintsA = ones(1,N)andb = 1.

Data Types:double

Linear inequality constraints, specified as a real vector.bis anM-element vector related to theAmatrix. If you passbas a row vector, solvers internally convertbto the column vectorb(:).

bencodes theMlinear inequalities

A*x <= b,

wherexis the column vector ofNvariablesx(:), andAis a matrix of sizeM-by-N.

For example, to specify

x1+ 2x2≤ 10
3x1+ 4x2≤ 20
5x1+ 6x2≤ 30,

give these constraints:

A = [1,2;3,4;5,6]; b = [10;20;30];

Example:To specify that the control variables sum to 1 or less, give the constraintsA = ones(1,N)andb = 1.

Data Types:double

Linear equality constraints, specified as a real matrix.Aeqis anMe-by-nvarsmatrix, whereMeis the number of equalities.

Aeqencodes theMelinear equalities

Aeq*x = beq,

wherexis the column vector ofNvariablesx(:), andbeqis a column vector withMeelements.

For example, to specify

x1+ 2x2+ 3x3= 10
2x1+ 4x2+x3= 20,

give these constraints:

Aeq = [1,2,3;2,4,1]; beq = [10;20];

Example:To specify that the control variables sum to 1, give the constraintsAeq = ones(1,N)andbeq = 1.

Data Types:double

Linear equality constraints, specified as a real vector.beqis anMe-element vector related to theAeqmatrix. If you passbeqas a row vector, solvers internally convertbeqto the column vectorbeq(:).

beqencodes theMelinear equalities

Aeq*x = beq,

wherexis the column vector ofNvariablesx(:), andAeqis a matrix of sizeMeq-by-N.

For example, to specify

x1+ 2x2+ 3x3= 10
2x1+ 4x2+x3= 20,

give these constraints:

Aeq = [1,2,3;2,4,1]; beq = [10;20];

Example:To specify that the control variables sum to 1, give the constraintsAeq = ones(1,N)andbeq = 1.

Data Types:double

Options, specified as the output ofoptimoptions.

For more information, seeSurrogate Optimization Options.

Option Description Values
BatchUpdateInterval
  • Number of function evaluations before the surrogate is updated.

  • Number of points to pass in a vectorized evaluation. WhenUseVectorizedistrue,surrogateoptpasses a matrix of sizeBatchUpdateInterval-by-nvar, wherenvaris the number of problem variables. Each row of the matrix represents one evaluation point. Output functions and plot functions are updated after each batch is evaluated completely.

Positive integer. Default is1.

CheckpointFile

File name for checkpointing and restarting optimization. The file has the.matdata type. SeeWork with Checkpoint Files.

Checkpointing takes time. This overhead is especially noticeable for functions that otherwise take little time to evaluate.

File name or file path, given as a string or character array. If you specify a file name without a path,surrogateoptsaves the checkpoint file in the current folder.

ConstraintTolerance Tolerance on nonlinear constraints, measured as the maximum of all nonlinear constraint function values, where positive values indicate a violation. This tolerance is an absolute (not relative) tolerance; seeTolerances and Stopping Criteria. Positive scalar. Default is1e-3.
Display

Level of display returned at the command line.

  • 'final'(default) — Exit message at the end of the iterations.

  • 'off'or the equivalent'none'— No display.

  • 'iter'— Iterative display; seeCommand-Line Display.

InitialPoints Initial points for solver.

Matrix of initial points, where each row is one point. Or, a structure with fieldX, whose value is a matrix of initial points, and these optional fields:

  • Fval, a vector containing the values of the objective function at the initial points

  • Ineq, a matrix containing nonlinear inequality constraint values

SeeAlgorithm Control. Default is[].

MaxFunctionEvaluations

Maximum number of objective function evaluations, a stopping criterion.

Positive integer. Default ismax(200,50*nvar), wherenvaris the number of problem variables.
MaxTime Maximum running time in seconds. The actual running time can exceedMaxTimebecause of the time required to evaluate an objective function or because of parallel processing delays. Positive scalar. Default isInf.
MinSampleDistance Minimum distance between trial points generated by the adaptive sampler. SeeSurrogate Optimization Algorithm. Positive scalar. Default is1e-3.
MinSurrogatePoints

Minimum number of random sample points to create at the start of a surrogate creation phase. SeeSurrogate Optimization Algorithm.

WhenBatchUpdateInterval> 1, the minimum number of random sample points used to create a surrogate is the larger ofMinSurrogatePointsandBatchUpdateInterval.

Integer at leastnvar+ 1. Default ismax(20,2*nvar), wherenvaris the number of problem variables.
ObjectiveLimit Tolerance on the objective function value. If a calculated objective function value of a feasible point is less thanObjectiveLimit, the algorithm stops. 标量值的两倍。默认是-Inf.
OutputFcn Output function to report on solver progress or to stop the solver. SeeOutput Function. Function name, function handle, or cell array of function names or handles. Default is[].
PlotFcn

Plot function to display solver progress or to stop solver. SeePlot Function.

Function name, function handle, or cell array of function names or handles. Built-in plot functions are:

  • 'optimplotfvalconstr'(默认),情节最好的可行的客观功能ion value found as a line plot. If there is no objective function, plot the maximum nonlinear constraint violation as a line plot.

    • The plot shows infeasible points as red and feasible points as blue.

    • If there is no objective function, the plot title shows the number of feasible solutions.

  • 'optimplotfval'— Plot the best objective function value found as a line plot.

  • 'optimplotx'— Plot the best solution found as a bar chart.

  • 'surrogateoptplot'— Plot the objective function value at each iteration, showing which phase of the algorithm produces the value and the best value found both in this phase and overall. SeeInterpret surrogateoptplot.

UseParallel

Boolean value indicating whether to compute objective function values in parallel.

You cannot specify bothUseParallel = trueandUseVectorized = true. If you set both totrue, the solver ignoresUseVectorizedand attempts to compute in parallel using a parallel pool, if possible.

Boolean. Default isfalse. For algorithmic details, seeParallel surrogateopt Algorithm.
UseVectorized

Boolean value indicating whether to compute objective function values in batches of sizeBatchUpdateInterval.

You cannot specify bothUseParallel = trueandUseVectorized = true. If you set both totrue, the solver ignoresUseVectorizedand attempts to compute in parallel using a parallel pool, if possible.

Boolean. Default isfalse. For an example, seeVectorized Surrogate Optimization for Custom Parallel Simulation.

Example:options = optimoptions('surrogateopt','Display','iter','UseParallel',true)

Problem structure, specified as a structure with these fields:

  • objective— Objective function, which can include nonlinear constraints, specified as a function name or function handle

  • lb— Lower bounds forx

  • ub— Upper bounds forx

  • solver'surrogateopt'

  • Aineq— Matrix for linear inequality constraints (optional)

  • bineq— Vector for linear inequality constraints (optional)

  • Aeq— Matrix for linear equality constraints (optional)

  • beq— Vector for linear equality constraints (optional)

  • options— Options created withoptimoptions

  • rngstate— Field to reset the state of the random number generator (optional)

  • intcon— Field specifying integer-valuedxcomponents (optional)

Note

Theseproblemfields are required:objective,lb,ub,solver, andoptions.

Data Types:struct

Path to a checkpoint file, specified as a string or character vector. A checkpoint file has the.matextension. If you specify a file name without a path,surrogateoptuses a checkpoint file in the current folder.

A checkpoint file stores the state of an optimization for resuming the optimization.surrogateoptupdates the checkpoint file at each function evaluation, so you can resume the optimization even whensurrogateopthalts prematurely. For an example, seeRestart Surrogate Optimization from Checkpoint File.

surrogateoptcreates a checkpoint file when it has a validCheckpointFileoption.

You can change some options when resuming from a checkpoint file. Seeopts.

The data in a checkpoint file is in.matformat. To avoid errors or other unexpected results, do not modify the data before callingsurrogateopt.

Warning

Do not resumesurrogateoptfrom a checkpoint file created with a different MATLAB®version.surrogateoptcan throw an error or give inconsistent results.

Example:'checkfile.mat'

Example:"C:\Program Files\MATLAB\docs\checkpointNov2019.mat"

Data Types:char|string

Options for resuming optimization from the checkpoint file, specified asoptimoptionsoptions (from a restricted set) that you can change from the original options. The options you can change are:

  • BatchUpdateInterval

  • CheckpointFile

  • Display

  • MaxFunctionEvaluations

  • MaxTime

  • MinSurrogatePoints

  • ObjectiveLimit

  • OutputFcn

  • PlotFcn

  • UseParallel

  • UseVectorized

Example:opts = optimoptions(options,'MaxFunctionEvaluations',400);

Output Arguments

collapse all

Solution, returned as a real vector.xhas the same length aslbandub.

Objective function value at the solution, returned as a real number.

  • Whenobjconstrreturns a scalar,fvalis the scalarobjconstr(x).

  • Whenobjconstrreturns a structure,fvalis the valueobjconstr(x).Fval, the objective function value atx(if this value exists).

Reasonsurrogateoptstopped, returned as one of the integer values described in this table.

Exit Flag Description

10

Problem has a unique feasible solution due to one of the following:

  • All upper boundsubare equal to the lower boundslb.

  • The linear equality constraintsAeq*x = beqand the bounds have a unique solution point.

surrogateoptreturns the feasible point and function value without performing any optimization.

3 Feasible point found. Solver stopped because too few new feasible points were found to continue.

1

The objective function value is less thanoptions.ObjectiveLimit. This exit flag takes precedence over exit flag10when both apply.

0

The number of function evaluations exceedsoptions.MaxFunctionEvaluationsor the elapsed time exceedsoptions.MaxTime. If the problem has nonlinear inequalities, the solution is feasible.

-1

The optimization is terminated by an output function or plot function.

-2

No feasible point is found due to one of the following:

  • A lower boundlb(i)exceeds a corresponding upper boundub(i). Or one or moreceil(lb(i))exceeds a correspondingfloor(ub(i))for i inintcon. In this case,surrogateoptreturnsx = []andfval = [].

  • lb = uband the pointlbis infeasible. In this case,x = lb, andfval = objconstr(x).Fval.

  • The linear and, if present, integer constraints are infeasible together with the bounds. In this case,surrogateoptreturnsx = []andfval = [].

  • The bounds, integer, and linear constraints are feasible, but no feasible solution is found with nonlinear constraints. In this case,xis the point of least maximum infeasibility of nonlinear constraints, andfval = objconstr(x).Fval.

Information about the optimization process, returned as a structure with these fields:

  • funccount— Total number of function evaluations.

  • elapsedtime——运行时间解算器在几秒钟内,意味着sured bytic/toc.

  • message— Reason why the algorithm stopped.

  • constrviolation— Maximum nonlinear constraint violation, if any.constrviolation = max(output.ineq).

  • ineq— Nonlinear inequality constraint value at the solutionx. Ifobjconstrreturns a structure, thenineq=objconstr(x).Ineq. Otherwise,ineqis empty.

  • rngstate— State of the MATLAB random number generator just before the algorithm starts. Use this field to reproduce your results. SeeReproduce Results, which discusses usingrngstateforga.

Points evaluated, returned as a structure with these fields:

  • X— Matrix withnvarscolumns, wherenvarsis the length oflborub. Each row ofXrepresents one point evaluated bysurrogateopt.

  • Fval— Column vector, where each entry is the objective function value of the corresponding row ofX.

  • Ineq— Matrix with each row representing the constraint function values of the corresponding row ofX.

Thetrialsstructure has the same form as theoptions.InitialPointsstructure. So, you can continue an optimization by passing thetrialsstructure as theInitialPointsoption.

Algorithms

surrogateoptrepeatedly performs these steps:

  1. Create a set of trial points by samplingMinSurrogatePointsrandom points within the bounds, and evaluate the objective function at the trial points.

  2. Create a surrogate model of the objective function by interpolating a radial basis function through all of the random trial points.

  3. Create a merit function that gives some weight to the surrogate and some weight to the distance from the trial points. Locate a small value of the merit function by randomly sampling the merit function in a region around the incumbent point (best point found since the last surrogate reset). Use this point, called the adaptive point, as a new trial point.

  4. Evaluate the objective at the adaptive point, and update the surrogate based on this point and its value. Count a "success" if the objective function value is sufficiently lower than the previous best (lowest) value observed, and count a "failure" otherwise.

  5. Update the dispersion of the sample distribution upwards if three successes occur beforemax(nvar,5)failures, wherenvard的数量吗imensions. Update the dispersion downwards ifmax(nvar,5)failures occur before three successes.

  6. Continue from step 3 until all trial points are withinMinSampleDistanceof the evaluated points. At that time, reset the surrogate by discarding all adaptive points from the surrogate, reset the scale, and go back to step 1 to createMinSurrogatePointsnew random trial points for evaluation.

For details, seeSurrogate Optimization Algorithm.

Alternative Functionality

App

TheOptimizeLive Editor task provides a visual interface forsurrogateopt.

Extended Capabilities

Introduced in R2018b