Closed sdwfrost closed 2 months ago
After reading the odin
docs more, I came across user
. Here is code that can be readily wrapped in Julia:
sir_ode_odin <- odin::odin({
## Derivatives
deriv(S) <- -beta*cee*S*I/N
deriv(I) <- beta*cee*S*I/N-gamma*I
deriv(R) <- gamma*I
N <- S + I + R
## Initial conditions
initial(S) <- S_ini
initial(I) <- I_ini
initial(R) <- R_ini
## parameters
S_ini <- user(990.0)
I_ini <- user(10.0)
R_ini <- user(0.0)
beta <- user(0.05)
cee <- user(10.0)
gamma <- user(0.25)
}, target="c")
sir_ode_model <- sir_ode_odin$new()
sir_ode_r <- function(u,p,t){
sir_ode_model$set_user(user=list(beta=p[1],cee=p[2],gamma=p[3]))
return(sir_ode_model$deriv(t,u))
}
Closed with 8045d5c020b47bbb8443622edff787f749cf1f92
Here is the model using the R library
odin
:The derivatives for (t,y) can be obtained as follows:
The main issue is how to modify the parameters of the model outside of compiling the odin object.