-
In scenarios where a compartmental model can be formulated using
+ODEs, denim provides 2 ways for users to define transitions
+between compartments:
+
+
This section demonstrates the run time and numerical accuracy of
+these 2 approaches as timeStep varies, using results from
+deSolve as the baseline. For this demonstration, we use the
+basic SIR model.
+
Model definition and configuration
The basic SIR model can be formulated using the following system of
+ODEs.
+\[
+\begin{cases}
+\frac{dS(t)}{dt} = - \beta \frac{I(t)}{N} S(t) \\
+\frac{dI(t)}{dt} = \beta \frac{I(t)}{N} S(t) - \gamma I(t) \\
+\frac{dR(t)}{dt} = \gamma I(t)
+\end{cases}
+\]
+The code to define this model is presented below.
+
+# ----- deSolve -----
+desolve_sir <- function(t, state, param){
+ with(as.list( c(state, param) ), {
+ dS = -beta*S*I/N
+ dI = beta*S*I/N - gamma*I
+ dR = gamma*I
+ list(c(dS, dI, dR))
+ })
+}
+
+# ----- denim: math expression -----
+denim_ode <- denim_dsl({
+ S -> I = beta*S*I/N
+ I -> R = gamma*I
+})
+
+# ----- denim: d_* function -----
+denim_dfunc <- denim_dsl({
+ S -> I = beta*S*I/N
+ I -> R = d_exponential(gamma)
+})
+
+# ---- Model configuration ----
+parameters <- c(beta = 0.4, gamma = 1/7, N = 1000)
+initialValues <- c(S = 999, I = 1, R=0)
+sim_duration <- 100
+times <- seq(0, sim_duration)
+The plot below summarizes the run time and accuracy at different
+timeStep (denoted dt), comparing the use of
+d_exponential() vs math expression for I->R
+transition.
+
## Warning: package 'patchwork' was built under R version 4.3.3
+

+
The plot for run time scaling (upper figure) indicates that using
+d_exponential() results in slightly faster run times as
+timeStep increases. This suggests that, for the current
+model, the overhead from parsing math expressions exceeds the time for
+iterating over sub-compartments.
+
As we've known, run time decreases as dt increases, and at dt = 1
+denim approaches the performance of deSolve.
+However, this also reduces accuracy, as suggested by the pairwise
+plot.
+
+
+
4. Performance in more complex model
To assess the performance of denim as the model grows
more complex, we measure the run-time and memory allocation as more
@@ -1571,9 +1640,9 @@
3. Performance with more complex mo
[3, 5, 25, 50, 100] compartments (i.e.,
[2, 4, 24, 49, 99] transitions under this settings).
Run time
-

+

Memory allocated
-

+

diff --git a/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-32-1.png b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-32-1.png
index bd19c20..d28dcc3 100644
Binary files a/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-32-1.png and b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-32-1.png differ
diff --git a/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-37-1.png b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-37-1.png
index 8898d9c..090938c 100644
Binary files a/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-37-1.png and b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-37-1.png differ
diff --git a/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-38-1.png b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-38-1.png
index f9cb713..163b9f4 100644
Binary files a/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-38-1.png and b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-38-1.png differ
diff --git a/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-39-1.png b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-39-1.png
new file mode 100644
index 0000000..3234796
Binary files /dev/null and b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-39-1.png differ
diff --git a/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-40-1.png b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-40-1.png
new file mode 100644
index 0000000..0e695c0
Binary files /dev/null and b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-40-1.png differ
diff --git a/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-41-1.png b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-41-1.png
new file mode 100644
index 0000000..8898d9c
Binary files /dev/null and b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-41-1.png differ
diff --git a/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-42-1.png b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-42-1.png
new file mode 100644
index 0000000..f9cb713
Binary files /dev/null and b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-42-1.png differ
diff --git a/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-43-1.png b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-43-1.png
new file mode 100644
index 0000000..f9cb713
Binary files /dev/null and b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-43-1.png differ
diff --git a/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-44-1.png b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-44-1.png
new file mode 100644
index 0000000..b9c6a2d
Binary files /dev/null and b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-44-1.png differ
diff --git a/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-46-1.png b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-46-1.png
new file mode 100644
index 0000000..8898d9c
Binary files /dev/null and b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-46-1.png differ
diff --git a/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-47-1.png b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-47-1.png
new file mode 100644
index 0000000..f9cb713
Binary files /dev/null and b/docs/articles/denim_benchmark_files/figure-html/unnamed-chunk-47-1.png differ
diff --git a/docs/articles/index.html b/docs/articles/index.html
index e5897bc..f759f2d 100644
--- a/docs/articles/index.html
+++ b/docs/articles/index.html
@@ -10,7 +10,7 @@
denim
-
1.2.2
+
1.2.3
+