# ROOT::Math::Minimizer quastion

Dear Root experts!

I have two questions aboutROOT::Math::Minimizer class:

minimization provides a vector of parameters x [0], x [1] …
in my case the SetLimitedVariable [1] depends on x [0], that is to say : at each iteration I have a new x [0], my limits ss_low, ss_up (see the example below /* … */) depends on the value x [0] given by the minimization.

Can I do a second “min->Minimize();” after recovering my parameters, something like what I write below

``````ROOT::Math::Minimizer* min = ROOT::Math::Factory::CreateMinimizer("Minuit2", "Migrad");
min->SetMaxFunctionCalls(1000000);//1000000
min->SetMaxIterations(10000);
min->SetTolerance(0.001);
min->SetPrintLevel(3);//3 au lieu de -1 pour afficher tout

ROOT::Math::Functor f(&Fcn, 4);
.....
min->SetLimitedVariable(0,"ll",  variable[0], step[0], ll_low, ll_up);
min->SetLimitedVariable(1,"ss",  variable[1], step[1],ss_low, ss_up);
....
// do the minimization
min->Minimize();
const double *xs = min->X();

cout<<"par[0] ="<< xs[0]<<" !par[1] ="<< xs[1]....

/* I want to do somthing like:
ss_low = xs[0] - 3;
ss_up = xs[0] + 3;
min->SetLimitedVariable(0,"ll",  variable[0], step[0], ll_low, ll_up);
min->SetLimitedVariable(1,"ss",  variable[1], step[1],ss_low, ss_up);
min->Minimize(); */
``````

Thank you very much in advance,

Hi,

It should work as you have written. If you have any problems, please let me know

Cheers

Lorenzo

so there is no problem if I make two minimizations as below? (First method)
what I want to do is get the variable [0] after the first iteration and use it in the variable [1] like what I write in the second method (see below), is that possible?:

//first method

``````--------------------------------------------------------------------

//first minimization
min->Minimize();
const double *xs = min->X();

cout<<"par[0] ="<< xs[0]<<" !par[1] ="<< xs[1]....

//retrieve parameters
ss_low = xs[0] - 3;
ss_up = xs[0] + 3;
min->SetLimitedVariable(0,"ll",  variable[0], step[0], ll_low, ll_up);
min->SetLimitedVariable(1,"ss",  variable[1], step[1],ss_low, ss_up);

//second minimization
min->Minimize();
``````

///second method

``````ROOT::Math::Minimizer* min = ROOT::Math::Factory::CreateMinimizer("Minuit2", "Migrad");
min->SetMaxFunctionCalls(1000000);//1000000
min->SetMaxIterations(10000);
min->SetTolerance(0.001);
min->SetPrintLevel(3);//3 au lieu de -1 pour afficher tout

ROOT::Math::Functor f(&Fcn, 4);
.....
min->SetLimitedVariable(0,"ll",  variable[0], step[0], ll_low, ll_up);
ss_low=min->X()[0] - 3;
ss_up=min->X()[0] + 3;
min->SetLimitedVariable(1,"ss",  variable[1], step[1],ss_low, ss_up);
....

// do the minimization
min->Minimize();
const double *xs = min->X();

cout<<"par[0] ="<< xs[0]<<" !par[1] ="<< xs[1]....
``````

Hi Lorenzo,
I obtain this result and the Minimization did NOT converge !!! , I have 6 free parameters,

``````Minuit2Minimizer: Minimize with max-calls 1000000 convergence for edm < 0.001 strategy 1
MnSeedGenerator: for initial parameters FCN = 0.2042598768742
MnSeedGenerator: Initial state:   - FCN =  0.2042598768742 Edm = 0.0529160919757376 NCalls =     25
MnSeedGenerator: Negative G2 found - new state:   - FCN =  0.1194703058954 Edm = 8.08352977319165e-08 NCalls =    197
VariableMetric: start iterating until Edm is < 2e-06
VariableMetric: Initial state   - FCN =  0.1194703058954 Edm = 8.08352977319165e-08 NCalls =    197
VariableMetric: Iteration #   0 - FCN =  0.1194703058954 Edm = 8.08352977319165e-08 NCalls =    197
VariableMetric: Iteration #   1 - FCN =  0.1194701824964 Edm = 5.13330807132362e-08 NCalls =    224
Info in <Minuit2>: MnHesse: 2nd derivative zero for Parameter  : name = dist_12
Info in <Minuit2>: MnHesse fails and will return diagonal matrix
VariableMetric: After Hessian   - FCN =  0.1194701824964 Edm = 5.13330807132362e-08 NCalls =    229
VariableMetric: Iteration #   2 - FCN =  0.1194701824964 Edm = 5.13330807132362e-08 NCalls =    229
Number of iterations 3
----------> Iteration 0
FVAL = 0.119470305895 Edm = 8.08352977319e-08 Nfcn = 197
Error matrix change = 1
Parameters :  p0 = 13 p1 = 7.50000014787254 p2 = 8.73013145502175 p3 = 5.33246923288788 p4 = 15 p5 = 4
----------> Iteration 1
FVAL = 0.119470182496 Edm = 5.13330807132e-08 Nfcn = 224
Error matrix change = 0.503243359804529
Parameters :  p0 = 13 p1 = 7.50000005056474 p2 = 8.73012951736379 p3 = 5.33247330876207 p4 = 15.000000601616 p5 = 4.00006974190362
----------> Iteration 2
FVAL = 0.119470182496 Edm = 5.13330807132e-08 Nfcn = 229
Error matrix change = 1
Parameters :  p0 = 13 p1 = 7.50000005056474 p2 = 8.73012951736379 p3 = 5.33247330876207 p4 = 15.000000601616 p5 = 4.00006974190362
Info in <Minuit2>: Minuit2Minimizer::Minimize : Minimization did NOT converge, Hesse is not valid
Minuit2Minimizer : Invalid Minimum - status = 2
FVAL  = 0.119470182496389
Edm   = 5.13330807132362e-08
Nfcn  = 229
``````

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