My favorites | Sign in
Project Logo
                
Search
for
Updated Jun 21, 2008 by jpivarski
Labels: User-Documentation
Features  
List of PyMinuit's features

What Minuit can do

Given an arbitrary numerical function of N variables, Minuit searches the parameter space for the minimum value of that function. This represents a very broad class of applications, but most often, Minuit is used to fit theoretical curves to experimental data.

In addition to finding the minimum, Minuit computes a great deal of information about the region surrounding that minimum, such as the covariance matrix, the second derivative at the minimum in all N dimensions. In curve-fitting applications, this covariance matrix expresses the uncertainty in the parameters of the fit. Because the region close to the minimum may be only approximately paraboloid, Minuit can also climb the sides of the well and calculate exact error bounds, presenting the results in one or two dimensions.

What PyMinuit can access

Users of high-energy physics programs like ROOT, PAW, mn_fit, and HippoDraw have probably accessed Minuit through the curve-fitting utilities. In some of these programs, it is possible to access Minuit directly, but not easily. (Sorry, everyone disagrees about what "easy" and "simple" mean.) PyMinuit provides access to Minuit's low-level minimization routines in a high-level programming environment, Python.

Through PyMinuit, you can


Comment by janAtSlac, Feb 16, 2008

Are there plans to integrate this package with numpy arrays? I would be interested in that in order to be able to interface more efficiently with other packages like matplotlib and pytables. I might just take a stab at it myself, if nobody is working on that already.

Comment by jpivarski, May 11, 2008

Most of the numerical output is not in the form of arrays--- only scan and maybe contours could benefit in terms of speed, if that's what you mean. If it's just a matter of sending PyMinuit output to a plotting package, why not do something like the following?

>>> import numpy
>>> matplotlib.plotThatWantsArrays(numpy.array(minuit.functionThatReturnsLists()))
Comment by YnCopin, Nov 04, 2008

I have 2 comments:

  • is there a way for the user to supply the gradients of the objective function? (the FCNGradientBase interface)
  • is there a way to provide extra-parameters to the objective function? E.g. with kwargs:
  • def chi2(a,b,c, extra_param1=0)

I thought of using a class method, but this does not work, see http://code.google.com/p/pyminuit/issues/detail?id=3. E.g.

class Model:

    def init(self, data): # data = [(x0,y0,dy0), (x1,y1,dy1),...]
        self.data = data 

    def model(self, x, a, b):
        return a + b*x 

    def chi2(self, a, b):
        c2 = 0 for x,y,dy in self.data:
            c2 += (self.model(x, a, b) - y)2 / dy2 
        return c2 

model = Model(data)
m = minuit.Minuit(model.chi2)
m.migrad()

Traceback (most recent call last):
    File "./test_minuit.py", line 43, in ?
        m.migrad() 
TypeError?: chi2() takes exactly 3 arguments (4 given)

The solution suggested in issue #3 does not apply there.

Comment by YnCopin, Nov 04, 2008

Sorry for the misformating of previous comment, but I think you get the point... Regarding my 2nd point, I think I found my way with class methods, using something like:

m = minuit.Minuit(lambda a,b: model.chi2(a,b))

but this looks a bit akward...

Comment by physicsmichael, Feb 09, 2009

@YnCopin??. I went through a similar issue. It is a bit more pythonic to define a function like

def make_gaussian(N, mu, sigma):
    def gaussian(x, N, mu, sigma):
        return N exp(-(x-mu)/(2 sigma2))
    return gaussian(N, mu, sigma)

This is probably incorrect, but you see the gist of returning a function w/ the specified parameters inserted. Tweak to make the code work!


Sign in to add a comment
Hosted by Google Code