Especificar puntos de inicio y valores para surrogateopt
, basado en problemas
Para algunos solvers, puede pasar los valores de la función objetivo y la función de restricción, si los hay, a solve
en el argumento x0
. Esto puede ahorrar tiempo en el solver. Pase un vector de objetos OptimizationValues
. Cree este vector con la función optimvalues
.
Los solvers que pueden utilizar los valores de la función objetivo son los siguientes:
ga
gamultiobj
paretosearch
surrogateopt
Los solvers que pueden utilizar los valores de la función de restricción no lineal son los siguientes:
paretosearch
surrogateopt
Por ejemplo, minimice la función peaks
utilizando surrogateopt
, comenzando por valores de una cuadrícula de puntos iniciales. Cree una cuadrícula desde –10 a 10 en la variable x
y de –5/2
a 5/2
en la variable y
con un espaciado de 1/2. Calcule los valores de la función objetivo en los puntos iniciales.
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); peaksvals = peaks(x0x,x0y);
Pase los valores en el argumento x0
mediante optimvalues
. Esto ahorra tiempo para solve
, ya que solve
no necesita calcular los valores. Pase los valores como vectores fila.
x0 = optimvalues(prob,'x',x0x(:)','y',x0y(:)',... "Objective",peaksvals(:)');
Resuelva el problema utilizando surrogateopt
con los valores iniciales.
[sol,fval,eflag,output] = solve(prob,x0,Solver="surrogateopt")
Solving problem using surrogateopt.
surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'.
sol = struct with fields:
x: 0.2279
y: -1.6258
fval = -6.5511
eflag = SolverLimitExceeded
output = struct with fields:
elapsedtime: 19.2871
funccount: 200
constrviolation: 0
ineq: [1x1 struct]
rngstate: [1x1 struct]
message: 'surrogateopt stopped because it exceeded the function evaluation limit set by ...'
solver: 'surrogateopt'
Consulte también
surrogateopt
| solve
| optimvalues