[SciPy-User] scipy.optimize: fitting multiple data arrays with the same function methodological and general problems
Luca Codutti
luca.codutti at uniud.it
Mon Jan 24 12:56:54 EST 2011
Dear Scipy users,
I'm wondering if you can help me with an optimization problem I'm
stuck for quite some time.
I need to fit several experimental data arrays using a common function
in order to determine common "global" parameters. Each dataset has
further known constants depending on each dataset that need to be feed
to the fitting function.
Till now I've figured out, browsing into the scipy mailing list, that
a good strategy might be in creating a one-dimensional least-square
differences array to be minimized using optmize.leastsq or curve_fit
algorithms.
The problem is that I'm working with sums and products of exponential
decays which possibly are difficult to optimize (I observe many times
NaN during the optimization) and I can't obtain valid or robust output
from the optimization.
I'm wondering if I understood correctly how to solve my global
optimization problem or if I'm doing things untidily.
Being more specific in a pseudo code way:
function_to_be_fit = (K*e^(-a)*e^(-b))/(K*e^(-c) + e^(-b))
to be optimized : a, b, and c
x_data = list(numpy.arrayX1, numpy.arrayX2 ...)
y_data = list(numpy.arrayY1, numpy.arrayY2 ...) *experimental data
known_constants = list(k1, k2,...)
starting optimization values = Opt = [a = Float1, b = Float2, c= Float3]
def Fitter ( Opt, constants, x_data, y_data):
s = []
def func = lambda Opt, k, x = log
((K*e^(-Opt[0])*e^(-Opt[1]))/(K*e^(-Opt[2]) + e^(-Opt[1])) )
for i in xrange(len(constants)):
for j in xrange(len(x_data)):
X_theor = func(Opt, constants[i], x[i][j])
Difference = X_theor - log (y_data[i][j])
s.append(Difference)
return s
fit = scipy.optimize.leastsq(Fitter, Opt, args = {known_constants,
x_data, y_data})
While this method seems to work fine while fitting e.g. parabolas
sharing the same amplitude but having different heights, for my
function I'm stuck every time into local minima which depend
substantially on the initial guessing parameters. So here I'm pretty
lost and I could not manage to find any working protocol in order to
obtain a global minima. Do you have any suggestions?
Thank you in advance.
----------------------------------------------------------------------
SEMEL (SErvizio di Messaging ELettronico) - CSIT -Universita' di Udine
More information about the SciPy-User
mailing list