How can I plot each iteration of optimization function variables while retaining a fixed quantity of prior iterations on the same plot?
Ältere Kommentare anzeigen
I am using fmincon to minimize f(x) and dynamically plotting x each time a new x is tried. In my case, x is basically an array of points in a 2D. My intent is to be able to observe the evolution of x throughout the process by plotting new x over the previous ones. Since the plot becomes uselessly cluttered after hundreds (or thousands) of iterations (and greatly slows down execution), I'm wondering if there is a way to dynamically discard (remove from the figure) iterations < n-k, where n is the current iteration, and k is some quantity of prior iterations that remain. I want to observe how the points move around the design space, each point having a trail of the last k iterations. I don't need to retain the values for each iterations, just want to see the progress as the code runs.
Here is an outline of how I have the code set up:
- Main script which sets x0, bounds, and calls a function ObjConstr
- ObjConstr does three things: (1) sets up the figure properties; (2) Calls fmincon using nested objective and constraint function exactly as described here; and (3) calls a functon PlotFun for each new x
- PlotFun takes x, does some basic manipulations on it, then plots to the figure
It works fast, until the plot gets too cluttered and it slows to a crawl, so my idea is to only retain x0 and the last k iterations of x. I'm guessing it might be necessary to store x for the k iterations, and then only plot them together, wait until the next k iterations are obtained, then clear the plot and re-plot the new iterations. I could use a consistent color scheme for the iterations to make the sequence apparent. But that's not quite what I want. Is there an efficient way to simply drop the earliest retained iteration each time a new x is plotted, without storing the x values?
If this is impractical then I would appreciate suggestions/examples for alternate means of visualizing the progress. I've considered some type of histogram, but really would like to see the points in coordinate space. I am still somewhat novice user, so I may be missing something dead simple.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Graphics Performance finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

