PyMC: Parameter estimation in a Markov system

心已入冬 提交于 2019-12-05 14:32:31

The easiest way is to generate a list, and allow PyMC to deal with it as a Container. There is a relevant example on the PyMC wiki. Here is the relevant snippet:

# Lognormal distribution of P's
Pmean0 = 0.
P_0 = Lognormal('P_0', mu=Pmean0, tau=isigma2, trace=False, value=P_inits[0])
P = [P_0]

# Recursive step
for i in range(1,nyears):
    Pmean = Lambda("Pmean", lambda P=P[i-1], k=k, r=r: log(max(P+r*P*(1-P)-k*catch[i-1],0.01)))
    Pi = Lognormal('P_%i'%i, mu=Pmean, tau=isigma2, value=P_inits[i], trace=False)
    P.append(Pi)

Notice how the mean of the current Lognormal is a function of the last one? Not elegant, using list.append and all, but you can use a list comprehension instead.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!