Python, scipy, curve_fit, bounds: How can I contstraint param by two intervals?
<p>I`m using scipy.optimize.curve_fit for fitting a sigmoidal curve to data. I need to bound one of parammeters from [-3, 0.5] and [0.5, 3.0]</p>

<p>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]</p>

<p>Is it possible, to bound function curve_fit with two intervals?</p>

<p>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:</p>

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

<p>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.</p>

python scipy curve-fitting