Restricting values for curve_fit (scipy.optimize)

后端 未结 1 479
别跟我提以往
别跟我提以往 2021-02-08 23:23

I\'m trying to fit a logistic growth curve to my data using curve_fit using the following function as the input.

def logistic(x, y0, k, d, a, b):
    if b > 0         


        
相关标签:
1条回答
  • 2021-02-09 00:06

    When the parameters fall out of the admissible range, return a wildly huge number (far from the data to be fitted). This will (hopefully) penalize this choice of parameters so much that curve_fit will settle on some other admissible set of parameters as optimal:

    def logistic(x, y0, k, d, a, b):
        if b > 0 and a > 0:
            y = (k * pow(1 + np.exp(d - (a * b * x) ), (-1/b) )) + y0
        elif b >= -1 or b < 0 or a < 0:
            y = (k * pow(1 - np.exp(d - (a * b * x) ), (-1/b) )) + y0
        else:
            y = 1e10
        return y
    
    0 讨论(0)
提交回复
热议问题