How to pass iteration number and f-count to fmincon

5 views (last 30 days)
Hi,
I was wondering if there is any way to pass current number of iteration and number of function evaluations to my objective function using fmincon function. I need that to selectively update some internal parameter if the solver struggles with finding solution (e.g. if it calculates more than 1 finite difference for each parameter within a single iteration)
Cheers, Aleksander

Accepted Answer

Alan Weiss
Alan Weiss on 22 Jul 2016
If you make your objective function explicitly depend on a parameter vector v, then you can make a nested function where v gets updated by a custom output function. I have never tried to do this, but MATLAB is nothing if not flexible, you can generally do whatever you want.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

More Answers (1)

Aleksander Marek
Aleksander Marek on 25 Jul 2016
Okay your solution was really useful, thanks a lot. Another thing I struggle now - since I usually use MultiStart environment for fmincon, if I do the same trick with nested functions now my information about iteration number/fval is 'global'. This obviously makes the process unparalleled so I lose a lot of computing power here. Any idea how could I make similar trick - passing function value from last iteration in particular - so that the optimization still can be run in parallel with multiple starting points? I assume brute force solution would be to run optimization function in parfor loop and bypassing MultiStart command. Any ideas?

Community Treasure Hunt

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

Start Hunting!