Minuit fit problem with large statistics

Hi,

I am using my code, implementing the FCN through the FCNBase, basically following this prescription:

https://root.cern.ch/root/htmldoc/guides/minuit2/Minuit2.html#the-users-mboxfcn

Specifically, to build the likelihood I am using the Poisson likelihood chi-square in page 3 of the following reference:

where I add penalty terms to take into account the systematic deviation of the parameters. The predicted number of events for each bin is computed by weighting the MC templates with the parameters.

I do not know if there is a more safe way to implement the likelihood.

Thanks for your help.

Hi,

The procedure is fine, I hope you compute directly the log , i.e. the sum of mu-n*log(mu) for each bin where mu is the number of expected events and n the number of observed ones.
When summing I would reccmend using the Kahan summation, which minimise the numerical error in the sum. We have a class for doing it in ROOT,
see https://root.cern.ch/doc/master/classROOT_1_1Math_1_1KahanSum.html
This might help in computing the likelihood with more precision

Lorenzo

Hello,

yes, I compute the terms for each bin, but I sum them within a for loop. I perform also other sum in for loops, for instance to get the predicted events for each bin.

Moreover, I directly multiply a matrix M (TMatrixD) and vector v (TVectorD) to get the penalty term (something like v* M*v). I will replace this operation and the summation within the for loops with the Kahan summation and post the result of the test.

Thanks for the suggestion.

Antonio

Hi,

I am still experiencing the same problem.

To simplify I just consider the Poisson terms (switching off the penalty constributions), so I am performing the Kahan sum of mu - n + n*log(n/mu) terms (mu is the number of expected events and n the number of observed ones).

The output in this case is the one I reported below, and the profile likelihood looks like this around the minimum:

Maybe the approach of using a binned fit doen not work in this case? But I can only build a binned likelihood.

Thanks for other suggestions.

Antonio

OUTPUT

initial values for parameters of interest:
b0 = 0.7342
b1 = 0.99484

MnSeedGenerator: for initial parameters FCN = 5.874057001141e+13
MnSeedGenerator: Initial state:   - FCN = 5.874057001141e+13 Edm =  1.15797e+14 NCalls =      9
VariableMetric: start iterating until Edm is < 0.002
VariableMetric: Initial state   - FCN = 5.874057001141e+13 Edm =  1.15797e+14 NCalls =      9
VariableMetric: Iteration #   0 - FCN = 5.874057001141e+13 Edm =  1.15797e+14 NCalls =      9
VariableMetric: Iteration #   1 - FCN =     220279841776 Edm =  1.62466e+11 NCalls =     19
VariableMetric: Iteration #   2 - FCN =     123603344472 Edm =  1.64561e+10 NCalls =     27
VariableMetric: Iteration #   3 - FCN =        158279480 Edm =  1.44131e+08 NCalls =     38
VariableMetric: Iteration #   4 - FCN =           224636 Edm =       219745 NCalls =     43
VariableMetric: Iteration #   5 - FCN =               -4 Edm =      5.27001 NCalls =     48
VariableMetric: Iteration #   6 - FCN =               -8 Edm =      3.39937 NCalls =     57
Info: VariableMetricBuilder: no improvement in line search
VariableMetric: Iteration #   7 - FCN =               -8 Edm =      3.39937 NCalls =     59
Info: VariableMetricBuilder: iterations finish without convergence.
Info in VariableMetricBuilder : edm = 7.08092
Info in             requested : edmval = 0.002
VariableMetric: After Hessian   - FCN =               -8 Edm =  3.76771e+08 NCalls =     73
VariableMetric: Iteration #   8 - FCN =               -8 Edm =  3.76771e+08 NCalls =     73
Info: VariableMetricBuilder: Tolerance is not sufficient, continue the minimization
Info in Current  Edm is : edm = 3.76771e+08
Info in Required Edm is : edmval = 0.002
Info: VariableMetricBuilder: no improvement in line search
VariableMetric: Iteration #   9 - FCN =               -8 Edm =  3.76771e+08 NCalls =     84
Info: VariableMetricBuilder: iterations finish without convergence.
Info in VariableMetricBuilder : edm = 3.76771e+08
Info in             requested : edmval = 0.002
Info: VariableMetricBuilder: FunctionMinimum is invalid after second try

