我是PyMC的新手,并尝试使用最大值a 拟合我的非均匀泊松过程和分段常数率函数后验估计。
我的流程描述了一天中的一些事件。因此,我将一天分成24小时,这意味着我的速率函数中有24个常数(分段常数)。
结合来自的想法:
我提出了以下一段代码,这是不满意的(结果明智,我确定它错了):
import numpy as np
import pymc
eventCounter = np.zeros(24) # will be filled with real counts before going on
alpha = 1.0 / eventCounter.mean()
a0 = pymc.Exponential('a0', alpha)
a1 = pymc.Exponential('a1', alpha)
a2 = pymc.Exponential('a2', alpha)
a3 = pymc.Exponential('a3', alpha)
a4 = pymc.Exponential('a4', alpha)
a5 = pymc.Exponential('a5', alpha)
a6 = pymc.Exponential('a6', alpha)
a7 = pymc.Exponential('a7', alpha)
a8 = pymc.Exponential('a8', alpha)
a9 = pymc.Exponential('a9', alpha)
a10 = pymc.Exponential('a10', alpha)
a11 = pymc.Exponential('a11', alpha)
a12 = pymc.Exponential('a12', alpha)
a13 = pymc.Exponential('a13', alpha)
a14 = pymc.Exponential('a14', alpha)
a15 = pymc.Exponential('a15', alpha)
a16 = pymc.Exponential('a16', alpha)
a17 = pymc.Exponential('a17', alpha)
a18 = pymc.Exponential('a18', alpha)
a19 = pymc.Exponential('a19', alpha)
a20 = pymc.Exponential('a20', alpha)
a21 = pymc.Exponential('a21', alpha)
a22 = pymc.Exponential('a22', alpha)
a23 = pymc.Exponential('a23', alpha)
@pymc.deterministic
def piecewise_constant(a0=a0, a1=a1, a2=a2, a3=a3, a4=a4, a5=a5, a6=a6, a7=a7, a8=a8, a9=a9, a10=a10, a11=a11, a12=a12, a13=a13, a14=a14, a15=a15, a16=a16, a17=a17, a18=a18, a19=a19, a20=a20, a21=a21, a22=a22, a23=a23):
out = np.zeros(24)
out[0] = a0
out[1] = a1
out[2] = a2
out[3] = a3
out[4] = a4
out[5] = a5
out[6] = a6
out[7] = a7
out[8] = a8
out[9] = a9
out[10] = a10
out[11] = a11
out[12] = a12
out[13] = a13
out[14] = a14
out[15] = a15
out[16] = a16
out[17] = a17
out[18] = a18
out[19] = a19
out[20] = a20
out[21] = a21
out[22] = a22
out[23] = a23
return out
observation = pymc.Poisson('obs', piecewise_constant, value=eventCounter, observed=True)
model = pymc.Model([observation, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23])
map = pymc.MAP(model)
map.fit()
map.revert_to_max() # i'm not sure if i need this, even after reading the docs!
print a0._value #...
a0,a1 ......中的值似乎与我的数据拟合(通过从给定lambda的非齐次泊松过程中采样生成 - >测试用例!)
我如何适合/估计我的lambdas? 我做错了什么?
(我正在使用pyMC 2.3.2!)