From 630e657f1794ea441afc9ff10663309fec5e847e Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Tue, 1 Nov 2022 14:16:21 +0100 Subject: Update online docs --- docs/dev/articles/index.html | 2 +- docs/dev/articles/web_only/benchmarks.html | 38 +++++- docs/dev/articles/web_only/compiled_models.html | 168 +++++++++++++----------- docs/dev/articles/web_only/multistart.html | 16 +-- 4 files changed, 133 insertions(+), 91 deletions(-) (limited to 'docs/dev/articles') diff --git a/docs/dev/articles/index.html b/docs/dev/articles/index.html index 551e9c98..45ba1c77 100644 --- a/docs/dev/articles/index.html +++ b/docs/dev/articles/index.html @@ -17,7 +17,7 @@ mkin - 1.1.2 + 1.2.0 diff --git a/docs/dev/articles/web_only/benchmarks.html b/docs/dev/articles/web_only/benchmarks.html index e5bc5a21..2aa2f45a 100644 --- a/docs/dev/articles/web_only/benchmarks.html +++ b/docs/dev/articles/web_only/benchmarks.html @@ -34,7 +34,7 @@ mkin - 1.1.2 + 1.2.0 @@ -63,11 +63,14 @@ Example evaluations of dimethenamid data from 2018 with nonlinear mixed-effects models
  • - Example evaluation of FOCUS Example Dataset Z + Short demo of the multistart method
  • Performance benefit by using compiled model definitions in mkin
  • +
  • + Example evaluation of FOCUS Example Dataset Z +
  • Calculation of time weighted average concentrations with mkin
  • @@ -106,7 +109,7 @@

    Benchmark timings for mkin

    Johannes Ranke

    -

    Last change 14 July 2022 (rebuilt 2022-09-16)

    +

    Last change 14 July 2022 (rebuilt 2022-11-01)

    Source: vignettes/web_only/benchmarks.rmd @@ -340,6 +343,14 @@ 1.957 3.633 + +Linux +Ryzen 7 1700 +4.2.2 +1.2.0 +2.020 +3.608 + @@ -511,6 +522,15 @@ 6.147 2.803 + +Linux +Ryzen 7 1700 +4.2.2 +1.2.0 +1.579 +5.973 +2.839 + @@ -736,6 +756,18 @@ 1.961 2.852 + +Linux +Ryzen 7 1700 +4.2.2 +1.2.0 +0.920 +1.295 +1.518 +3.060 +1.895 +2.740 + diff --git a/docs/dev/articles/web_only/compiled_models.html b/docs/dev/articles/web_only/compiled_models.html index 49a579fc..ade86bc5 100644 --- a/docs/dev/articles/web_only/compiled_models.html +++ b/docs/dev/articles/web_only/compiled_models.html @@ -20,6 +20,8 @@ + +
    +
    -
    -

    -How to benefit from compiled models

    +
    +

    How to benefit from compiled models +

    When using an mkin version equal to or greater than 0.9-36 and a C compiler is available, you will see a message that the model is being compiled from autogenerated C code when defining a model using mkinmod. Starting from version 0.9.49.9, the mkinmod() function checks for presence of a compiler using

    -pkgbuild::has_compiler()
    -

    In previous versions, it used Sys.which("gcc") for this check.

    +pkgbuild::has_compiler()
    +

    In previous versions, it used Sys.which("gcc") for this check.

    On Linux, you need to have the essential build tools like make and gcc or clang installed. On Debian based linux distributions, these will be pulled in by installing the build-essential package.

    On MacOS, which I do not use personally, I have had reports that a compiler is available by default.

    On Windows, you need to install Rtools and have the path to its bin directory in your PATH variable. You do not need to modify the PATH variable when installing Rtools. Instead, I would recommend to put the line

    -Sys.setenv(PATH = paste("C:/Rtools/bin", Sys.getenv("PATH"), sep=";"))
    +Sys.setenv(PATH = paste("C:/Rtools/bin", Sys.getenv("PATH"), sep=";"))

    into your .Rprofile startup file. This is just a text file with some R code that is executed when your R session starts. It has to be named .Rprofile and has to be located in your home directory, which will generally be your Documents folder. You can check the location of the home directory used by R by issuing

    -Sys.getenv("HOME")
    +Sys.getenv("HOME")
    -
    -

    -Comparison with other solution methods

    +
    +

    Comparison with other solution methods +

    First, we build a simple degradation model for a parent compound with one metabolite, and we remove zero values from the dataset.

    -library("mkin", quietly = TRUE)
    -SFO_SFO <- mkinmod(
    -  parent = mkinsub("SFO", "m1"),
    -  m1 = mkinsub("SFO"))
    -
    ## Temporary DLL for differentials generated and loaded
    +library("mkin", quietly = TRUE) +SFO_SFO <- mkinmod( + parent = mkinsub("SFO", "m1"), + m1 = mkinsub("SFO"))
    +
    ## Temporary DLL for differentials generated and loaded
    -FOCUS_D <- subset(FOCUS_2006_D, value != 0)
    +FOCUS_D <- subset(FOCUS_2006_D, value != 0)

    We can compare the performance of the Eigenvalue based solution against the compiled version and the R implementation of the differential equations using the benchmark package. In the output of below code, the warnings about zero being removed from the FOCUS D dataset are suppressed. Since mkin version 0.9.49.11, an analytical solution is also implemented, which is included in the tests below.

    -if (require(rbenchmark)) {
    -  b.1 <- benchmark(
    -    "deSolve, not compiled" = mkinfit(SFO_SFO, FOCUS_D,
    -       solution_type = "deSolve",
    -       use_compiled = FALSE, quiet = TRUE),
    -    "Eigenvalue based" = mkinfit(SFO_SFO, FOCUS_D,
    -       solution_type = "eigen", quiet = TRUE),
    -    "deSolve, compiled" = mkinfit(SFO_SFO, FOCUS_D,
    -       solution_type = "deSolve", quiet = TRUE),
    -    "analytical" = mkinfit(SFO_SFO, FOCUS_D,
    -       solution_type = "analytical",
    -       use_compiled = FALSE, quiet = TRUE),
    -    replications = 1, order = "relative",
    -    columns = c("test", "replications", "relative", "elapsed"))
    -  print(b.1)
    -} else {
    -  print("R package rbenchmark is not available")
    -}
    -
    ##                    test replications relative elapsed
    -## 4            analytical            1    1.000   0.182
    -## 3     deSolve, compiled            1    1.824   0.332
    -## 2      Eigenvalue based            1    2.082   0.379
    -## 1 deSolve, not compiled            1   46.181   8.405
    +if (require(rbenchmark)) { + b.1 <- benchmark( + "deSolve, not compiled" = mkinfit(SFO_SFO, FOCUS_D, + solution_type = "deSolve", + use_compiled = FALSE, quiet = TRUE), + "Eigenvalue based" = mkinfit(SFO_SFO, FOCUS_D, + solution_type = "eigen", quiet = TRUE), + "deSolve, compiled" = mkinfit(SFO_SFO, FOCUS_D, + solution_type = "deSolve", quiet = TRUE), + "analytical" = mkinfit(SFO_SFO, FOCUS_D, + solution_type = "analytical", + use_compiled = FALSE, quiet = TRUE), + replications = 1, order = "relative", + columns = c("test", "replications", "relative", "elapsed")) + print(b.1) +} else { + print("R package rbenchmark is not available") +}
    +
    ##                    test replications relative elapsed
    +## 4            analytical            1    1.000   0.186
    +## 3     deSolve, compiled            1    1.656   0.308
    +## 2      Eigenvalue based            1    2.102   0.391
    +## 1 deSolve, not compiled            1   38.968   7.248

    We see that using the compiled model is by more than a factor of 10 faster than using deSolve without compiled code.

    -
    -

    -Model without analytical solution

    +
    +

    Model without analytical solution +

    This evaluation is also taken from the example section of mkinfit. No analytical solution is available for this system, and now Eigenvalue based solution is possible, so only deSolve using with or without compiled code is available.

    -if (require(rbenchmark)) {
    -  FOMC_SFO <- mkinmod(
    -    parent = mkinsub("FOMC", "m1"),
    -    m1 = mkinsub( "SFO"))
    -
    -  b.2 <- benchmark(
    -    "deSolve, not compiled" = mkinfit(FOMC_SFO, FOCUS_D,
    -                                      use_compiled = FALSE, quiet = TRUE),
    -    "deSolve, compiled" = mkinfit(FOMC_SFO, FOCUS_D, quiet = TRUE),
    -    replications = 1, order = "relative",
    -    columns = c("test", "replications", "relative", "elapsed"))
    -  print(b.2)
    -  factor_FOMC_SFO <- round(b.2["1", "relative"])
    -} else {
    -  factor_FOMC_SFO <- NA
    -  print("R package benchmark is not available")
    -}
    -
    ## Temporary DLL for differentials generated and loaded
    -
    ##                    test replications relative elapsed
    -## 2     deSolve, compiled            1    1.000   0.541
    -## 1 deSolve, not compiled            1   29.091  15.738
    +if (require(rbenchmark)) { + FOMC_SFO <- mkinmod( + parent = mkinsub("FOMC", "m1"), + m1 = mkinsub( "SFO")) + + b.2 <- benchmark( + "deSolve, not compiled" = mkinfit(FOMC_SFO, FOCUS_D, + use_compiled = FALSE, quiet = TRUE), + "deSolve, compiled" = mkinfit(FOMC_SFO, FOCUS_D, quiet = TRUE), + replications = 1, order = "relative", + columns = c("test", "replications", "relative", "elapsed")) + print(b.2) + factor_FOMC_SFO <- round(b.2["1", "relative"]) +} else { + factor_FOMC_SFO <- NA + print("R package benchmark is not available") +}
    +
    ## Temporary DLL for differentials generated and loaded
    +
    ##                    test replications relative elapsed
    +## 2     deSolve, compiled            1    1.000   0.452
    +## 1 deSolve, not compiled            1   29.431  13.303

    Here we get a performance benefit of a factor of 29 using the version of the differential equation model compiled from C code!

    -

    This vignette was built with mkin 1.0.3.9000 on

    -
    ## R version 4.0.3 (2020-10-10)
    -## Platform: x86_64-pc-linux-gnu (64-bit)
    -## Running under: Debian GNU/Linux bullseye/sid
    -
    ## CPU model: AMD Ryzen 7 1700 Eight-Core Processor
    +

    This vignette was built with mkin 1.2.0 on

    +
    ## R version 4.2.2 (2022-10-31)
    +## Platform: x86_64-pc-linux-gnu (64-bit)
    +## Running under: Debian GNU/Linux 11 (bullseye)
    +
    ## CPU model: AMD Ryzen 7 1700 Eight-Core Processor
    @@ -211,11 +219,13 @@ @@ -224,5 +234,7 @@ + + diff --git a/docs/dev/articles/web_only/multistart.html b/docs/dev/articles/web_only/multistart.html index 0c08905a..50a57d1b 100644 --- a/docs/dev/articles/web_only/multistart.html +++ b/docs/dev/articles/web_only/multistart.html @@ -34,7 +34,7 @@ mkin - 1.1.2 + 1.2.0 @@ -109,7 +109,7 @@

    Short demo of the multistart method

    Johannes Ranke

    -

    Last change 26 September 2022 (rebuilt 2022-10-28)

    +

    Last change 26 September 2022 (rebuilt 2022-11-01)

    Source: vignettes/web_only/multistart.rmd @@ -144,23 +144,21 @@

    This confirms that the variance of k2 is the most problematic parameter, so we reduce the parameter distribution model by removing the intersoil variability for k2.

     f_saem_reduced <- update(f_saem_full, no_random_effect = "log_k2")
    -illparms(f_saem_reduced)
    -
    ## character(0)
    -
    -f_saem_reduced_multi <- multistart(f_saem_reduced, n = 16, cores = 16)
    +illparms(f_saem_reduced)
    +f_saem_reduced_multi <- multistart(f_saem_reduced, n = 16, cores = 16)
     parplot(f_saem_reduced_multi, lpos = "topright")

    The results confirm that all remaining parameters can be determined with sufficient certainty.

    We can also analyse the log-likelihoods obtained in the multiple runs:

    -
    +
     llhist(f_saem_reduced_multi)

    The parameter histograms can be further improved by excluding the result with the low likelihood.

    -
    +
     parplot(f_saem_reduced_multi, lpos = "topright", llmin = -326, ylim = c(0.5, 2))

    We can use the anova method to compare the models, including a likelihood ratio test if the models are nested.

    -
    +
     anova(f_saem_full, best(f_saem_reduced_multi), test = TRUE)
    ## Data: 155 observations of 1 variable(s) grouped in 6 datasets
     ## 
    -- 
    cgit v1.2.1