diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2020-05-27 07:12:51 +0200 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2020-05-27 07:12:51 +0200 |
commit | b5ee48a86e4b1d4c05aaadb80b44954e2e994ebc (patch) | |
tree | aeeeaf623e4a6102b9ca2440cf0e32ff7a7a1d25 /docs/articles/web_only/compiled_models.html | |
parent | a77a10ea6c607346778ba0700b3b66ac393101a2 (diff) |
Add docs generated using released version 0.9.52
Diffstat (limited to 'docs/articles/web_only/compiled_models.html')
-rw-r--r-- | docs/articles/web_only/compiled_models.html | 81 |
1 files changed, 40 insertions, 41 deletions
diff --git a/docs/articles/web_only/compiled_models.html b/docs/articles/web_only/compiled_models.html index 837b288b..5aaa09bc 100644 --- a/docs/articles/web_only/compiled_models.html +++ b/docs/articles/web_only/compiled_models.html @@ -68,9 +68,6 @@ <li> <a href="../../articles/web_only/NAFTA_examples.html">Example evaluation of NAFTA SOP Attachment examples</a> </li> - <li> - <a href="../../articles/web_only/benchmarks.html">Some benchmark timings</a> - </li> </ul> </li> <li> @@ -100,10 +97,10 @@ <h1 data-toc-skip>Performance benefit by using compiled model definitions in mkin</h1> <h4 class="author">Johannes Ranke</h4> - <h4 class="date">2020-05-14</h4> + <h4 class="date">2020-05-27</h4> - <small class="dont-index">Source: <a href="http://github.com/jranke/mkin/blob/master/vignettes/web_only/compiled_models.rmd"><code>vignettes/web_only/compiled_models.rmd</code></a></small> - <div class="hidden name"><code>compiled_models.rmd</code></div> + <small class="dont-index">Source: <a href="http://github.com/jranke/mkin/blob/master/vignettes/web_only/compiled_models.Rmd"><code>vignettes/web_only/compiled_models.Rmd</code></a></small> + <div class="hidden name"><code>compiled_models.Rmd</code></div> </div> @@ -122,57 +119,56 @@ <p>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</p> <div class="sourceCode" id="cb3"><html><body><pre class="r"><span class="fu"><a href="https://rdrr.io/r/base/Sys.getenv.html">Sys.getenv</a></span>(<span class="st">"HOME"</span>)</pre></body></html></div> </div> -<div id="comparison-with-other-solution-methods" class="section level2"> +<div id="comparison-with-eigenvalue-based-solutions" class="section level2"> <h2 class="hasAnchor"> -<a href="#comparison-with-other-solution-methods" class="anchor"></a>Comparison with other solution methods</h2> -<p>First, we build a simple degradation model for a parent compound with one metabolite, and we remove zero values from the dataset.</p> +<a href="#comparison-with-eigenvalue-based-solutions" class="anchor"></a>Comparison with Eigenvalue based solutions</h2> +<p>First, we build a simple degradation model for a parent compound with one metabolite.</p> <div class="sourceCode" id="cb4"><html><body><pre class="r"><span class="fu"><a href="https://rdrr.io/r/base/library.html">library</a></span>(<span class="st">"mkin"</span>, <span class="kw">quietly</span> <span class="kw">=</span> <span class="fl">TRUE</span>) <span class="no">SFO_SFO</span> <span class="kw"><-</span> <span class="fu"><a href="../../reference/mkinmod.html">mkinmod</a></span>( <span class="kw">parent</span> <span class="kw">=</span> <span class="fu"><a href="../../reference/mkinsub.html">mkinsub</a></span>(<span class="st">"SFO"</span>, <span class="st">"m1"</span>), <span class="kw">m1</span> <span class="kw">=</span> <span class="fu"><a href="../../reference/mkinsub.html">mkinsub</a></span>(<span class="st">"SFO"</span>))</pre></body></html></div> <pre><code>## Successfully compiled differential equation model from auto-generated C code.</code></pre> -<div class="sourceCode" id="cb6"><html><body><pre class="r"><span class="no">FOCUS_D</span> <span class="kw"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/subset.html">subset</a></span>(<span class="no">FOCUS_2006_D</span>, <span class="no">value</span> <span class="kw">!=</span> <span class="fl">0</span>)</pre></body></html></div> -<p>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.</p> -<div class="sourceCode" id="cb7"><html><body><pre class="r"><span class="kw">if</span> (<span class="fu"><a href="https://rdrr.io/r/base/library.html">require</a></span>(<span class="no">rbenchmark</span>)) { +<p>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.</p> +<div class="sourceCode" id="cb6"><html><body><pre class="r"><span class="kw">if</span> (<span class="fu"><a href="https://rdrr.io/r/base/library.html">require</a></span>(<span class="no">rbenchmark</span>)) { <span class="no">b.1</span> <span class="kw"><-</span> <span class="fu"><a href="https://rdrr.io/pkg/rbenchmark/man/benchmark.html">benchmark</a></span>( - <span class="st">"deSolve, not compiled"</span> <span class="kw">=</span> <span class="fu"><a href="../../reference/mkinfit.html">mkinfit</a></span>(<span class="no">SFO_SFO</span>, <span class="no">FOCUS_D</span>, - <span class="kw">solution_type</span> <span class="kw">=</span> <span class="st">"deSolve"</span>, - <span class="kw">use_compiled</span> <span class="kw">=</span> <span class="fl">FALSE</span>, <span class="kw">quiet</span> <span class="kw">=</span> <span class="fl">TRUE</span>), - <span class="st">"Eigenvalue based"</span> <span class="kw">=</span> <span class="fu"><a href="../../reference/mkinfit.html">mkinfit</a></span>(<span class="no">SFO_SFO</span>, <span class="no">FOCUS_D</span>, - <span class="kw">solution_type</span> <span class="kw">=</span> <span class="st">"eigen"</span>, <span class="kw">quiet</span> <span class="kw">=</span> <span class="fl">TRUE</span>), - <span class="st">"deSolve, compiled"</span> <span class="kw">=</span> <span class="fu"><a href="../../reference/mkinfit.html">mkinfit</a></span>(<span class="no">SFO_SFO</span>, <span class="no">FOCUS_D</span>, - <span class="kw">solution_type</span> <span class="kw">=</span> <span class="st">"deSolve"</span>, <span class="kw">quiet</span> <span class="kw">=</span> <span class="fl">TRUE</span>), - <span class="st">"analytical"</span> <span class="kw">=</span> <span class="fu"><a href="../../reference/mkinfit.html">mkinfit</a></span>(<span class="no">SFO_SFO</span>, <span class="no">FOCUS_D</span>, - <span class="kw">solution_type</span> <span class="kw">=</span> <span class="st">"analytical"</span>, - <span class="kw">use_compiled</span> <span class="kw">=</span> <span class="fl">FALSE</span>, <span class="kw">quiet</span> <span class="kw">=</span> <span class="fl">TRUE</span>), - <span class="kw">replications</span> <span class="kw">=</span> <span class="fl">1</span>, <span class="kw">order</span> <span class="kw">=</span> <span class="st">"relative"</span>, - <span class="kw">columns</span> <span class="kw">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="st">"test"</span>, <span class="st">"replications"</span>, <span class="st">"relative"</span>, <span class="st">"elapsed"</span>)) + <span class="st">"deSolve, not compiled"</span> <span class="kw">=</span> <span class="fu"><a href="../../reference/mkinfit.html">mkinfit</a></span>(<span class="no">SFO_SFO</span>, <span class="no">FOCUS_2006_D</span>, + <span class="kw">solution_type</span> <span class="kw">=</span> <span class="st">"deSolve"</span>, + <span class="kw">use_compiled</span> <span class="kw">=</span> <span class="fl">FALSE</span>, <span class="kw">quiet</span> <span class="kw">=</span> <span class="fl">TRUE</span>), + <span class="st">"Eigenvalue based"</span> <span class="kw">=</span> <span class="fu"><a href="../../reference/mkinfit.html">mkinfit</a></span>(<span class="no">SFO_SFO</span>, <span class="no">FOCUS_2006_D</span>, + <span class="kw">solution_type</span> <span class="kw">=</span> <span class="st">"eigen"</span>, <span class="kw">quiet</span> <span class="kw">=</span> <span class="fl">TRUE</span>), + <span class="st">"deSolve, compiled"</span> <span class="kw">=</span> <span class="fu"><a href="../../reference/mkinfit.html">mkinfit</a></span>(<span class="no">SFO_SFO</span>, <span class="no">FOCUS_2006_D</span>, + <span class="kw">solution_type</span> <span class="kw">=</span> <span class="st">"deSolve"</span>, <span class="kw">quiet</span> <span class="kw">=</span> <span class="fl">TRUE</span>), + <span class="kw">replications</span> <span class="kw">=</span> <span class="fl">3</span>) <span class="fu"><a href="https://rdrr.io/r/base/print.html">print</a></span>(<span class="no">b.1</span>) + <span class="no">factor_SFO_SFO</span> <span class="kw"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/Round.html">round</a></span>(<span class="no">b.1</span>[<span class="st">"1"</span>, <span class="st">"relative"</span>]) } <span class="kw">else</span> { + <span class="no">factor_SFO_SFO</span> <span class="kw"><-</span> <span class="fl">NA</span> <span class="fu"><a href="https://rdrr.io/r/base/print.html">print</a></span>(<span class="st">"R package rbenchmark is not available"</span>) }</pre></body></html></div> -<pre><code>## test replications relative elapsed -## 4 analytical 1 1.000 0.191 -## 3 deSolve, compiled 1 1.801 0.344 -## 2 Eigenvalue based 1 2.105 0.402 -## 1 deSolve, not compiled 1 42.864 8.187</code></pre> -<p>We see that using the compiled model is by more than a factor of 10 faster than using deSolve without compiled code.</p> +<pre><code>## test replications elapsed relative user.self sys.self +## 3 deSolve, compiled 3 0.997 1.000 0.997 0.000 +## 1 deSolve, not compiled 3 24.417 24.490 24.405 0.001 +## 2 Eigenvalue based 3 1.159 1.162 1.159 0.000 +## user.child sys.child +## 3 0 0 +## 1 0 0 +## 2 0 0</code></pre> +<p>We see that using the compiled model is by a factor of around 24 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.</p> </div> -<div id="model-without-analytical-solution" class="section level2"> +<div id="model-that-can-not-be-solved-with-eigenvalues" class="section level2"> <h2 class="hasAnchor"> -<a href="#model-without-analytical-solution" class="anchor"></a>Model without analytical solution</h2> -<p>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.</p> -<div class="sourceCode" id="cb9"><html><body><pre class="r"><span class="kw">if</span> (<span class="fu"><a href="https://rdrr.io/r/base/library.html">require</a></span>(<span class="no">rbenchmark</span>)) { +<a href="#model-that-can-not-be-solved-with-eigenvalues" class="anchor"></a>Model that can not be solved with Eigenvalues</h2> +<p>This evaluation is also taken from the example section of mkinfit.</p> +<div class="sourceCode" id="cb8"><html><body><pre class="r"><span class="kw">if</span> (<span class="fu"><a href="https://rdrr.io/r/base/library.html">require</a></span>(<span class="no">rbenchmark</span>)) { <span class="no">FOMC_SFO</span> <span class="kw"><-</span> <span class="fu"><a href="../../reference/mkinmod.html">mkinmod</a></span>( <span class="kw">parent</span> <span class="kw">=</span> <span class="fu"><a href="../../reference/mkinsub.html">mkinsub</a></span>(<span class="st">"FOMC"</span>, <span class="st">"m1"</span>), <span class="kw">m1</span> <span class="kw">=</span> <span class="fu"><a href="../../reference/mkinsub.html">mkinsub</a></span>( <span class="st">"SFO"</span>)) <span class="no">b.2</span> <span class="kw"><-</span> <span class="fu"><a href="https://rdrr.io/pkg/rbenchmark/man/benchmark.html">benchmark</a></span>( - <span class="st">"deSolve, not compiled"</span> <span class="kw">=</span> <span class="fu"><a href="../../reference/mkinfit.html">mkinfit</a></span>(<span class="no">FOMC_SFO</span>, <span class="no">FOCUS_D</span>, + <span class="st">"deSolve, not compiled"</span> <span class="kw">=</span> <span class="fu"><a href="../../reference/mkinfit.html">mkinfit</a></span>(<span class="no">FOMC_SFO</span>, <span class="no">FOCUS_2006_D</span>, <span class="kw">use_compiled</span> <span class="kw">=</span> <span class="fl">FALSE</span>, <span class="kw">quiet</span> <span class="kw">=</span> <span class="fl">TRUE</span>), - <span class="st">"deSolve, compiled"</span> <span class="kw">=</span> <span class="fu"><a href="../../reference/mkinfit.html">mkinfit</a></span>(<span class="no">FOMC_SFO</span>, <span class="no">FOCUS_D</span>, <span class="kw">quiet</span> <span class="kw">=</span> <span class="fl">TRUE</span>), - <span class="kw">replications</span> <span class="kw">=</span> <span class="fl">1</span>, <span class="kw">order</span> <span class="kw">=</span> <span class="st">"relative"</span>, - <span class="kw">columns</span> <span class="kw">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="st">"test"</span>, <span class="st">"replications"</span>, <span class="st">"relative"</span>, <span class="st">"elapsed"</span>)) + <span class="st">"deSolve, compiled"</span> <span class="kw">=</span> <span class="fu"><a href="../../reference/mkinfit.html">mkinfit</a></span>(<span class="no">FOMC_SFO</span>, <span class="no">FOCUS_2006_D</span>, <span class="kw">quiet</span> <span class="kw">=</span> <span class="fl">TRUE</span>), + <span class="kw">replications</span> <span class="kw">=</span> <span class="fl">3</span>) <span class="fu"><a href="https://rdrr.io/r/base/print.html">print</a></span>(<span class="no">b.2</span>) <span class="no">factor_FOMC_SFO</span> <span class="kw"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/Round.html">round</a></span>(<span class="no">b.2</span>[<span class="st">"1"</span>, <span class="st">"relative"</span>]) } <span class="kw">else</span> { @@ -180,9 +176,12 @@ <span class="fu"><a href="https://rdrr.io/r/base/print.html">print</a></span>(<span class="st">"R package benchmark is not available"</span>) }</pre></body></html></div> <pre><code>## Successfully compiled differential equation model from auto-generated C code.</code></pre> -<pre><code>## test replications relative elapsed -## 2 deSolve, compiled 1 1.000 0.466 -## 1 deSolve, not compiled 1 30.942 14.419</code></pre> +<pre><code>## test replications elapsed relative user.self sys.self +## 2 deSolve, compiled 3 1.392 1.000 1.391 0 +## 1 deSolve, not compiled 3 43.021 30.906 43.002 0 +## user.child sys.child +## 2 0 0 +## 1 0 0</code></pre> <p>Here we get a performance benefit of a factor of 31 using the version of the differential equation model compiled from C code!</p> <p>This vignette was built with mkin 0.9.50.2 on</p> <pre><code>## R version 4.0.0 (2020-04-24) |