forked from dkaschek/dMod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestXs2.R
More file actions
68 lines (47 loc) · 1.6 KB
/
testXs2.R
File metadata and controls
68 lines (47 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
rm(list = ls(all.names = TRUE))
# Create and set a specific working directory inside your project folder
.workingDir <- file.path(purrr::reduce(1:1, ~dirname(.x), .init = rstudioapi::getSourceEditorContext()$path), "wd")
if (!dir.exists(.workingDir)) dir.create(.workingDir)
setwd(.workingDir)
# unlink(list.files(".", pattern = "\\.(cpp|c|o|so|dll)$", full.names = TRUE), force = TRUE)
set.seed(5555)
library(dMod)
library(ggplot2)
library(dplyr)
# Set up reactions
eqns <- eqnvec(x = "-k*x")
events <- eventlist() %>%
addEvent(var = "x", time = "te", value = "v", root = NA, method = "add")
x.ds <- odemodel(eqns, events = events, modelname = "test_Xs_ds", compile = F, solver = "deSolve") %>% Xs()
x.bs <- odemodel(eqns, events = events, modelname = "test_Xs_bs", compile = F, solver = "boost") %>% Xs()
observables <- eqnvec(obs = "offset-x")
g <- Y(observables, f=x.bs, modelname = "obsfun_test", compile = F)
p <- eqnvec() %>%
define("x~x", x = getParameters(x.ds,g)) %>%
insert("x~1") %>% P(compile = F)
getEquations(p)
getEquations(x.bs)
getEquations(g)
compile(g, x.ds, x.bs ,p, cores = 10)
# loadDLL(g, x.ds, x.bs ,p)
getParameters(p)
pars <- c(k=1, te = 1, v=0, offset = 1)
# debugonce(p)
p(pars)
p(pars) %>% getDerivs()
times <- seq(0,10,len = 300)
prd.ds <- x.ds*p
prd.bs <- x.bs*p
# debugonce(x.bs)
out.ds <- prd.ds(times,pars)
out.bs <- prd.bs(times,pars)
out.ds %>% plot()
out.bs %>% plot()
# debugonce(getDerivs)
out.ds %>% getDerivs() %>% plot()
out.bs %>% getDerivs() %>% plot()
prd.ds <- g*x.ds*p
# debugonce(g)
out.ds <- prd.ds(times,pars)
out.ds %>% plot()
out.ds %>% getDerivs() %>% plot()