optimistix icon indicating copy to clipboard operation
optimistix copied to clipboard

Help with adding (quasi-newton) Davidon–Fletcher–Powell update method?

Open pfackeldey opened this issue 9 months ago • 4 comments

Dear optimistix team,

I'm looking into implementing the Minuit optimizer with optimistix. Python bindings for the (newer) C++ implementation can be found in iminuit. This optimizer is a standard in high-energy physics research and commonly used by physicists at CERN. Our community is currently in the process of trying to port some of our statistical inference tools (e.g. pyhf) towards JAX, and thus like to re-implemented Minuit in JAX aswell.

My (best) understanding of Minuit is that it consists of 2 parts (that - if specified by a user - are automatically switched between):

  1. "MIGRAD": basically the same as optimistix.BFGS, but the update of the hessian (or its inverse) is done by the Davidon-Fletcher-Powell formula instead.
  2. "SIMPLEX": this looks to me exactly like optimistix.NelderMead - so, perfect!

My wish is to implement MIGRAD in optimistix and for this I had a look at the BFGS code. As far as I understand I probably want to keep the whole code and only switch out bfgs_update by a new dfp_update function. Is this assumption correct? If yes, could you give me some hints what things need to be changed? (I have some troubles understanding the PyTree manipulations in the existing bfgs_update code and connect them to the mathematical formula for BFGS.)

In addition, the termination of the minimization is determined in Minuit by the so-called "edm"-measure, which is calculated by: $\text{edm} =\nabla^T H^{-1} \nabla$, where $H^{-1}$ denotes the inverse hessian, see p. 348 in Minuit. I suppose I'd have to add this custom measure and the termination logic inside the step function aswell?

I'd be happy for any tips and help to make this happen, and contribute this (e.g. the dfp_update formula) to optimistix.

Best, Peter

cc @nsmith- and @matthewfeickert

pfackeldey avatar Mar 12 '25 19:03 pfackeldey

We're also thinking about adding L-BFGS here: https://github.com/patrick-kidger/optimistix/issues/116

I think it would be best if we make the update formula a solver attribute? This now makes three different versions of update formulas that are useful in different contexts. Same could go for termination conditions, I'm experimenting with this for constrained solves where optimality error is the typical criterion. We could then default to cauchy_termination in classic BFGS, and make Minuit an extra solver that also inherits from AbstractBFGS.

Regarding the Pytree formulations - it took a little getting used to for me as well, happy to walk you through them anytime!

johannahaffner avatar Mar 12 '25 19:03 johannahaffner

Hi @johannahaffner,

that sounds great! Making the update formula and termination criteria a choice would solve it and follows the composability design for solvers by optimistix (as far as I understood it) :)

Regarding the Pytree formulations - it took a little getting used to for me as well, happy to walk you through them anytime!

Thanks, that would be super helpful! Would you be up for a short (pair-programming) video call?

pfackeldey avatar Mar 12 '25 19:03 pfackeldey

Yes, we could do that early next week! If you're at CERN right now, we could also meet up somewhere in Switzerland.

johannahaffner avatar Mar 12 '25 21:03 johannahaffner

Great, I'll reach out to you via email 👍 Thank you already a lot in advance!

pfackeldey avatar Mar 12 '25 21:03 pfackeldey