diff options
Diffstat (limited to 'vignettes/compiled_models.Rmd')
-rw-r--r-- | vignettes/compiled_models.Rmd | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/vignettes/compiled_models.Rmd b/vignettes/compiled_models.Rmd index 8dc74692..8f6df55d 100644 --- a/vignettes/compiled_models.Rmd +++ b/vignettes/compiled_models.Rmd @@ -16,7 +16,7 @@ vignette: > ```{r, include = FALSE}
library(knitr)
-opts_chunk$set(tidy = FALSE, cache = TRUE)
+opts_chunk$set(tidy = FALSE, cache = FALSE)
```
## Benchmark for a model that can also be solved with Eigenvalues
@@ -46,24 +46,30 @@ the microbenchmark package. ```{r benchmark_SFO_SFO}
library("microbenchmark")
+library("ggplot2")
mb.1 <- microbenchmark(
- mkinfit(SFO_SFO, FOCUS_2006_D, solution_type = "deSolve", use_compiled = FALSE,
- quiet = TRUE),
- mkinfit(SFO_SFO, FOCUS_2006_D, solution_type = "eigen", quiet = TRUE),
- mkinfit(SFO_SFO, FOCUS_2006_D, solution_type = "deSolve", quiet = TRUE),
+ "deSolve, not compiled" = mkinfit(SFO_SFO, FOCUS_2006_D,
+ solution_type = "deSolve",
+ use_compiled = FALSE, quiet = TRUE),
+ "Eigenvalue based" = mkinfit(SFO_SFO, FOCUS_2006_D,
+ solution_type = "eigen", quiet = TRUE),
+ "deSolve, compiled" = mkinfit(SFO_SFO, FOCUS_2006_D,
+ solution_type = "deSolve", quiet = TRUE),
times = 3, control = list(warmup = 1))
-smb.1 <- summary(mb.1)[-1]
-rownames(smb.1) <- c("deSolve, not compiled", "Eigenvalue based", "deSolve, compiled")
-print(smb.1)
+
+smb.1 <- summary(mb.1)
+print(mb.1)
+autoplot(mb.1)
```
We see that using the compiled model is by a factor of
-`r round(smb.1["deSolve, not compiled", "median"]/smb.1["deSolve, compiled", "median"], 1)`
+`r round(smb.1[1, "median"]/smb.1[3, "median"], 1)`
faster than using the R version with the default ode solver, and it is even
faster than the Eigenvalue based solution implemented in R which does not need
iterative solution of the ODEs:
```{r}
+rownames(smb.1) <- smb.1$expr
smb.1["median"]/smb.1["deSolve, compiled", "median"]
```
@@ -77,17 +83,18 @@ FOMC_SFO <- mkinmod( m1 = mkinsub( "SFO"))
mb.2 <- microbenchmark(
- mkinfit(FOMC_SFO, FOCUS_2006_D, use_compiled = FALSE, quiet = TRUE),
- mkinfit(FOMC_SFO, FOCUS_2006_D, quiet = TRUE),
+ "deSolve, not compiled" = mkinfit(FOMC_SFO, FOCUS_2006_D,
+ use_compiled = FALSE, quiet = TRUE),
+ "deSolve, compiled" = mkinfit(FOMC_SFO, FOCUS_2006_D, quiet = TRUE),
times = 3, control = list(warmup = 1))
-smb.2 <- summary(mb.2)[-1]
-rownames(smb.2) <- c("deSolve, not compiled", "deSolve, compiled")
-print(smb.2)
+smb.2 <- summary(mb.2)
+print(mb.2)
smb.2["median"]/smb.2["deSolve, compiled", "median"]
+autoplot(mb.2)
```
Here we get a performance benefit of a factor of
-`r round(smb.2["deSolve, not compiled", "median"]/smb.2["deSolve, compiled", "median"], 1)`
+`r round(smb.2[1, "median"]/smb.2[2, "median"], 1)`
using the version of the differential equation model compiled from C code using
the inline package!
|