user2003965
user2003965

Reputation: 503

Levenberg-Marquardt in python with constraints

Is there any good way to add constraits into levenberg-marquadt routine in python? What i found so far is mostly changing the errorfunction to something like

def errorfunction(params, PSD_data, bins):
if (params[0] < 0) or (params[1] < 0) or (params[2] < 0):
    return (PSD_data - PSD_fit(params, bins))*1000
else:
    return PSD_data - PSD_fit(params, bins)

But even then it is possible to get wrong results, eg. params[0] to be negativ! Any sugggestions?

Upvotes: 0

Views: 4662

Answers (1)

FlavioF
FlavioF

Reputation: 11

You can use the lmfit library for this:

http://cars9.uchicago.edu/software/python/lmfit/

It supports constraints and it is build on top of scipy.

Upvotes: 1

Related Questions