In [381]:
import numpy as np
import matplotlib.pyplot as plt
from scipy import linalg
%matplotlib inline

In [382]:
import sys
sys.path.append("../")

In [383]:
import PoissonProcessClasses as PP
import imp
imp.reload(PP)


Out[383]:
<module 'PoissonProcessClasses' from '../PoissonProcessClasses.py'>

In [384]:
N = 100# number of observations 
d = 1 # number of covariates

The intensity is $\theta * X$ where $X$ is a row vector.


In [ ]:
theta = np.array([2])

We consider different shapes for the intensity: random, constant,sinusoidal:


In [396]:
X = 0.1*np.random.normal(size = (d,N))
X = np.reshape(np.ones(N,),(1,N))
X = np.reshape(np.sin(np.arange(N)),(1,N))

In [397]:
dt = 0.1 # discretization step

In [398]:
l = np.exp(np.dot(X.T,theta))

In [399]:
u = np.random.uniform(size = len(l))
y = 1*(l*dt>u)
print(y)


[0 0 1 0 0 0 0 0 1 0 1 0 0 0 1 1 0 0 0 1 1 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0
 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0
 0 0 0 1 1 0 0 0 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0]

In [400]:
model = PP.PPModel(X,dt = dt)

In [401]:
res = model.fit(y)


/Users/val/anaconda/lib/python3.4/site-packages/scipy/optimize/_minimize.py:362: RuntimeWarning: Method L-BFGS-B does not use Hessian information (hess).
  RuntimeWarning)

In [406]:
print('The estimated parameter is '+ str(res.x[0])+ '. The true parameter is '+str(theta[0])+'.')


The estimated parameter is 2.15000450615. The true parameter is 2.

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: