Main Content

Initial Points for Global Optimization Toolbox Solvers

Some Global Optimization Toolbox solvers require an initial point x0. When solving optimization problems using the problem-based approach, you specify x0 in the second argument for solve and for prob2struct. To specify an initial point, create a structure with the variable names as fields and variable values as structure values. For example, for a scalar variable x and a 2-by-2 matrix y for the patternsearch solver, enter the following code.

x0.x = 5;
x0.y = eye(2) + 0.1*randn(2);
[sol,fval] = solve(prob,x0,"Solver","patternsearch")

Note

When using the problem-based approach with ga, particleswarm, or surrogateopt, you cannot specify an initial point or population. Instead, convert your problem using prob2struct and then pass the initial point or population in the associated option:

For example, take a 2-D variable x and a 2-by-2 matrix y for the ga solver.

x = optimvar('x',2,"LowerBound",-1,"UpperBound",1);
y = optimvar('y',2,2,"LowerBound",-1,"UpperBound",1);
prob = optimproblem("Objective",...
    cosh(dot(y*x,[2;-1])) - sinh(dot(y*x,[1;-2])));
prob.Constraints = y(1,2) == y(2,1);
problem = prob2struct(prob,"Solver","ga");

% Obtain indices of problem variables
idx = varindex(prob)
idx = 

  struct with fields:

    x: [1 2]
    y: [3 4 5 6]
% Set initial population: x0x for x, x0y for y
rng default
x0x = [1;1/2];
x0y = eye(2)/2 + 0.1*randn(2);
pop = zeros(1,max([idx.x,idx.y])); % Allocate population
pop(idx.x) = x0x(:)'; % Convert to row vector
pop(idx.y) = x0y(:)';
% Place in options
problem.options.InitialPopulationMatrix = pop;
% Solve problem
[sol,fval] = ga(problem)
Optimization terminated: average change in the fitness value less than options.FunctionTolerance.

sol =

    1.0000   -1.0000    0.3080   -1.0000   -0.9990    1.0000


fval =

  -50.4209

The solution satisfies the constraint y(1,2) == y(2,1) only to the constraint tolerance 1e-3: sol(4) = -1.0000, but sol(5) = -0.9990.

See Also

|

Related Topics