# How to get the hessian matrix from Minuit2Minimizer?

Dear experts,

`````` I am minimizing a negative log-likelihood function and I am using Minuit2Minimizer with the migrad algorithm and strategy = 2. Unfortunately, the hessian matrix is forced to be positive definite by adding a positive number to the diagonal elements. I have a suspicion that the intrinsic problem are large correlations between some nuisance parameters as described in these Wouter's slides: https://indico.cern.ch/event/254550/contributions/570045/attachments/445364/617689/atlas-stats-degenll-v2.pdf
I would like to do the analysis suggested by Wouter on p.15 but I can't find a way how to get the hessian matrix. He had a personal function giving him the matrix and I can't see anything like that implemented in https://root.cern.ch/doc/v608/classROOT_1_1Minuit2_1_1MnHesse.html...
I will appreciate your help a lot!
Best regards
``````

Vojtech

Hi,

You can use GetCovMatrix() if you want the covariance matrix (inverse of the Hessian) or GetHessianMatrix if you want the matrix of the second derivatives.
See https://root.cern.ch/doc/master/classROOT_1_1Minuit2_1_1Minuit2Minimizer.html#a886ec378e9bff310ff36930fcbb9d529

In general Minuit2 inverts always internally the Hessian matrix so it
makes normally more sense to get the covariance matrix.

I cannot access those slides, in case send to me privately, so I don’t know which analysis are you refering to.

Best Regards

Lorenzo

Dear Lorenzo,

`````` thank you very much for your answer! Please, find Wouter's slides
``````

in the attachement. According to it, I need the hessian matrix and not
the covariance matrix. Let me ask you one more question about the
hessian matrix returned by
https://root.cern.ch/doc/master/classROOT_1_1Minuit2_1_1Minuit2Minimizer.html#a886ec378e9bff310ff36930fcbb9d529,

• is it the last hessian matrix, i.e. the one that is positive
definite because of having been forced to be so?

Best regards

Vojtech

Dear Lorenzo, all,

``````I've just done the following:
``````

RooMinimizer minim(*nll);
minim.setStrategy(2);
minim.setEps(0.0001);
minim.optimizeConst(2);
ROOT::Minuit2::Minuit2Minimizer m2minim = static_castROOT::Minuit2::Minuit2Minimizer*(minim->fitter()->GetMinimizer());
double h = new double[10n
n];
m2minim->GetHessianMatrix(h);

In the fit, the hessian matrix was forced to be positive definite. With the procedure above, I am retrieving the positive definite matrix (I checked that all its eigenvalues were positive). However, I would like to get the original hessian matrix. Is there a way how to do that? Is there a way how to retrieve the constant that was added to the diagonal elements when forcing the matrix to be pos. def.?
Best regards
Vojtech

Hi,

The original matrix, before making it pos def, I think is deleted. You would need to patch yourself the code in
math/minuit2/src/MnHesse.cxx to store this matrix

Best Regards

Lorenzo

Dear Lorenzo,

`````` thank you very much for your answer!

Just to make 100% sure - is the matrix I get the one that was
``````

forced to be positive definite? (Just in case there was some step in the
middle or so…)

`````` Best regards
``````

Vojtech

Hi,

There are some steps in the middle. The matrix you get is the inverse of the Covariance User matrix which is the one first computed by MnHesse using the second derivatives, then inverted (and made positive) and then transformed from internal to external coordinates in case you have bonds in the parameters

Lorenzo

Dear Lorenzo,

`````` do I understand correctly that it is the covariance matrix that is
``````

made positive definite and not the hessian matrix? Is it possible to say
how much does the matrix I get reflect properties of the original
hessian matrix?

`````` Best regards
``````

Vojtech

Hi,

Actually it is the Hessian matrix made positive defined and then inverted to obtained the covariance matrix, which is stored in the state of Minuit2.

Lorenzo

Dear Lorenzo,
I am sorry for being so slow. Is the order of steps below correct?

1. calculate second derivatives and store them in a matrix (that is called hessian matrix)

2. check whether the hessian matrix is positive definite

3. if the hessian matrix fails the check 2) then add a positive constant to each of its diagonal elements

4. invert the matrix from step 3) to get the covariance matrix

5. store the covariance matrix and delete everything else

6. if user asks for a hessian matrix, invert the covariance matrix from step 5) and pass it to him

Best regards

Vojtech

Dear Vojtech,

The order is correct. There are eventually additional steps in case the parameter are bounded. In this case
transformations on the parameters are applied (e.g. p -> p’ = asin( 2 * (p-a)/(b-a) - 1) ) for a parameter p bound in the interval [a,b].
Minuit uses the internal (unlimited) parameters p’ and then transform it back the covariance matrix returned to the user

Lorenzo

Dear Lorenzo,