Trouble with plotting iterations in patternsearch optimization

3 ビュー (過去 30 日間)
Jonatan Solanas
Jonatan Solanas 2022 年 8 月 18 日
回答済み: Alan Weiss 2022 年 8 月 19 日
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', '*');
case 'done'
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.
  2 件のコメント
Jonatan Solanas
Jonatan Solanas 2022 年 8 月 18 日
Hello Alan,
The reason I'm using OutputFcn instead of PlotFcn to plot the graph is that the latter plots the graph in a pop-up window and I couldn't figure out a way to pass the graphs of the pop-up window into the UI's graphs. With OutputFcn I easily achieved it.
Additionally, you have talked about 'psplotbestf'. If I have no other choice I will use that graph, but I don't like that I only get 3 iterations with it. Coming from the 'fmincon' algorithm, several more iterations are performed there and I think is more visual for the user to watch the optimization progress if more than 3 iterations are done.
With the code of the OutputFcn I posted I get many more iterations than 3 with the 'patternsearch' algorithm. Probably because of the 'interrupt' case, although I don't really understand what it does. So what I would like to do is get rid of the reset of iterations happening, if it is possible.



Alan Weiss
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.
Alan Weiss
MATLAB mathematical toolbox documentation

その他の回答 (0 件)




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by