TMinuit: fit function depends on iteration number

I’m writing a TMinuit minimization scheme in which the value of the fit function itself depends explicitly on the iteration time. Does anyone have experience doing this? I have read quickly the TMinuit data members, and I find public:
Int_t fNfcn Number of calls to FCN
Is this what I’m looking for? Can I directly use fNfcn inside of my fit function: gMinuit.fNfcn ?
Thanks!

Hi,

I don’t understand why your fit function should depend on the number of iterations. gMinuit->fNfcn is the number of function calls which is related to the number of iterations and is probably what you need. The actual number of iterations is not stored in TMInuit.

Regards,

Lorenzo

Thanks, Lorenzo. My fit function has an interaction potential that is modeled as a Lorentzian with width that decreases over iteration time in order to avoid landing in a spurious local minima. I’ll try gMinuit->fNfcn and see if it works. Do you know any reason why the number of function calls would only be related to (and not equal to) the number of iterations? It seems that one iteration should involve only one function call, to evaluate the function at the current parameter values.

Hi,
during one iteration the function is evaluated and also the gradient vector which requires at least 2 other function evaluation/parameter. In addition Minuit performs a line search (minimization in one dimension), which
requires some extra function calls.
Also Minuit might compute before iterating and at the end the second derivatives (Hessian matrix) which require some extra function calls.

So, if your function depends on gMinuit->fNfcn you risk to screw up the gradient calculation and/or the line search in Minuit. I have doubts your approach will work

Best Regards

Lorenzo

Hi Lorenzo,
I don’t understand why you say[quote]The actual number of iterations is not stored in TMInuit.
[/quote]
If I am able to tell Minuit the maximum number of iterations to attempt, there must be an internal counter that stops when it reaches the maximum. Why not have a public method to allow the user to access this internal counter?
Thanks!

Hi,
you are able to tell Minuit the maximum number of function calls and not the number of iterations. This is what stops eventually Minuit iterating.

Lorenzo

Hi Lorenzo,
Thanks for clearing that up. It seems clear now that fNfcn will not work for this application. From the last time I used Minuit (admittedly, three years ago) I seem to recall that in verbose mode Minuit would print a summary to screen after each iteration. I will attempt to create my own iteration counter based on this output, or whatever triggers the output.
Thanks!

Hi,

in the debug mode (print level=3) TMinuit print the result of each iteration. You can probably patch
TMinuit::mnmigr() (the Migrad routine) to detect when a new iteration happens

Lorenzo

Hi,

To revisit this topic (using Minuit2 instead of TMinuit), I see in
root.cern.ch/root/html/ROOT__Min … mizer.html
that there are two separate options to set, one for max iterations and one for max function calls:
void ROOT::Math::Minimizer::SetMaxFunctionCalls(unsigned int maxfcn)
void ROOT::Math::Minimizer::SetMaxIterations(unsigned int maxiter)

I understand that there are multiple function calls within each iteration, so I can’t simply keep track of my own counter on my fit function. Since one can SetMaxIterations, is it possible for the user to do something equivalent to “GetCurrentIteration” in Minuit2?

Hi,

MInuit2 is like Minuit. MaxIteration is available in the general Minimizer interface, but it is not implemented.
What is used is MaxFunctionCalls.
It is possible to retrieve the number of iterations, but only at the end. It would need some changes in the code to have this. I would need to add a method like Iterate() in the Minuit2 minimizer which performs one iteration step

Lorenzo