In [2]:
from matplotlib.pyplot import plot
from ssa import SSA
from pystan import stan
%matplotlib inline
In [3]:
N = 100
alpha = 1
mu = 10
x, t = SSA(3,N,a=alpha,mu=mu)
x = x.astype(int) # path data supposed to be integers.
path_data = {
'N' : N,
't' : t,
'x' : x
}
In [4]:
# Setup STAN :
model_description = """
data{
int<lower=0> N; ## number of time steps
vector[N] t; ## time value at each time step
int<lower=0> x[N]; ## population value at each time step
}
transformed data{
int<lower=0> x0; ## starting population value
x0 <- x[1];
}
parameters{
real<lower=0> alpha; ## birth rate parameter
real<lower=0> mu; ## death rate parameter
}
model {
x ~ poisson(alpha/mu+(x0-alpha/mu)*exp(-mu*t));
}
"""
In [ ]:
fit = stan(model_code=model_description,
data=path_data, chains=1,iter=1000)
print fit
In [ ]: