Passing constants to functor, cleaner way to set free variables

I’m attempting to perform numerical minimization, as in https://root.cern.ch/doc/master/NumericalMinimization_8C.html.

Firstly, how can one pass constants to the objective function (e.g. I may wish to minimize some function with a constant parameter that may be set, such as the constants a and b in the Rosenbrock function)?

It looks like SetFixedVariable may be used for this. Is it possible to pass constants by other means (in my case, I may want to pass a std::vector of TVector3’s to the objective function, which will operate on their components, the result of which will ultimately become mathematical constants of the function)?

Secondly, is there a clean way to set a large number of free variables? Currently, I have an array of 12 free variables, and I set them with 12 lines like:

minimizer->SetVariable(0, 'x1', variable[0], step[0]);
...
minimizer->SetVariable(11, 'x11', variable[11], step[11]);

I see SetVariables() in the docs, however I don’t understand it’s usage. It would be nice to e.g. be able to simply pass the array of initial estimates.

Once you define a “free” variable using “ROOT::Math::Minimizer::SetVariable”, you can “fix” it using “ROOT::Math::Minimizer::FixVariable” and “free” it again using “ROOT::Math::Minimizer::ReleaseVariable”.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.