Load the ilmtools package...
In [1]:
include("ilmtools.jl")
Out[1]:
Generate a population from a bi-variate uniform distribution...
In [2]:
pop_db1 = create_pop_db_univariates(100, Uniform(0,10), Uniform(0,10))
Out[2]:
Generate the initial infection and propagate infection through population (SIR model) in continuous time with parameters $\alpha=2, \beta=6, \gamma=5$
In [3]:
evdb = infect_recover_loop(pop_db1, "discrete", "SIR", 2, 6, 5)
Out[3]:
Generate the efficient log likelihood function
In [4]:
ll = create_loglikelihood(pop_db1, evdb)
Out[4]:
Time the log likelihood function (run twice)
In [5]:
ll((2, 6, 5))
@time ll((2, 6, 5))
Out[5]:
Run MCMC
In [6]:
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 [7]:
plot(x=burnin:n, y=sim.value[burnin:n, 1, 1], Geom.line)
Out[7]:
In [8]:
plot(x=burnin:n, y=sim.value[burnin:n, 2, 1], Geom.line)
Out[8]:
In [9]:
plot(x=burnin:n, y=sim.value[burnin:n, 3, 1], Geom.line)
Out[9]: