Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VariableMetricBuilder warning using migrad() #26

Open
GoogleCodeExporter opened this issue Mar 15, 2015 · 1 comment
Open

VariableMetricBuilder warning using migrad() #26

GoogleCodeExporter opened this issue Mar 15, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

Hi,

I am having trouble using the migrad() command when fitting a curve to data.  I 
have defined the function I am trying to fit as:

## A Fast Rising & Exponentially Decaying function with four parameters###

def fred(t,a,b,c,d):    
            return (a*exp((2*b/c)**.5)*exp(-b/(t-d)-(t-d)/c))


The function I am trying to minimize is the chi2 function:

def chi2(a,b,c,d):
                c2 = (((data - fred(t,a,b,c,d))/dataErr)**2).sum()
            return c2

### creating minuit object ## Initial parameters are best fit using leastsq in 
scipy

m = minuit.Minuit(chi2, a=2.55129e-06, b=95165.9,c=188188,d=253576440.)
m.migrad()



What is the expected output? What do you see instead?

I expect the data to be fitted with the curve and similar parameters to be 
obtained, but instead I get this message after m.migrad() runs:

VariableMetricBuilder: warning: no improvement in line search  
negative or zero diagonal element 1 in covariance matrix
negative or zero diagonal element 2 in covariance matrix
added 0.500001 to diagonal of error matrix


Not exactly why this happens.  I was able to use migrad() with a gaussian and 
sample data and have it work with the same method so i am confused. If someone 
could explain what this means it would help.

What version of the product are you using? On what operating system?
I am using the latest version of pyminuit on Ubuntu Linux




Original issue reported on code.google.com by kcremin%...@gtempaccount.com on 6 Aug 2011 at 1:13

@GoogleCodeExporter
Copy link
Author

This is a Minuit issue, rather than a PyMinuit (interface) issue.  Fitting 
steep functions is always difficult, because the chi^2 function is far from 
parabolic.  (Minuit's MIGRAD algorithm assumes that chi^2 as a function of all 
of its variables is a paraboloid in each iteration, and iterates to correct for 
small departures from that picture.  If the fit function is steep or otherwise 
not well-behaved, there could be large departures from that picture, and the 
fit doesn't converge.)

The way to solve this issue is to try to get the initial parameters as close as 
possible to the real shape (by hand) and, just as importantly, the initial step 
parameters as close as possible to the second derivative matrix.  Even if your 
initial parameters are exactly on the chi^2 minimum, if the step sizes are 
orders of magnitude from the region where the minimum is shaped like a 
paraboloid, MIGRAD's numerical calculation of the second derivative will be far 
from the true second derivative at the minimum.  Another way to do it is to 
algebraically re-express the functional form so that small changes in each 
parameter do not cause large changes in chi^2.

It may sound perverse to say that you need to fit the function by hand before 
you can fit it by computer, but that's how it goes.  No algorithm can 
numerically find the global minimum of an arbitrarily complicated function 
without sampling all of the points (infinitely many points).  With your 
adaptively interpolating human eye and theoretical knowledge of the true shape, 
you have more information than the computer has.  Think of it like scraping the 
nastiest bits of stuff off of a plate before putting it in the dishwasher: 
humans are good at robustly getting close to the right answer, and Minuit is 
good at polishing it off and giving rigorous uncertainty bounds.

Original comment by jpivar...@gmail.com on 6 Aug 2011 at 3:46

  • Changed state: Invalid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant