Trouble with plotting iterations in patternsearch optimization
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jonatan Solanas
el 18 de Ag. de 2022
Respondida: Alan Weiss
el 19 de Ag. de 2022
Hello, I am currently trying to plot the optimization progress of a problem using the patternsearch algorithm.
Specifically, I want to plot the objective function value acheived with every iteration. Since I want to plot it in a UI using App Designer I am using an Output Function to do so.
Here is the code to the output function:
function [stop,options,optchanged] = outFcn(app,optimvalues,options,flag)
stop = false;
optchanged = false;
switch flag
case 'init'
hold (app.UIAxes2, "on");
case {'iter','interrupt'}
scatter(app.UIAxes2, optimvalues.iteration, optimvalues.fval, 36, 'red', '*');
drawnow
case 'done'
hold (app.UIAxes2, "off");
end
end
The trouble I am having is that after a certain number of iterations (properly plotted), the iteration number suddenly starts back from 0. This is not convenient for the plotting since then some different points overlap as they have the same iteration number.
I have tried leaving only 'iter' in its case call, but then it only shows like 3 iterations in the graph. And leaving only 'interrupt' brings pretty much the same result as with the code above.
So I have basically two questions:
- Why do only 3 iterations appear when using only 'iter' and why more appear when using both 'iter' and 'interrupt'?
- Even though it is probably not the most accurate thing, I would like to do the following: instead of plotting directly the optimvalues.iteration value (which eventually resets), I would like to plot a kind of cumulative iteration count. So that when the iteration value resets to zero, the following points aren't plotted again at 0,1,2... but rather continuing after the last iteration number before the reset, e.g. 12,13,14...
I find it hard to get the latter working since everything inside the output function resets with every iteration and so I can't think of a way to code an iteration count as I would like it. I would much appreciate if you could help me with that.
Thanks in advance.
2 comentarios
Alan Weiss
el 18 de Ag. de 2022
I don't know anything about App Designer. But I wonder what happens if instead of an output function you tried to use one of the built-in plot functions such as 'psplotbestf'.
Alan Weiss
MATLAB mathematical toolbox documentation
Respuesta aceptada
Alan Weiss
el 19 de Ag. de 2022
I think that what is going on is that you have nonlinear constraints in your problem. When there are nonlinear constraints, patternsearch (and ga) take very few major iterations. Most of their computations are done in solving the resulting subproblems. See Nonlinear Constraint Solver Algorithm. So what you are plotting in the 'interrupt' state is not the iterations for the most part, but the subproblem iterations, which might not be what you want.
For an example showing how the number of solver iterations decreases in the presence of nonlinear constraints, see Constrained Minimization Using patternsearch and Optimize Live Editor Task.
Alan Weiss
MATLAB mathematical toolbox documentation
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!