Hi,

@moneta or any other expert that might help: do you think there is something else I could try to make the fit work also with such large bin content? Or it might be the case to change method? Like Bayesian with mirginalization of the nusiances, but I am not sure if this wouldn’t reproduce the same problem…

I have also tried to make a sort of internal rebinning (internal to the FCN, by splitting the content of each bin in such a way to reduce the statistics), but this does not seem to help.

Thanks for any other hint.

Antonio

Can you try the summation of mu -n log(mu), it should be better than doing mu -n + n*log(n/m) where you are adding some useless constant term(i.e not depending on mu)

Lorenzo

yes @moneta, sorry. I forgot to mention: I tried to use both mu - nlog(mu) and also a simple chi2 (n - mu)**2/n (since I thought this at the end should be the case given the high statistic). Unfortunatelly in both cases I do not solve the problem.

For the simple chi2 it “seems” that the fit converges (see below), but when I perform the profiling I get a shifted minimum (should be b0 = 0.6 from the fit, and the same thing happens for b1):

I really don’t understand what is going on.

Thanks again for the suggestions.

Antonio

Initial parameter values:

b0 = 0.7342
b1 = 0.99484
c0 = 0.91775
c1 = 0.65241
c2 = 1.01901
c3 = 0.8635

MnSeedGenerator: for initial parameters FCN = 1.945697553707e+14
MnSeedGenerator: Initial state:   - FCN = 1.945697553707e+14 Edm =  4.40091e+14 NCalls =     27
VariableMetric: start iterating until Edm is < 2e-06
VariableMetric: Initial state   - FCN = 1.945697553707e+14 Edm =  4.40091e+14 NCalls =     27
VariableMetric: Iteration #   0 - FCN = 1.945697553707e+14 Edm =  4.40091e+14 NCalls =     27
VariableMetric: Iteration #   1 - FCN = 1.362416550105e+13 Edm =  1.35221e+13 NCalls =     53
VariableMetric: Iteration #   2 - FCN =   237058177783.3 Edm =  1.62261e+11 NCalls =     73
VariableMetric: Iteration #   3 - FCN =   1487606218.203 Edm =  1.24578e+09 NCalls =     89
VariableMetric: Iteration #   4 - FCN =   4156963.927511 Edm =  3.39985e+06 NCalls =    103
VariableMetric: Iteration #   5 - FCN =   3590.370543003 Edm =      3361.52 NCalls =    117
VariableMetric: Iteration #   6 - FCN =   9.874759437987 Edm =      2.73625 NCalls =    131
VariableMetric: Iteration #   7 - FCN =   7.036065324394 Edm =   0.00384476 NCalls =    144
VariableMetric: Iteration #   8 - FCN =   7.032069478253 Edm =  1.33019e-10 NCalls =    157

============= OUTPUT FROM MIGRAD STEP ==============

Minuit did successfully converge.
# of function calls: 157
minimum function Value: 7.032069478253
minimum edm: 1.330190379013e-10
minimum internal state vector: LAVector parameters:
     -0.637718532142
    -0.4142121304884
    -0.9305975012986
      -1.04562659439
     -0.908184829191
    -0.9344208580264

