Specify Start Points for MultiStart
, Problem-Based
When solving a problem using MultiStart
in the problem-based approach, you can specify the start points using one or both of these techniques:
Create a vector of
OptimizationValues
objects using theoptimvalues
function. Pass this vector as thex0
argument tosolve
.Set the
MinNumStartPoints
name-value argument when you callsolve
. IfMinNumStartPoints
exceeds the number of points inx0
, thensolve
creates extra points at random within the problem bounds.
Vector of Initial Points
For this example, create the initial points vector as a grid for the variable x
consisting of integer values from –10 through 10, and for the variable y
consisting of half-integer values from –5/2
through 5/2
. The optimvalues
function requires a problem, so create an optimization problem with the objective function peaks(x,y)
.
You must specify the points for optimvalues
so that the dimension (index) of the number of points is last. For example, to give multiple values of a scalar t
with n
points, specify
(This is 1-by-n
, and n
is the last index.)
To give multiple values of a vector variable w
of length 2, specify
(This is 2-by-n
, and n
is the last index.)
This rule holds even for row vectors. In other words, you specify multiple row vectors as if each were a column vector.
To give multiple values of a matrix A
that is 2-by-3, specify
(This is 2-by-3-by-n
, and n
is the last index.)
In the present example, ensure that you specify the multiple values of the scalar variables x
and y
as row vectors, as in the scalar t
example.
x = optimvar("x",LowerBound=-10,UpperBound=10); y = optimvar("y",LowerBound=-5/2,UpperBound=5/2); prob = optimproblem(Objective=peaks(x,y)); xval = -10:10; yval = (-5:5)/2; [x0x,x0y] = meshgrid(xval,yval); % Convert x0x and x0y to row vectors for optimvalues x0 = optimvalues(prob,x=x0x(:)',y=x0y(:)');
Solve the minimization problem starting from all the points in x0
.
ms = MultiStart; [sol,fval,eflag,output] = solve(prob,x0,ms)
Solving problem using MultiStart. MultiStart completed the runs from all start points. All 231 local solver runs converged with a positive local solver exitflag.
sol = struct with fields:
x: 0.2283
y: -1.6255
fval = -6.5511
eflag = LocalMinimumFoundAllConverged
output = struct with fields:
funcCount: 2230
localSolverTotal: 231
localSolverSuccess: 231
localSolverIncomplete: 0
localSolverNoSolution: 0
message: 'MultiStart completed the runs from all start points. ...'
local: [1x1 struct]
objectiveDerivative: "reverse-AD"
constraintDerivative: "closed-form"
globalSolver: 'MultiStart'
solver: 'fmincon'
Random Start Points
Solve the problem again, this time using MultiStart
from 25 random initial points. Set the initial point for solve
to [–1,2]
.
init.x = -1; init.y = 2; rng default % For reproducibility [sol2,fval2,eflag2,output2] = solve(prob,init,ms,MinNumStartPoints=25)
Solving problem using MultiStart. MultiStart completed the runs from all start points. All 25 local solver runs converged with a positive local solver exitflag.
sol2 = struct with fields:
x: 0.2283
y: -1.6255
fval2 = -6.5511
eflag2 = LocalMinimumFoundAllConverged
output2 = struct with fields:
funcCount: 161
localSolverTotal: 25
localSolverSuccess: 25
localSolverIncomplete: 0
localSolverNoSolution: 0
message: 'MultiStart completed the runs from all start points. ...'
local: [1x1 struct]
objectiveDerivative: "reverse-AD"
constraintDerivative: "closed-form"
globalSolver: 'MultiStart'
solver: 'fmincon'
This time, MultiStart
runs from 25 pseudorandom initial points. The solution is the same as before.
See Also
MultiStart
| solve
| optimvalues