root icon indicating copy to clipboard operation
root copied to clipboard

[Minuit2] Add interface to pass initial values/cov matrix

Open mdessole opened this issue 1 year ago • 6 comments

This Pull request:

Modifies Minuit2 interface to pass initial error/covariance matrix or second derivatives (G2) vector.

Changes or fixes:

This PR exploits existing code in MnSeedGenerator and introduces some improvements, namely:

  1. Check whether provided matrix has positive diagonal (G2 must be positive) and larger than working precision Eps; if it is not the case, numerical computation is carried out.
  2. Disable NegativeG2LineSearch whenever point 1 is satisfied.

Furthermore, this PR provides an interface to pass the error/covariance matrix or second derivatives (G2) vector via ROOT::Math::Minimizer. The user can provide either the error/covariance matrix in compressed format (column-major upper triangular part), OR the g2 vector, see the code snippet below. The matrix or second derivatives must take into account only variable parameters, implying that all fixed parameters must be declared before providing initial values.

   ROOT::Math::Minimizer* minimum = ROOT::Math::Factory::CreateMinimizer(minName, algoName);

   minimum->SetVariable(0,"x",0.,0.);
   minimum->SetVariable(1,"y",0.,0.);

   int nrow = 2;
   std::vector<double> cov(nrow*(nrow+1)/2);
   std::vector<double> g2(nrow);

   for(int i = 0; i < nrow; i++) {
      g2[i] = 0.1*(i+1);
      for(int j = i;j< nrow;j++)
          cov[i * nrow - (i - 1) * i / 2 + j - i] = (i==j) ? 0.1*(i+1) : 0.;
   }

   minimum->SetCovariance(cov,nrow);
   // OR
   //minimum->SetG2(g2,nrow);

Checklist:

  • [x] tested changes locally
  • [x] updated the docs (if necessary)

mdessole avatar Sep 16 '24 08:09 mdessole

Hi @mdessole, thanks a lot for the PR! There are merge conflicts though. Could you please rebase on master? Thanks!

guitargeek avatar Sep 16 '24 11:09 guitargeek

Test Results

    17 files      17 suites   3d 13h 7m 15s ⏱️  2 700 tests  2 699 ✅ 1 💤 0 ❌ 43 571 runs  43 571 ✅ 0 💤 0 ❌

Results for commit 1a1bc1f2.

:recycle: This comment has been updated with latest results.

github-actions[bot] avatar Sep 16 '24 13:09 github-actions[bot]

It's not great that we have to consider all these redundant overloads. I would suggest getting rid of them first, to keep the interface clean and consistent:

  • https://github.com/root-project/root/pull/16443

What do you think, @lmoneta?

guitargeek avatar Sep 16 '24 18:09 guitargeek

Rebased to re-run on mac15.

dpiparo avatar Sep 17 '24 18:09 dpiparo

Are we missing something to go ahead with this PR?

dpiparo avatar Sep 25 '24 07:09 dpiparo

Hi @guitargeek, @lmoneta! The PR is ready for review, could you please have a look?

mdessole avatar Oct 14 '24 06:10 mdessole