minimum internal covariance matrix: LASymMatrix parameters:
  4.0404906e-15 -3.9281492e-16 -9.6884525e-17  1.1951951e-16 -5.9210979e-17 -1.0756265e-16
 -3.9281492e-16  8.5219684e-16 -3.9946092e-17 -4.3359988e-17 -2.7288428e-17 -6.5379137e-17
 -9.6884525e-17 -3.9946092e-17  1.1088869e-16 -9.4453262e-18 -9.6832698e-18 -3.4046117e-17
  1.1951951e-16 -4.3359988e-17 -9.4453262e-18  8.7585524e-16  2.7277547e-18 -3.4678407e-17
 -5.9210979e-17 -2.7288428e-17 -9.6832698e-18  2.7277547e-18  1.5370099e-16 -1.1733134e-17
 -1.0756265e-16 -6.5379137e-17 -3.4046117e-17 -3.4678407e-17 -1.1733134e-17  3.1034533e-16


# ext. ||   Name    ||   type  ||     Value     ||  Error +/- 

   0   ||        b0 || limited ||     0.6069541004546 ||7.660735923398e-08
   1   ||        b1 || limited ||      0.896296780389 ||4.008557463742e-08
   2   ||        c0 || limited ||     0.9901149782449 ||3.145184113151e-08
   3   ||        c1 || limited ||     0.6738057146488 ||7.41883549038e-08
   4   ||        c2 || limited ||      1.058058068564 ||3.81337058597e-08
   5   ||        c3 || limited ||     0.9787248098882 ||5.234640609864e-08

I am not sure I have understood exactly what is happening here. Are you computing the profile likelihood as function of b0 minimising all other parameters as it is done within Minos ?
Have you tried computing the Minos errors ?
If you can post the program reproducing the problem it would be useful

best regards

Lorenzo

I am not sure I have understood exactly what is happening here. Are you computing the profile likelihood as function of b0 minimising all other parameters as it is done within Minos ?

yes, right. I am building the profile as function of the parameter by fixing it and minimizing w.r.t. all other parameters. This just for a cross-check and to get a feeling of the shape around the minimum.

Have you tried computing the Minos errors ?

yes, I also compute Minos errors, and they look unrealistically small:

1-sigma minos errors: 
par b0: 0.606954 -7.66074e-08 7.66074e-08
par b1: 0.896297 -4.00856e-08 4.00856e-08

If you can post the program reproducing the problem it would be useful

Sure, I will prepare a minimal working example reproducing the problem and post it. It is probable that I am missing something.

Thanks for the support.

Antonio

Hi,

Then when running Minos, it would be interesting to see the log.
But how it is produced the scan plot above showing a minimum for b0 around 0.85 ?

I think such small errors are expected given the large statistics. These Minos error looks to me consistent with the ones obtained from the Hessian matrix.

Lorenzo

Hi,

so, I uploaded a txt file with the log from Minos.

I think such small errors are expected given the large statistics. These Minos error looks to me consistent with the ones obtained from the Hessian matrix.

but then the values of the poi from the fit would be to far away from the true values, I mean, not compatible. It looks more reasonable the minimum from the “manual” scan. Maybe I am getting confused…

When I apply Hesse, I get something that I interpreted as not much reliable, since the covariance matrix status is 2. The log is in OUTPUT-1.

But how it is produced the scan plot above showing a minimum for b0 around 0.85 ?

This is produced by using migrad for each point: the starting point is near the minimum found by the initial minimization (for b0 the value is 0.6), then I iterate for b0 values that move away from the minimum.

Antonio

minos_log.txt (33.9 KB)

OUTPUT-1

============= OUTPUT FROM HESSE STEP ==============

# of function calls: 220
function Value: 7.032069478253
expected distance to the Minimum (edm): 2.970483266889e-10
external parameters: 
# ext. ||   Name    ||   type  ||     Value     ||  Error +/- 

   0   ||        b0 || limited ||     0.6069541004546 ||1.658345941902e-06
   1   ||        b1 || limited ||      0.896296780389 ||7.293672876219e-07
   2   ||        c0 || limited ||     0.9901149782449 ||3.481822086204e-07
   3   ||        c1 || limited ||     0.6738057146488 ||2.383161526454e-07
   4   ||        c2 || limited ||      1.058058068564 ||2.05883902149e-07
   5   ||        c3 || limited ||     0.9787248098882 ||5.936370880977e-07



