0
votes

I`m using scipy.optimize.curve_fit for fitting a sigmoidal curve to data. I need to bound one of parameters from [-3, 0.5] and [0.5, 3.0]

I tried fit curve without bounds, and next if parameter is lower than zero, I fit once more with bounds [-3, 0.5] and in contrary with[0.5, 3.0]

Is it possible, to bound function curve_fit with two intervals?

2
I do not think it is possible to bound parameters with curve_fit, but you might be interested in lmfit package which provides exactly this functionality.Vlas Sokolov
I spoke over-optimistically - now that I think of it, there's no direct way to impose two interval constraint in lmfit. Perhaps you can try to create two dependent parameters where one is scaled by a factor of -1 from the other?Vlas Sokolov

2 Answers

0
votes

No, least_squares (hence curve_fit) only supports box constraints.

0
votes

There is a crude way to do this, and that is to have your function return very large values if the parameter is outside the multiple bounds. For example:

sigmoid_func(x, parameters):
    if parameter outside multiple bounds:
        return 1.0E10 * len(x) # very large number
    else:
        return sigmoid value

This has the effect of yielding very large errors if the parameter is outside of your multiple bounds. If you have single bound range of [upper, lower] tou should not use this method, since the most recent version of scipy already supports the more common single bound range type of problem.