What Minuit can doGiven 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 accessUsers 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 - Use any Python function as an objective function (FCN). Python exceptions will stop the minimization routine, so you should in principle never encounter segmentation faults.
- Set starting parameter values and errors (interpreted as starting step sizes).
- Fix and release parameters.
- Apply two-sided parameter limits (the domain of the function).
- Minimize with the MIGRAD or SIMPLEX algorithm.
- Set a printMode option to print out function and parameter values call-by-call. Parameter values may be absolute, relative to the starting point, or relative to the previous call.
- Compute the covariance matrix at the given point with HESSE.
- Express the covariance matrix as a dictionary from parameter name pairs to matrix elements or as a tuple-of-tuples matrix.
- Normalize the covariance matrix (that is, calculate the correlation matrix) and optionally skip fixed parameters.
- Calculate non-linear MINOS errors, all in one call, or on a parameter, by parameter basis, specifying the desired number of standard deviations from the minimum.
- Calculate 2D contours a given number of standard deviations from the minimum. The result is a list of 2-tuple pairs, to be given to a plotting program.
- Scan the function with an N-dimensional lattice of points, either at the centers of bins or at the corners.
- Set limits on the number of allowed function calls, the tolerance, the Minuit strategy number (0, 1, 2), the up parameter (1 for chi2, 1/2 for -log likelihood), and access the function value, number of calls in the last command, and estimated distance to the minimum.
|
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.
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?
I have 2 comments:
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.
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:
but this looks a bit akward...
@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!