[SciPy-user] mpfit

Steve Schmerler elcorto at gmx.net
Thu Feb 17 08:17:20 CST 2005

Evelien Vanhollebeke wrote:
> Hi scipy-users,
> I was wondering if anyone was using the mpfit module 
> (http://cars.uchicago.edu/software) <http://cars.uchicago.edu/software>.
> I would really like (need) to use it, but can't get to seem the thing 
> perform as it should be. I am aware of the two messages posted in this 
> mailing list,

that was me :)

> and changed the two mentioned lines. I am using python 
> 2.3.3.  Maybe if someone could share his/her user defined function or 
> some other hints?  At first, the program just crashed on the parinfo, 
> which is not really necessary. Now I can get it run (if I don't use the 
> autoderivate=0, then it gets stuck on the "fjac" variable), but as 
> already mentioned, it doesn't iterate.

Unfortunately I don't have my mpfit stuff at hand right now but what I 
remember doing was something like:


import mpfit

# read data and prepare 2 data arrays 't' and 'y'

def func(t, x):
	- the model function
	- t -- x-axis (data)
	- x -- parameter array
	- return y-values at each t
	y_model = ...
	return y_model

# len(t) == len(y_model) = len(y)

def residuals(x, t = t, y = y, fjac = None):
	# I'm not sure about the fjac part, this residual function is 			# 
defined according to the example in the mpfit docstring

	# I think it was 0
	status = 0

	# or stauts at pos 1?
	return [status, y - func(t, x)]

fit = mpfit.mpfit(residuals, ...)


I don't remember the parinfo-stuff right now. I wrote a little "wrapper" 
around mpfit (insert limits in parinfo etc.). Tell me if you want to 
have a look on this.

I also tried leastsq but it's less sophisticated than mpfit.

In mpfit (in enorm()) you can replace


This is faster.

Cheers steve

> Thanks
> Evelien
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user

There are three types of people in this world: those who make things 
happen, those who watch things happen and those who wonder what 
happened. - Mary Kay Ash

More information about the SciPy-user mailing list