Trouble with plotting iterations in patternsearch optimization
3 ビュー (過去 30 日間)
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;
hold (app.UIAxes2, "on");
scatter(app.UIAxes2, optimvalues.iteration, optimvalues.fval, 36, 'red', '*');
hold (app.UIAxes2, "off");
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.
Alan Weiss 2022 年 8 月 19 日
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.
MATLAB mathematical toolbox documentation