Load the ilmtools package...
In [10]:
include("ilmtools.jl")
Out[10]:
Generate a population from a bi-variate uniform distribution...
In [11]:
pop_db1 = create_pop_db_univariates(100, Uniform(0,10), Uniform(0,10))
Out[11]:
Generate the initial infection and propagate infection through population (SIR model) in continuous time with parameters $\alpha=2, \beta=6, \gamma=5$
In [12]:
evdb = infect_recover_loop(pop_db1, "continuous", "SIR", 2, 6, 5)
Out[12]:
Generate the efficient log likelihood function
In [13]:
ll = create_loglikelihood(pop_db1, evdb)
Out[13]:
Time the log likelihood function
In [14]:
ll((1, 7, 4)), ll((3, 7, 7)), ll((1, 7, 4)), @time ll((2, 6, 5))
Out[14]:
Run MCMC
In [15]:
n = 20000
burnin = 10000
sim = Chains(n, 3, names = ["alpha", "beta", "gamma"])
theta = AMMVariate([2.0, 6.0, 5])
SigmaF = cholfact(eye(3))
@time for i in 1:n
amm!(theta, SigmaF, ll, adapt = (i <= burnin))
sim[i,:,1] = theta[1:3]
end
Mamba.describe(sim)
Produce trace plots of $\alpha$, $\beta$, and $\gamma$
In [16]:
plot(x=burnin:n, y=sim.value[burnin:n, 1, 1], Geom.line)
Out[16]:
In [17]:
plot(x=burnin:n, y=sim.value[burnin:n, 2, 1], Geom.line)
Out[17]:
In [18]:
plot(x=burnin:n, y=sim.value[burnin:n, 3, 1], Geom.line)
Out[18]: