Skip to content

Instantly share code, notes, and snippets.

@currymj
Created July 11, 2018 15:11
Show Gist options
  • Save currymj/70ada28a935e4ed5342c368cccf0503b to your computer and use it in GitHub Desktop.
Save currymj/70ada28a935e4ed5342c368cccf0503b to your computer and use it in GitHub Desktop.
example of bc_model with lag parameter failing for turing inference
using DifferentialEquations
using DiffEqBayes
using Distributions
const p0 = 0.2; const q0 = 0.3; const v0 = 1; const d0 = 5
const p1 = 0.2; const q1 = 0.3; const v1 = 1; const d1 = 1
const d2 = 1; const beta0 = 1; const beta1 = 1; #const tau = 1
function bc_model(du,u,h,p,t)
du[1] = (v0/(1+beta0*(h(p, t-p[1])[3]^2))) * (p0 - q0)*u[1] - d0*u[1]
du[2] = (v0/(1+beta0*(h(p, t-p[1])[3]^2))) * (1 - p0 + q0)*u[1] +
(v1/(1+beta1*(h(p, t-p[1])[3]^2))) * (p1 - q1)*u[2] - d1*u[2]
du[3] = (v1/(1+beta1*(h(p, t-p[1])[3]^2))) * (1 - p1 + q1)*u[2] - d2*u[3]
end
h(p, t) = ones(3)
tspan = (0.0,10.0)
u0 = [1.0,1.0,1.0]
prob = DDEProblem(bc_model,u0,h,tspan, [1.0])
alg = MethodOfSteps(RK4())
sol = solve(prob,alg)
t_obs = linspace(0.0, 10.0, 1000)
randomized = VectorOfArray([sol(t_obs[i]) + 0.01*randn(3) for i=1:length(t_obs)])
data = convert(Array, randomized)
turing_result = turing_inference(prob, MethodOfSteps(RK4()), t_obs, data, [Gamma(1.0, 1.0)]; num_samples=500)
@currymj
Copy link
Author

currymj commented Jul 11, 2018

Main> Pkg.status("DiffEqBayes")
 - DiffEqBayes                   0.6.0

Main> Pkg.status("DelayDiffEq")
 - DelayDiffEq                   3.6.0              master

Main> Pkg.status("DifferentialEquations")
 - DifferentialEquations         4.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment