aboutsummaryrefslogtreecommitdiff
path: root/vignettes/compiled_models.Rmd
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2017-05-05 12:11:30 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2017-05-05 12:13:33 +0200
commit1c7dbeec335c404377381157d34db6e219ce3f21 (patch)
treea0fc9b632a18a6e783adcd11a74837bf8cfcdba4 /vignettes/compiled_models.Rmd
parent5f6faef514c603c04b5824b80bbaf3bfb5cd2eb7 (diff)
Switch from microbenchmark to rbenchmark
Diffstat (limited to 'vignettes/compiled_models.Rmd')
-rw-r--r--vignettes/compiled_models.Rmd74
1 files changed, 37 insertions, 37 deletions
diff --git a/vignettes/compiled_models.Rmd b/vignettes/compiled_models.Rmd
index 18e1a462..864cac87 100644
--- a/vignettes/compiled_models.Rmd
+++ b/vignettes/compiled_models.Rmd
@@ -41,60 +41,60 @@ SFO_SFO <- mkinmod(
We can compare the performance of the Eigenvalue based solution against the
compiled version and the R implementation of the differential equations using
-the microbenchmark package.
+the benchmark package.
```{r benchmark_SFO_SFO, fig.height = 3}
-library("microbenchmark")
-library("ggplot2")
-mb.1 <- microbenchmark(
- "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 = 0))
-
-smb.1 <- summary(mb.1)
-print(mb.1)
-autoplot(mb.1)
+if (require(rbenchmark)) {
+ b.1 <- benchmark(
+ "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),
+ replications = 3)
+ print(b.1)
+ factor_SFO_SFO <- round(b.1["1", "relative"])
+} else {
+ factor_SFO_SFO <- NA
+ print("R package benchmark is not available")
+}
```
-We see that using the compiled model is by a factor of
-`r round(smb.1[1, "median"]/smb.1[3, "median"], 1)`
+We see that using the compiled model is by a factor of around
+`r factor_SFO_SFO`
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:
+iterative solution of the ODEs.
-```{r}
-rownames(smb.1) <- smb.1$expr
-smb.1["median"]/smb.1["deSolve, compiled", "median"]
-```
## Model that can not be solved with Eigenvalues
This evaluation is also taken from the example section of mkinfit.
```{r benchmark_FOMC_SFO, fig.height = 3}
-FOMC_SFO <- mkinmod(
- parent = mkinsub("FOMC", "m1"),
- m1 = mkinsub( "SFO"))
-
-mb.2 <- microbenchmark(
- "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 = 0))
-smb.2 <- summary(mb.2)
-print(mb.2)
-smb.2["median"]/smb.2["deSolve, compiled", "median"]
-autoplot(mb.2)
+if (require(rbenchmark)) {
+ FOMC_SFO <- mkinmod(
+ parent = mkinsub("FOMC", "m1"),
+ m1 = mkinsub( "SFO"))
+
+ b.2 <- benchmark(
+ "deSolve, not compiled" = mkinfit(FOMC_SFO, FOCUS_2006_D,
+ use_compiled = FALSE, quiet = TRUE),
+ "deSolve, compiled" = mkinfit(FOMC_SFO, FOCUS_2006_D, quiet = TRUE),
+ replications = 3)
+ print(b.2)
+ factor_FOMC_SFO <- round(b.2["1", "relative"])
+} else {
+ factor_FOMC_SFO <- NA
+ print("R package benchmark is not available")
+}
```
Here we get a performance benefit of a factor of
-`r round(smb.2[1, "median"]/smb.2[2, "median"], 1)`
+`r factor_FOMC_SFO`
using the version of the differential equation model compiled from C code!
This vignette was built with mkin `r packageVersion("mkin")` on

Contact - Imprint