I have a differential equation:

def func(Y, t, r, p, K, alpha):
    return r * (Y ** p) * (1 - (Y / K) ** alpha)

and I want to find the best parameters that fit (r,p,K,alpha). I tried to use curve fit but it was too bad, this is my code

# I chose the value of maxfev randomly
popt, pcov = curve_fit(func, df.index, df.Value,method='lm',maxfev = 8000)

t = np.linspace(0, len(df), len(df))
y0 = popt[0]
params = (popt[1], popt[2], popt[3], popt[4]) # r, p, K, alpha
sol = odeint(func, y0, t, args=params)

and this the plot:

enter image description here

Note: this is how my real data looks like:

enter image description here

what I'm looking for it the best values for (r,p,K and alpha), how to find them?


If nothing else is possible, you could try using a genetic algorithm.


Not the answer you're looking for? Browse other questions tagged or ask your own question.