1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-17 23:13:14 +02:00

(v1.7.1.9062) website update

This commit is contained in:
2021-12-06 11:12:30 +01:00
parent 1fa3fc6af2
commit e63defe324
97 changed files with 1768 additions and 3133 deletions

View File

@ -44,7 +44,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.7.1.9030</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.7.1.9062</span>
</span>
</div>
@ -185,13 +185,13 @@
</header><script src="benchmarks_files/header-attrs-2.9/header-attrs.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>Benchmarks</h1>
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/main/vignettes/benchmarks.Rmd" class="external-link"><code>vignettes/benchmarks.Rmd</code></a></small>
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/vignettes/benchmarks.Rmd" class="external-link"><code>vignettes/benchmarks.Rmd</code></a></small>
<div class="hidden name"><code>benchmarks.Rmd</code></div>
</div>
@ -202,7 +202,7 @@
<p>Using the <code>microbenchmark</code> package, we can review the calculation performance of this function. Its function <code><a href="https://rdrr.io/pkg/microbenchmark/man/microbenchmark.html" class="external-link">microbenchmark()</a></code> runs different input expressions independently of each other and measures their time-to-result.</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/joshuaulrich/microbenchmark/" class="external-link">microbenchmark</a></span><span class="op">)</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="va"><a href="https://github.com/msberends/AMR" class="external-link">AMR</a></span><span class="op">)</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="va"><a href="https://msberends.github.io/AMR">AMR</a></span><span class="op">)</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="va"><a href="https://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span></code></pre></div>
<p>In the next test, we try to coerce different input values into the microbial code of <em>Staphylococcus aureus</em>. Coercion is a computational process of forcing output based on an input. For microorganism names, coercing user input to taxonomically valid microorganism names is crucial to ensure correct interpretation and to enable grouping based on taxonomic properties.</p>
<p>The actual result is the same every time: it returns its microorganism code <code>B_STPHY_AURS</code> (<em>B</em> stands for <em>Bacteria</em>, its taxonomic kingdom).</p>
@ -224,42 +224,42 @@
times <span class="op">=</span> <span class="fl">25</span><span class="op">)</span>
<span class="fu"><a href="https://docs.ropensci.org/skimr/reference/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">S.aureus</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">2</span><span class="op">)</span>
<span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># as.mo("sau") 12.0 13.0 15.0 14.0 15.0 48 25</span>
<span class="co"># as.mo("stau") 54.0 57.0 73.0 62.0 92.0 99 25</span>
<span class="co"># as.mo("STAU") 54.0 58.0 73.0 63.0 91.0 98 25</span>
<span class="co"># as.mo("staaur") 13.0 13.0 20.0 14.0 15.0 52 25</span>
<span class="co"># as.mo("STAAUR") 11.0 13.0 18.0 14.0 16.0 47 25</span>
<span class="co"># as.mo("S. aureus") 27.0 30.0 38.0 31.0 36.0 63 25</span>
<span class="co"># as.mo("S aureus") 27.0 29.0 42.0 33.0 60.0 66 25</span>
<span class="co"># as.mo("Staphylococcus aureus") 3.8 4.1 6.8 4.2 4.6 36 25</span>
<span class="co"># as.mo("Staphylococcus aureus (MRSA)") 240.0 250.0 280.0 270.0 300.0 320 25</span>
<span class="co"># as.mo("Sthafilokkockus aaureuz") 160.0 190.0 200.0 200.0 210.0 340 25</span>
<span class="co"># as.mo("MRSA") 13.0 13.0 17.0 14.0 15.0 46 25</span>
<span class="co"># as.mo("VISA") 20.0 23.0 34.0 25.0 52.0 59 25</span></code></pre></div>
<span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># as.mo("sau") 12.0 13 18.0 14.0 15.0 45.0 25</span>
<span class="co"># as.mo("stau") 55.0 61 79.0 87.0 91.0 99.0 25</span>
<span class="co"># as.mo("STAU") 55.0 58 71.0 61.0 91.0 100.0 25</span>
<span class="co"># as.mo("staaur") 11.0 12 20.0 14.0 25.0 46.0 25</span>
<span class="co"># as.mo("STAAUR") 12.0 12 13.0 13.0 14.0 15.0 25</span>
<span class="co"># as.mo("S. aureus") 27.0 30 43.0 34.0 58.0 62.0 25</span>
<span class="co"># as.mo("S aureus") 26.0 28 43.0 32.0 59.0 66.0 25</span>
<span class="co"># as.mo("Staphylococcus aureus") 3.7 4 4.3 4.1 4.6 5.3 25</span>
<span class="co"># as.mo("Staphylococcus aureus (MRSA)") 250.0 250 280.0 280.0 290.0 390.0 25</span>
<span class="co"># as.mo("Sthafilokkockus aaureuz") 190.0 200 210.0 210.0 220.0 230.0 25</span>
<span class="co"># as.mo("MRSA") 10.0 12 18.0 14.0 14.0 43.0 25</span>
<span class="co"># as.mo("VISA") 19.0 22 29.0 24.0 26.0 55.0 25</span></code></pre></div>
<p><img src="benchmarks_files/figure-html/unnamed-chunk-4-1.png" width="750"></p>
<p>In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 5 milliseconds means it can determine 200 input values per second. It case of 200 milliseconds, this is only 5 input values per second. It is clear that accepted taxonomic names are extremely fast, but some variations are up to 200 times slower to determine.</p>
<p>To improve performance, we implemented two important algorithms to save unnecessary calculations: <strong>repetitive results</strong> and <strong>already precalculated results</strong>.</p>
<div id="repetitive-results" class="section level3">
<h3 class="hasAnchor">
<a href="#repetitive-results" class="anchor" aria-hidden="true"></a>Repetitive results</h3>
<p>Repetitive results are values that are present more than once in a vector. Unique values will only be calculated once by <code><a href="../reference/as.mo.html">as.mo()</a></code>. So running <code><a href="../reference/as.mo.html">as.mo(c("E. coli", "E. coli"))</a></code> will check the value <code>"E. coli"</code> only once.</p>
<div class="section level3">
<h3 id="repetitive-results">Repetitive results<a class="anchor" aria-label="anchor" href="#repetitive-results"></a>
</h3>
<p>Repetitive results are values that are present more than once in a vector. Unique values will only be calculated once by <code><a href="../reference/as.mo.html">as.mo()</a></code>. So running <code>as.mo(c("E. coli", "E. coli"))</code> will check the value <code>"E. coli"</code> only once.</p>
<p>To prove this, we will use <code><a href="../reference/mo_property.html">mo_name()</a></code> for testing - a helper function that returns the full microbial name (genus, species and possibly subspecies) which uses <code><a href="../reference/as.mo.html">as.mo()</a></code> internally.</p>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># start with the example_isolates data set</span>
<span class="va">x</span> <span class="op">&lt;-</span> <span class="va">example_isolates</span> <span class="op">%&gt;%</span>
<span class="va">x</span> <span class="op">&lt;-</span> <span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
<span class="co"># take all MO codes from the 'mo' column</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/pull.html" class="external-link">pull</a></span><span class="op">(</span><span class="va">mo</span><span class="op">)</span> <span class="op">%&gt;%</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/pull.html" class="external-link">pull</a></span><span class="op">(</span><span class="va">mo</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
<span class="co"># and copy them a thousand times</span>
<span class="fu"><a href="https://rdrr.io/r/base/rep.html" class="external-link">rep</a></span><span class="op">(</span><span class="fl">1000</span><span class="op">)</span> <span class="op">%&gt;%</span>
<span class="fu"><a href="https://rdrr.io/r/base/rep.html" class="external-link">rep</a></span><span class="op">(</span><span class="fl">1000</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
<span class="co"># then scramble them</span>
<span class="fu"><a href="https://rdrr.io/r/base/sample.html" class="external-link">sample</a></span><span class="op">(</span><span class="op">)</span>
<span class="co"># what do these values look like? They are of class &lt;mo&gt;:</span>
<span class="fu"><a href="https://rdrr.io/r/utils/head.html" class="external-link">head</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span>
<span class="co"># Class &lt;mo&gt;</span>
<span class="co"># [1] B_STRPT_PNMN B_KLBSL_PNMN B_ESCHR_COLI B_SERRT_MRCS B_STPHY_CONS</span>
<span class="co"># [6] B_ESCHR_COLI</span>
<span class="co"># [1] B_STPHY_CONS B_STPHY_EPDR B_STPHY_CONS B_STRPT_PNMN B_STRPT_EQNS</span>
<span class="co"># [6] B_STPHY_AURS</span>
<span class="co"># as the example_isolates data set has 2,000 rows, we should have 2 million items</span>
<span class="fu"><a href="https://rdrr.io/r/base/length.html" class="external-link">length</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span>
@ -275,12 +275,12 @@
<span class="fu"><a href="https://docs.ropensci.org/skimr/reference/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">3</span><span class="op">)</span>
<span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># mo_name(x) 188 202 260 233 335 408 10</span></code></pre></div>
<p>So getting official taxonomic names of 2,000,000 (!!) items consisting of 90 unique values only takes 0.233 seconds. That is 116 nanoseconds on average. You only lose time on your unique input values.</p>
<span class="co"># mo_name(x) 190 204 271 259 346 372 10</span></code></pre></div>
<p>So getting official taxonomic names of 2,000,000 (!!) items consisting of 90 unique values only takes 0.259 seconds. That is 130 nanoseconds on average. You only lose time on your unique input values.</p>
</div>
<div id="precalculated-results" class="section level3">
<h3 class="hasAnchor">
<a href="#precalculated-results" class="anchor" aria-hidden="true"></a>Precalculated results</h3>
<div class="section level3">
<h3 id="precalculated-results">Precalculated results<a class="anchor" aria-label="anchor" href="#precalculated-results"></a>
</h3>
<p>What about precalculated results? If the input is an already precalculated result of a helper function such as <code><a href="../reference/mo_property.html">mo_name()</a></code>, it almost doesnt take any time at all. In other words, if you run <code><a href="../reference/mo_property.html">mo_name()</a></code> on a valid taxonomic name, it will return the results immediately (see C below):</p>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">run_it</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/microbenchmark/man/microbenchmark.html" class="external-link">microbenchmark</a></span><span class="op">(</span>A <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="st">"STAAUR"</span><span class="op">)</span>,
@ -290,10 +290,10 @@
<span class="fu"><a href="https://docs.ropensci.org/skimr/reference/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">3</span><span class="op">)</span>
<span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># A 8.09 8.18 8.94 8.69 9.47 10.50 10</span>
<span class="co"># B 23.40 24.90 31.90 27.90 28.20 80.70 10</span>
<span class="co"># C 2.03 2.20 2.35 2.35 2.48 2.66 10</span></code></pre></div>
<p>So going from <code><a href="../reference/mo_property.html">mo_name("Staphylococcus aureus")</a></code> to <code>"Staphylococcus aureus"</code> takes 0.0023 seconds - it doesnt even start calculating <em>if the result would be the same as the expected resulting value</em>. That goes for all helper functions:</p>
<span class="co"># A 8.16 8.77 9.77 10.10 10.60 10.90 10</span>
<span class="co"># B 23.20 26.60 32.00 27.50 28.90 76.30 10</span>
<span class="co"># C 2.01 2.24 2.44 2.44 2.67 2.91 10</span></code></pre></div>
<p>So going from <code>mo_name("Staphylococcus aureus")</code> to <code>"Staphylococcus aureus"</code> takes 0.0024 seconds - it doesnt even start calculating <em>if the result would be the same as the expected resulting value</em>. That goes for all helper functions:</p>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">run_it</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/microbenchmark/man/microbenchmark.html" class="external-link">microbenchmark</a></span><span class="op">(</span>A <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_species</a></span><span class="op">(</span><span class="st">"aureus"</span><span class="op">)</span>,
B <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_genus</a></span><span class="op">(</span><span class="st">"Staphylococcus"</span><span class="op">)</span>,
@ -307,19 +307,19 @@
<span class="fu"><a href="https://docs.ropensci.org/skimr/reference/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">3</span><span class="op">)</span>
<span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># A 1.68 1.72 1.88 1.88 1.97 2.32 10</span>
<span class="co"># B 1.64 1.80 1.90 1.95 1.98 2.14 10</span>
<span class="co"># C 1.71 1.74 1.88 1.80 2.08 2.21 10</span>
<span class="co"># D 1.70 1.79 1.86 1.87 1.96 1.99 10</span>
<span class="co"># E 1.73 1.85 1.94 1.91 2.03 2.20 10</span>
<span class="co"># F 1.71 1.78 1.91 1.89 2.00 2.25 10</span>
<span class="co"># G 1.66 1.78 1.87 1.88 1.98 2.04 10</span>
<span class="co"># H 1.73 1.82 2.06 1.98 2.07 2.80 10</span></code></pre></div>
<p>Of course, when running <code><a href="../reference/mo_property.html">mo_phylum("Firmicutes")</a></code> the function has zero knowledge about the actual microorganism, namely <em>S. aureus</em>. But since the result would be <code>"Firmicutes"</code> anyway, there is no point in calculating the result. And because this package contains all phyla of all known bacteria, it can just return the initial value immediately.</p>
<span class="co"># A 1.57 1.61 1.69 1.65 1.77 1.91 10</span>
<span class="co"># B 1.54 1.59 1.73 1.64 1.84 2.19 10</span>
<span class="co"># C 1.56 1.63 1.76 1.75 1.77 2.11 10</span>
<span class="co"># D 1.58 1.59 1.73 1.65 1.66 2.62 10</span>
<span class="co"># E 1.55 1.62 1.70 1.66 1.72 2.13 10</span>
<span class="co"># F 1.58 1.62 1.81 1.72 1.81 2.61 10</span>
<span class="co"># G 1.54 1.65 1.73 1.69 1.71 2.32 10</span>
<span class="co"># H 1.58 1.65 1.80 1.74 1.84 2.24 10</span></code></pre></div>
<p>Of course, when running <code>mo_phylum("Firmicutes")</code> the function has zero knowledge about the actual microorganism, namely <em>S. aureus</em>. But since the result would be <code>"Firmicutes"</code> anyway, there is no point in calculating the result. And because this package contains all phyla of all known bacteria, it can just return the initial value immediately.</p>
</div>
<div id="results-in-other-languages" class="section level3">
<h3 class="hasAnchor">
<a href="#results-in-other-languages" class="anchor" aria-hidden="true"></a>Results in other languages</h3>
<div class="section level3">
<h3 id="results-in-other-languages">Results in other languages<a class="anchor" aria-label="anchor" href="#results-in-other-languages"></a>
</h3>
<p>When the system language is non-English and supported by this <code>AMR</code> package, some functions will have a translated result. This almost doest take extra time:</p>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="st">"CoNS"</span>, language <span class="op">=</span> <span class="st">"en"</span><span class="op">)</span> <span class="co"># or just mo_name("CoNS") on an English system</span>
@ -342,13 +342,13 @@
<span class="fu"><a href="https://docs.ropensci.org/skimr/reference/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">4</span><span class="op">)</span>
<span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># en 19.64 20.10 28.32 20.72 22.65 104.80 100</span>
<span class="co"># de 30.76 31.59 37.06 32.27 33.87 95.10 100</span>
<span class="co"># nl 34.88 35.58 43.87 36.41 38.73 94.00 100</span>
<span class="co"># es 34.62 35.22 44.72 36.04 37.88 97.92 100</span>
<span class="co"># it 24.03 24.59 28.09 25.19 26.12 79.32 100</span>
<span class="co"># fr 23.79 24.37 30.37 24.89 26.29 194.10 100</span>
<span class="co"># pt 23.85 24.42 28.21 24.90 26.22 83.14 100</span></code></pre></div>
<span class="co"># en 19.38 19.92 23.08 20.50 21.40 67.58 100</span>
<span class="co"># de 30.74 31.50 39.35 32.08 33.43 201.20 100</span>
<span class="co"># nl 34.89 35.54 43.82 36.15 37.79 86.27 100</span>
<span class="co"># es 34.62 35.30 42.36 35.99 37.61 90.39 100</span>
<span class="co"># it 33.42 34.36 41.50 35.13 36.40 84.45 100</span>
<span class="co"># fr 32.86 33.35 38.69 34.20 35.26 82.96 100</span>
<span class="co"># pt 30.76 31.42 37.89 32.17 33.33 84.66 100</span></code></pre></div>
<p>Currently supported non-English languages are German, Dutch, Spanish, Italian, French and Portuguese.</p>
</div>
</div>
@ -363,12 +363,12 @@
<footer><div class="copyright">
<p></p>
<p>Developed by <a href="https://www.rug.nl/staff/m.s.berends/" class="external-link external-link">Matthijs S. Berends</a>, <a href="https://www.rug.nl/staff/c.f.luz/" class="external-link external-link">Christian F. Luz</a>, <a href="https://www.rug.nl/staff/a.w.friedrich/" class="external-link external-link">Alexander W. Friedrich</a>, <a href="https://www.rug.nl/staff/b.sinha/" class="external-link external-link">Bhanu N. M. Sinha</a>, <a href="https://www.rug.nl/staff/c.j.albers/" class="external-link external-link">Casper J. Albers</a>, <a href="https://www.rug.nl/staff/c.glasner/" class="external-link external-link">Corinna Glasner</a>.</p>
<p>Developed by Matthijs S. Berends, Christian F. Luz, Dennis Souverein, Erwin E. A. Hassing.</p>
</div>
<div class="pkgdown">
<p></p>
<p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link external-link">pkgdown</a> 1.6.1.9001.</p>
<p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.0.</p>
</div>
</footer>