covariance matrix status: 2
covariance matrix: 
MnUserCovariance: 

  2.75011e-12 -5.67386e-13 -2.31483e-13 -3.73249e-13  5.11066e-15 -6.64132e-13
 -5.67386e-13  5.31977e-13 -1.56523e-13  6.34979e-14 -1.31279e-13 -1.42786e-13
 -2.31483e-13 -1.56523e-13  1.21231e-13  3.80681e-14  6.36851e-14  1.93662e-13
 -3.73249e-13  6.34979e-14  3.80681e-14  5.67946e-14  3.54615e-15  9.92467e-14
  5.11066e-15 -1.31279e-13  6.36851e-14  3.54615e-15  4.23882e-14  8.65851e-14
 -6.64132e-13 -1.42786e-13  1.93662e-13  9.92467e-14  8.65851e-14  3.52405e-13

MnUserCovariance Parameter correlations: 

            1    -0.469091    -0.400902     -0.94443    0.0149685    -0.674618
    -0.469091            1    -0.616348     0.365308    -0.874234    -0.329776
    -0.400902    -0.616348            1     0.458776     0.888401     0.936951
     -0.94443     0.365308     0.458776            1    0.0722739     0.701522
    0.0149685    -0.874234     0.888401    0.0722739            1     0.708434
    -0.674618    -0.329776     0.936951     0.701522     0.708434            1

global correlation coefficients : 
MnGlobalCorrelationCoeff: 

     0.997715
     0.997715
     0.995163
     0.948521
     0.982068
     0.995264



Eigenvalue-0 = 8.31084e-16
Eigenvalue-1 = 1.43441e-15
Eigenvalue-2 = 2.46679e-15
Eigenvalue-3 = 5.61024e-15
Eigenvalue-4 = 7.46583e-13
Eigenvalue-5 = 3.09798e-12

Hi,

Thank you for the log. I see that Minos failed for both b0 and b1 (lower error). I am not sure if the upper error determination works.

The scan figure of chi2 vs b0 cannot be true. The minimum should be at b0 ~ 0.6 and if the error are so small the parabola should be much narrower around the minimum.

I think I would need to run your code to see what is really happening

Lorenzo

Hi @moneta,

I managed to setup a test code that reproduces what I am doing.

Within fitTest, the fN parameter allows to set the normalization coefficient to reproduce the expected statistics for data. There are two values, one for low statistics, where the fit is working (the likelihood profiles are as I would expect them), and one for high statistics, where the fit is showing the behaviour I discussed.

In Chi2FCN there is the possibility to use a simple chi2 or the mu -n + n*log(n/m) (did not manage to make mu - n*log(m) converge).

Thanks,
Antonio

test_code.tar.gz (8.3 KB)

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

Hi,

I see your code performs several fits and many of them fail because of precision issues. It is difficult to me to find the problem mentioned before with Minos.
Can you please simplify the code, so I can exactly reproduce the Minos problem ?
Thank you

Lorenzo

Hi @moneta,

I see your code performs several fits and many of them fail because of precision issues. It is difficult to me to find the problem mentioned before with Minos.

yes, right. The code I provided includes also the likelihood profiling, which performs several fits;

Can you please simplify the code, so I can exactly reproduce the Minos problem ?

yes, I am attaching a new version in which only the fit and Minos analysis are performed;

Thank you,
Antonio

test_code_v2.tar.gz (6.8 KB)

Hello Antonio,

please note the @moneta will be on vacation the next two weeks. If you check in once a week by writing a short message, the topic won’t get closed.

If you have a CERN account, you can also create a JIRA ticket on https://root.cern (button with the bug at the very bottom), and add a link to this thread.

2 Likes

Hi @StephanH,

thanks for the info.

I opened a ticket on JIRA, as you have suggested:

https://sft.its.cern.ch/jira/browse/ROOT-10954

Cheers,
Antonio

1 Like

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