Fitting in Python

The file linfit.py uses a one-step algorithm to calculate the fest fit to a straight line. This is very efficient, but it does not produce estimates of the uncertainties of the fitted parameters (the slope and intercept of the line). Data is read in line-by-line from dbf.dat and the columns filled in with the ".append(...)" method for arrays by parsing each line. This is clumsy but robust and explicit.

The file pymindb.py uses the famous CERN fitting program MINUIT (via the pyminuit package) to give you access to all the power of that program. It also uses a somewhat more compact (if a bit esoteric) numpy.loadtxt('dbf.dat') method for reading in all the data in one step; note hoever that the elements in the data table must be separated by exactly one space for this to work properly.

Both are poorly optimized implementations by JHB. You can certainly handle the data input, plotting and other features much more elegantly if you spend more time on the scripts, but this will do in a pinch!


Jess H. Brewer
Last modified: Wed Oct 27 05:17:02 PDT 2010