增长功能无法达成共识-令人困惑的结果

好的,我正在写一篇有关用Python生成增长函数的论文(Paine等,2012)。增长函数以多种不同的方式表示,我将需要使用其中的一种以上(针对不同的应用程序)。

公式1:Gompertz函数表示为质量随时间的变化公式2:Gompertz函数表示为时间的函数

公式1是表示为质量随时间变化的Gompertz函数,公式2是表示为经过的总时间的Gompertz函数。一个计算基于当前质量的质量变化,另一个计算基于质量增长了多长时间的质量。

我已经将它们翻译成python并编写了一些代码来检查它们是否匹配(因为它们是同一个方程式的不同表达式,这应该不是问题...)

import numpy as np
import matplotlib.pyplot as plt

def gompertz_t(m_0, K, r, t):
    return K*(m_0/K)**np.exp(-r*t)

def gompertz_m(m, K, r):
    eq1 = r*m
    eq2 = np.log(K/m)
    return m+eq1*eq2

x = list(range(0,50,1))

m_0 = 0.1 #(must not be equal to zero)

#Set up values for year 0
y_1 = [m_0]
y_2 = [m_0]

for i in x[1:]:
    #And run for x years
    y_1.append(gompertz_m(y_1[-1],50,0.5))
    y_2.append(gompertz_t(y_2[0],50,0.5,i))

# df = pd.DataFrame(index = x)
# df["gompertz_m"] = y_1
# df["gompertz_t"] = y_2
# df.to_clipboard()

fig = plt.figure()
chart = fig.add_subplot(1, 1, 1)
chart.plot(x,y_1, label="Gompertz curve (time)")
chart.plot(x,y_2, label="Gompertz curve (mass)")

plt.legend()
fig.tight_layout()
plt.show()

但是...他们不匹配。所得曲线不一致。

一个对比

有人可以告诉我这里出了什么问题吗?我在其他增长曲线上也遇到过同样的问题,因此我认为这是我的实现方式而不是原始方程式的问题。

阿兰·T。

我相信差异是由于等式1是等式2的导数。这意味着,以1个时间单位(年)为增量的循环将等式1近似“离散”地变化,而等式2则产生连续值。 (即方程式1的积分)。为了获得更好的拟合,您将需要大大提高方程式1的“采样率”。

为此,您需要使函数返回其真实增量值(即不将其添加到mass参数):

def gompertz_m(m, K, r):
    eq1 = r*m
    eq2 = np.log(K/m)
    return eq1*eq2           # removed the m + 

然后通过应用多个较小的时间间隔来提高采样率。

例如(每天采样):

for i in x[1:]:
    #And run for x years
    cumMass = y_1[-1]
    for _ in range(365):
        cumMass += gompertz_m(cumMass,50,0.5)/365
    y_1.append(cumMass)
    y_2.append(gompertz_t(y_2[0],50,0.5,i))

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章