Created
March 14, 2016 05:17
-
-
Save yoavram/fd12f909e3130484606f to your computer and use it in GitHub Desktop.
Fit a Gompertz curve to (t, y) data.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gompertz(t, N0, K, r, T): | |
return K * np.exp(-T * np.exp(-r * t)) | |
popt, cov = curve_fit(gompertz, t, N, (N.min(), N.max(), 1, 2)) | |
N0, K, r, T = popt | |
Nhat = gompertz(t, N0, K, r, T) | |
print('N0={0:.3f}, K={1:.3f}, r={2:.6f}, T={3:.4f}'.format(N0, K, r, T)) | |
print("MSE:", ((N - Nhat)**2).mean()) | |
plt.scatter(t, N) | |
plt.plot(t, logistic(t, N0, K, r), label='Logistic') | |
plt.plot(t, Nhat, label='Gompertz') | |
plt.xlabel('Time') | |
plt.ylabel('OD') | |
plt.legend(loc='upper left') | |
sns.despine(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment