aboutsummaryrefslogtreecommitdiff
path: root/docs/dev/articles/web_only/compiled_models.html
diff options
context:
space:
mode:
Diffstat (limited to 'docs/dev/articles/web_only/compiled_models.html')
-rw-r--r--docs/dev/articles/web_only/compiled_models.html119
1 files changed, 84 insertions, 35 deletions
diff --git a/docs/dev/articles/web_only/compiled_models.html b/docs/dev/articles/web_only/compiled_models.html
index e9d80420..e7905860 100644
--- a/docs/dev/articles/web_only/compiled_models.html
+++ b/docs/dev/articles/web_only/compiled_models.html
@@ -34,14 +34,14 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../../index.html">mkin</a>
- <span class="version label label-info" data-toggle="tooltip" data-placement="bottom" title="In-development version">1.2.2</span>
+ <span class="version label label-info" data-toggle="tooltip" data-placement="bottom" title="In-development version">1.2.3</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
- <a href="../../reference/index.html">Functions and data</a>
+ <a href="../../reference/index.html">Reference</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
@@ -53,6 +53,9 @@
<li>
<a href="../../articles/mkin.html">Introduction to mkin</a>
</li>
+ <li class="divider">
+ </li>
+<li class="dropdown-header">Example evaluations with (generalised) nonlinear least squares</li>
<li>
<a href="../../articles/FOCUS_D.html">Example evaluation of FOCUS Example Dataset D</a>
</li>
@@ -60,22 +63,31 @@
<a href="../../articles/FOCUS_L.html">Example evaluation of FOCUS Laboratory Data L1 to L3</a>
</li>
<li>
- <a href="../../articles/web_only/dimethenamid_2018.html">Example evaluations of dimethenamid data from 2018 with nonlinear mixed-effects models</a>
+ <a href="../../articles/web_only/FOCUS_Z.html">Example evaluation of FOCUS Example Dataset Z</a>
+ </li>
+ <li class="divider">
</li>
+<li class="dropdown-header">Example evaluations with hierarchical models (nonlinear mixed-effects models)</li>
<li>
- <a href="../../articles/web_only/multistart.html">Short demo of the multistart method</a>
+ <a href="../../articles/prebuilt/2022_dmta_parent.html">Testing hierarchical parent degradation kinetics with residue data on dimethenamid and dimethenamid-P</a>
</li>
<li>
- <a href="../../articles/web_only/compiled_models.html">Performance benefit by using compiled model definitions in mkin</a>
+ <a href="../../articles/prebuilt/2022_dmta_pathway.html">Testing hierarchical pathway kinetics with residue data on dimethenamid and dimethenamid-P</a>
</li>
<li>
- <a href="../../articles/web_only/FOCUS_Z.html">Example evaluation of FOCUS Example Dataset Z</a>
+ <a href="../../articles/prebuilt/2022_cyan_pathway.html">Testing hierarchical pathway kinetics with residue data on cyantraniliprole</a>
</li>
<li>
- <a href="../../articles/twa.html">Calculation of time weighted average concentrations with mkin</a>
+ <a href="../../articles/web_only/dimethenamid_2018.html">Comparison of saemix and nlme evaluations of dimethenamid data from 2018</a>
</li>
<li>
- <a href="../../articles/web_only/NAFTA_examples.html">Example evaluation of NAFTA SOP Attachment examples</a>
+ <a href="../../articles/web_only/multistart.html">Short demo of the multistart method</a>
+ </li>
+ <li class="divider">
+ </li>
+<li class="dropdown-header">Performance</li>
+ <li>
+ <a href="../../articles/web_only/compiled_models.html">Performance benefit by using compiled model definitions in mkin</a>
</li>
<li>
<a href="../../articles/web_only/benchmarks.html">Benchmark timings for mkin</a>
@@ -83,6 +95,15 @@
<li>
<a href="../../articles/web_only/saem_benchmarks.html">Benchmark timings for saem.mmkin</a>
</li>
+ <li class="divider">
+ </li>
+<li class="dropdown-header">Miscellaneous</li>
+ <li>
+ <a href="../../articles/twa.html">Calculation of time weighted average concentrations with mkin</a>
+ </li>
+ <li>
+ <a href="../../articles/web_only/NAFTA_examples.html">Example evaluation of NAFTA SOP Attachment examples</a>
+ </li>
</ul>
</li>
<li>
@@ -106,13 +127,15 @@
- </header><script src="compiled_models_files/accessible-code-block-0.0.1/empty-anchor.js"></script><div class="row">
+ </header><div class="row">
<div class="col-md-9 contents">
<div class="page-header toc-ignore">
- <h1 data-toc-skip>Performance benefit by using compiled model definitions in mkin</h1>
- <h4 data-toc-skip class="author">Johannes Ranke</h4>
+ <h1 data-toc-skip>Performance benefit by using compiled model
+definitions in mkin</h1>
+ <h4 data-toc-skip class="author">Johannes
+Ranke</h4>
- <h4 data-toc-skip class="date">2022-11-24</h4>
+ <h4 data-toc-skip class="date">2023-04-16</h4>
<small class="dont-index">Source: <a href="https://github.com/jranke/mkin/blob/HEAD/vignettes/web_only/compiled_models.rmd" class="external-link"><code>vignettes/web_only/compiled_models.rmd</code></a></small>
<div class="hidden name"><code>compiled_models.rmd</code></div>
@@ -124,23 +147,39 @@
<div class="section level2">
<h2 id="how-to-benefit-from-compiled-models">How to benefit from compiled models<a class="anchor" aria-label="anchor" href="#how-to-benefit-from-compiled-models"></a>
</h2>
-<p>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 <code><a href="../../reference/mkinmod.html">mkinmod()</a></code> function checks for presence of a compiler using</p>
+<p>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 <code><a href="../../reference/mkinmod.html">mkinmod()</a></code> function
+checks for presence of a compiler using</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
-<code class="sourceCode R"><span><span class="fu">pkgbuild</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/pkgbuild/man/has_compiler.html" class="external-link">has_compiler</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
-<p>In previous versions, it used <code>Sys.which("gcc")</code> for this check.</p>
-<p>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.</p>
-<p>On MacOS, which I do not use personally, I have had reports that a compiler is available by default.</p>
-<p>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</p>
+<code class="sourceCode R"><span><span class="fu">pkgbuild</span><span class="fu">::</span><span class="fu"><a href="https://r-lib.github.io/pkgbuild/reference/has_compiler.html" class="external-link">has_compiler</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
+<p>In previous versions, it used <code>Sys.which("gcc")</code> for this
+check.</p>
+<p>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.</p>
+<p>On MacOS, which I do not use personally, I have had reports that a
+compiler is available by default.</p>
+<p>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</p>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/base/Sys.setenv.html" class="external-link">Sys.setenv</a></span><span class="op">(</span>PATH <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/paste.html" class="external-link">paste</a></span><span class="op">(</span><span class="st">"C:/Rtools/bin"</span>, <span class="fu"><a href="https://rdrr.io/r/base/Sys.getenv.html" class="external-link">Sys.getenv</a></span><span class="op">(</span><span class="st">"PATH"</span><span class="op">)</span>, sep<span class="op">=</span><span class="st">";"</span><span class="op">)</span><span class="op">)</span></span></code></pre></div>
-<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>
+<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"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/base/Sys.getenv.html" class="external-link">Sys.getenv</a></span><span class="op">(</span><span class="st">"HOME"</span><span class="op">)</span></span></code></pre></div>
</div>
<div class="section level2">
<h2 id="comparison-with-other-solution-methods">Comparison with other solution methods<a class="anchor" aria-label="anchor" href="#comparison-with-other-solution-methods"></a>
</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>
+<p>First, we build a simple degradation model for a parent compound with
+one metabolite, and we remove zero values from the dataset.</p>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="st"><a href="https://pkgdown.jrwb.de/mkin/">"mkin"</a></span>, quietly <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span>
<span><span class="va">SFO_SFO</span> <span class="op">&lt;-</span> <span class="fu"><a href="../../reference/mkinmod.html">mkinmod</a></span><span class="op">(</span></span>
@@ -149,7 +188,12 @@
<pre><code><span><span class="co">## Temporary DLL for differentials generated and loaded</span></span></code></pre>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">FOCUS_D</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/subset.html" class="external-link">subset</a></span><span class="op">(</span><span class="va">FOCUS_2006_D</span>, <span class="va">value</span> <span class="op">!=</span> <span class="fl">0</span><span class="op">)</span></span></code></pre></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>
+<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"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="kw">if</span> <span class="op">(</span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">require</a></span><span class="op">(</span><span class="va"><a href="http://rbenchmark.googlecode.com" class="external-link">rbenchmark</a></span><span class="op">)</span><span class="op">)</span> <span class="op">{</span></span>
<span> <span class="va">b.1</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/rbenchmark/man/benchmark.html" class="external-link">benchmark</a></span><span class="op">(</span></span>
@@ -170,16 +214,20 @@
<span> <span class="fu"><a href="https://rdrr.io/r/base/print.html" class="external-link">print</a></span><span class="op">(</span><span class="st">"R package rbenchmark is not available"</span><span class="op">)</span></span>
<span><span class="op">}</span></span></code></pre></div>
<pre><code><span><span class="co">## test replications relative elapsed</span></span>
-<span><span class="co">## 4 analytical 1 1.000 0.221</span></span>
-<span><span class="co">## 3 deSolve, compiled 1 1.561 0.345</span></span>
-<span><span class="co">## 2 Eigenvalue based 1 1.932 0.427</span></span>
-<span><span class="co">## 1 deSolve, not compiled 1 33.629 7.432</span></span></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>
+<span><span class="co">## 4 analytical 1 1.000 0.105</span></span>
+<span><span class="co">## 3 deSolve, compiled 1 1.276 0.134</span></span>
+<span><span class="co">## 2 Eigenvalue based 1 1.762 0.185</span></span>
+<span><span class="co">## 1 deSolve, not compiled 1 21.914 2.301</span></span></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>
</div>
<div class="section level2">
<h2 id="model-without-analytical-solution">Model without analytical solution<a class="anchor" aria-label="anchor" href="#model-without-analytical-solution"></a>
</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>
+<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"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="kw">if</span> <span class="op">(</span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">require</a></span><span class="op">(</span><span class="va"><a href="http://rbenchmark.googlecode.com" class="external-link">rbenchmark</a></span><span class="op">)</span><span class="op">)</span> <span class="op">{</span></span>
<span> <span class="va">FOMC_SFO</span> <span class="op">&lt;-</span> <span class="fu"><a href="../../reference/mkinmod.html">mkinmod</a></span><span class="op">(</span></span>
@@ -200,14 +248,15 @@
<span><span class="op">}</span></span></code></pre></div>
<pre><code><span><span class="co">## Temporary DLL for differentials generated and loaded</span></span></code></pre>
<pre><code><span><span class="co">## test replications relative elapsed</span></span>
-<span><span class="co">## 2 deSolve, compiled 1 1.000 0.482</span></span>
-<span><span class="co">## 1 deSolve, not compiled 1 27.865 13.431</span></span></code></pre>
-<p>Here we get a performance benefit of a factor of 28 using the version of the differential equation model compiled from C code!</p>
-<p>This vignette was built with mkin 1.2.2 on</p>
-<pre><code><span><span class="co">## R version 4.2.2 (2022-10-31)</span></span>
+<span><span class="co">## 2 deSolve, compiled 1 1.000 0.176</span></span>
+<span><span class="co">## 1 deSolve, not compiled 1 23.938 4.213</span></span></code></pre>
+<p>Here we get a performance benefit of a factor of 24 using the version
+of the differential equation model compiled from C code!</p>
+<p>This vignette was built with mkin 1.2.3 on</p>
+<pre><code><span><span class="co">## R version 4.2.3 (2023-03-15)</span></span>
<span><span class="co">## Platform: x86_64-pc-linux-gnu (64-bit)</span></span>
-<span><span class="co">## Running under: Debian GNU/Linux 11 (bullseye)</span></span></code></pre>
-<pre><code><span><span class="co">## CPU model: AMD Ryzen 7 1700 Eight-Core Processor</span></span></code></pre>
+<span><span class="co">## Running under: Debian GNU/Linux 12 (bookworm)</span></span></code></pre>
+<pre><code><span><span class="co">## CPU model: AMD Ryzen 9 7950X 16-Core Processor</span></span></code></pre>
</div>
</div>
@@ -228,7 +277,7 @@
<div class="pkgdown">
<p></p>
-<p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.6.</p>
+<p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.7.</p>
</div>
</footer>

Contact - Imprint