私はPyMCを初めて使用し、最大事後推定値を使用して、不均一なポアソンプロセスを区分定数レート関数に適合させようとしています。
私のプロセスは、1 日の間にいくつかのイベントを記述します。したがって、私は 1 日を 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... の値が私のデータに適合していないようです (指定されたラムダを使用した非均質ポアソン過程からのサンプリングによって生成されました -> テストケース!)
ラムダをどのように適合/推定できますか? 私は何を間違っていますか?
(私は pyMC 2.3.2 を使用しています!)