8

I'm new to PyMC and trying to fit my non-homogeneous poisson-process with a piecewise-constant rate function using the maximum a posteriori estimate.

My process describes some events during a day. Therefore i'm splitting a day into 24 hours, which means, that i have 24 constants within my rate-function (piecewise-constant).

Combining ideas from:

i came up with the following piece of code, which is not satisfying (result-wise and i'm sure it's wrong):

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 #...

The values in a0, a1... don't seem to be fitted to my data (generated by sampling from a non-homogeneous poisson-process with given lambdas -> test-case!)

How can i fit / estimate my lambdas? What am i doing wrong?

(I'm using pyMC 2.3.2!)

Community
  • 1
  • 1
sascha
  • 32,238
  • 6
  • 68
  • 110
  • 2
    This question appears to be off-topic because it belongs on http://stats.stackexchange.com/ – jonrsharpe Jun 06 '14 at 14:35
  • Maybe... But the official mailing-list refers to StackOverflow for questions. See [here](https://groups.google.com/forum/#!forum/pymc) – sascha Jun 06 '14 at 14:36
  • I think that is more for problems with the code or errors in implementation - your question appears to be about the underlying theory/method, which is not on-topic here. – jonrsharpe Jun 06 '14 at 14:48

0 Answers0