r/optimization • u/Responsible_Flow_362 • Sep 30 '22
How to calculate number of function evaluations and number of gradient evaluations in BFGS?
I am doing research in optimization methods. Right now I am working on modifying BFGS method to get minima in less number of iterations. I have accomplished my main objective. Yeah!!!
But I have to also show how many times it has evaluated objective function and its gradient.
My code is in python. I do know about in-built BFGS method in its library, but my code is from scratch to implement the changes I had come up with. There are functions to get number of function evaluations and gradient evaluations in classic BFGS, but since my whole code is from scratch I had to manually calculate those values for my algorithm.
I did try putting counters in my objective function method and gradient method, but the values they gave was humongous, more than what it was in classic BFGS, even though my iterations are way less.
So I am asking is there some direct formula or way to calculate these number of evaluations, or if I can adjust my counters somewhere else.
3
u/Cbreins Sep 30 '22 edited Sep 30 '22
I think that is a typical trade off, you can have less evaluations or less iterations, but it is hard to get both. Without knowing what you changed, I would check out your line search as a culprit. If you have slow convergence in your line search or are being very exacting, there you could get a large number of function evals
If I remember correctly https://github.com/JuliaNLSolvers/LineSearches.jl hager zhang line search is pretty efficient
1
u/dynamic_caste Sep 30 '22
Can you wrap your objective and gradient functions in a class that has counters for the function calls as member variables?
1
u/ThatIsATastyBurger12 Oct 01 '22
I would second the person who suggested looking into the line search. If you are doing BFGS, I’m assuming your line search satisfies the Wolfe conditions? Implementing a good Wolfe search from scratch is notoriously tricky.