Minimization subject to constrains with Tminuit, is it possible? [PyROOT]

Dear experts,

I need to minimize a function subject to nonlinear constraints. I heard about Minuit, and that it is a great tool. But I read some old forums [2001-2003] where it was said that the Minuit cannot handle constraints. Since then has minimization subject to constraints been implemented in any way in Minuit? I know that in some cases you could use Lagrange multipliers, but I don’t think that will work on the equations that I need to minimize.

Best Regards,
Cesar.

I am sure @moneta can help you, but have you looked at Roofit ?

1 Like

Hi @couet , i heard about Roofit but I never really used it. Is it a good tool for minimization?

Yes I think so :smiley:

1 Like

Ok, thank you! I’ll have a look at it. Does it work in c++ and python, or just c++? And do you happen to know if there is some tutorial or example for a minimization subject to multiple constraints?

On the page I sent you there is link to the tutorials.
Yes it works with C++ and python

1 Like

Hi Cesar,

Yes, Minuit is a fantastic tool to minimize functions and of course it can handle
constrains on the fitting parameters.

Generally speaking it is used by several ROOT classes, like the TH1,2,…
to fit functions to data distributions by minimizing a sum of squares (chisquare, Gaussian data scatter) or a log likelihood function determined by counting/Poisson statistics. These convenient class interfaces do not allow parameter constrains. In that case you will have to define your own function that has to be minimized.

Have a look at a tutorial that uses from the TMinuit class the SetFCN() function, like for instance fit2dHist.C .

In this example a function called “myFCN” is declared and its value is further on minimized as a function of some parameters.

So how to build in constraints ?..

Sticking to this histogram example the function to be minimized is a sum of squares of the difference between the data and a function:

chi2_unconstr = Sum_i=0^n (y_i - f(x_i,a_j))^2 where a_j=0,m are the parameters to be fitted.

In case your parameter constrain can be expressed in a functional form like:

g(a_j) = c, where g is some arbitrary function and c a constant,

You can install this parameter constrain through a Lagrangian multiplier in your fit

chi2_constr = chi2_unconstr + lambda (g(a_j)-c)

So redefine your function with this new fitting parameter lambda. If you have more constraints just add more parameters.

If your constrain has the form g(a_j) <= c, you will enter more difficult territory. If the function to be minimized is quadric in the parameters a_j you can use the quadratic programming implementation in ROOT, see the tutorial portfolio.C

-Eddy

1 Like

Thank you @Eddy_Offermann ! I try to work on this now.