Scipy's Optimize Curve Fit Limits

后端 未结 4 1288
无人及你
无人及你 2021-01-06 04:07

Is there any way I can provide limits for the Scipy\'s Optimize Curve Fit?

My example:

    def optimized_formula(x, m_1, m_2, y_1, y_2, ratio_2):
            


        
4条回答
  •  無奈伤痛
    2021-01-06 04:41

    Note: New in version 0.17 of SciPy

    Let's suppose you want to fit a model to the data which looks like this:

    y=a*t**alpha+b
    

    and with the constraint on alpha

    0

    while other parameters a and b remains free. Then we should use the bounds option of optimize.curve_fit:

    import numpy as np
    from scipy.optimize import curve_fit
    def func(t, a,alpha,b):
         return a*t**alpha+b
    param_bounds=([-np.inf,0,-np.inf],[np.inf,2,np.inf])
    popt, pcov = optimize.curve_fit(func, xdata,ydata,bounds=param_bounds)
    

    Source is here

提交回复
热议问题