mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 18:01:50 +02:00
faster determination of abx
This commit is contained in:
@ -40,7 +40,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="Released version">0.6.1.9003</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.6.1.9034</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@ -217,14 +217,14 @@
|
||||
<a class="sourceLine" id="cb2-8" title="8"> <span class="dt">times =</span> <span class="dv">10</span>)</a>
|
||||
<a class="sourceLine" id="cb2-9" title="9"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(S.aureus, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">signif =</span> <span class="dv">2</span>)</a>
|
||||
<a class="sourceLine" id="cb2-10" title="10"><span class="co"># Unit: milliseconds</span></a>
|
||||
<a class="sourceLine" id="cb2-11" title="11"><span class="co"># expr min lq mean median uq max neval</span></a>
|
||||
<a class="sourceLine" id="cb2-12" title="12"><span class="co"># as.mo("sau") 17 17 22.0 18 18.0 66 10</span></a>
|
||||
<a class="sourceLine" id="cb2-13" title="13"><span class="co"># as.mo("stau") 47 48 52.0 48 48.0 92 10</span></a>
|
||||
<a class="sourceLine" id="cb2-14" title="14"><span class="co"># as.mo("staaur") 18 18 35.0 18 62.0 66 10</span></a>
|
||||
<a class="sourceLine" id="cb2-15" title="15"><span class="co"># as.mo("STAAUR") 17 18 25.0 18 18.0 54 10</span></a>
|
||||
<a class="sourceLine" id="cb2-16" title="16"><span class="co"># as.mo("S. aureus") 28 28 41.0 28 72.0 73 10</span></a>
|
||||
<a class="sourceLine" id="cb2-17" title="17"><span class="co"># as.mo("S. aureus") 28 28 41.0 28 28.0 120 10</span></a>
|
||||
<a class="sourceLine" id="cb2-18" title="18"><span class="co"># as.mo("Staphylococcus aureus") 8 8 9.3 8 8.1 20 10</span></a></code></pre></div>
|
||||
<a class="sourceLine" id="cb2-11" title="11"><span class="co"># expr min lq mean median uq max neval</span></a>
|
||||
<a class="sourceLine" id="cb2-12" title="12"><span class="co"># as.mo("sau") 18 18 22.0 18 18.0 62.0 10</span></a>
|
||||
<a class="sourceLine" id="cb2-13" title="13"><span class="co"># as.mo("stau") 47 47 57.0 48 50.0 92.0 10</span></a>
|
||||
<a class="sourceLine" id="cb2-14" title="14"><span class="co"># as.mo("staaur") 17 18 23.0 18 19.0 62.0 10</span></a>
|
||||
<a class="sourceLine" id="cb2-15" title="15"><span class="co"># as.mo("STAAUR") 17 17 18.0 17 18.0 23.0 10</span></a>
|
||||
<a class="sourceLine" id="cb2-16" title="16"><span class="co"># as.mo("S. aureus") 28 28 38.0 29 29.0 78.0 10</span></a>
|
||||
<a class="sourceLine" id="cb2-17" title="17"><span class="co"># as.mo("S. aureus") 28 28 48.0 29 73.0 130.0 10</span></a>
|
||||
<a class="sourceLine" id="cb2-18" title="18"><span class="co"># as.mo("Staphylococcus aureus") 8 8 8.1 8 8.1 8.2 10</span></a></code></pre></div>
|
||||
<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 100 milliseconds, this is only 10 input values per second. The second input is the only one that has to be looked up thoroughly. All the others are known codes (the first one is a WHONET code) or common laboratory codes, or common full organism names like the last one. Full organism names are always preferred.</p>
|
||||
<p>To achieve this speed, the <code>as.mo</code> function also takes into account the prevalence of human pathogenic microorganisms. The downside is of course that less prevalent microorganisms will be determined less fast. See this example for the ID of <em>Thermus islandicus</em> (<code>B_THERMS_ISL</code>), a bug probably never found before in humans:</p>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" title="1">T.islandicus <-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/microbenchmark/topics/microbenchmark">microbenchmark</a></span>(<span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"theisl"</span>),</a>
|
||||
@ -236,12 +236,12 @@
|
||||
<a class="sourceLine" id="cb3-7" title="7"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(T.islandicus, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">signif =</span> <span class="dv">2</span>)</a>
|
||||
<a class="sourceLine" id="cb3-8" title="8"><span class="co"># Unit: milliseconds</span></a>
|
||||
<a class="sourceLine" id="cb3-9" title="9"><span class="co"># expr min lq mean median uq max neval</span></a>
|
||||
<a class="sourceLine" id="cb3-10" title="10"><span class="co"># as.mo("theisl") 470 470 500 510 520 530 10</span></a>
|
||||
<a class="sourceLine" id="cb3-11" title="11"><span class="co"># as.mo("THEISL") 470 470 490 470 520 520 10</span></a>
|
||||
<a class="sourceLine" id="cb3-12" title="12"><span class="co"># as.mo("T. islandicus") 74 74 87 74 120 120 10</span></a>
|
||||
<a class="sourceLine" id="cb3-13" title="13"><span class="co"># as.mo("T. islandicus") 74 74 89 74 120 140 10</span></a>
|
||||
<a class="sourceLine" id="cb3-14" title="14"><span class="co"># as.mo("Thermus islandicus") 73 73 93 74 120 120 10</span></a></code></pre></div>
|
||||
<p>That takes 7.8 times as much time on average. A value of 100 milliseconds means it can only determine ~10 different input values per second. We can conclude that looking up arbitrary codes of less prevalent microorganisms is the worst way to go, in terms of calculation performance. Full names (like <em>Thermus islandicus</em>) are almost fast - these are the most probable input from most data sets.</p>
|
||||
<a class="sourceLine" id="cb3-10" title="10"><span class="co"># as.mo("theisl") 470 480 510 520 530 530 10</span></a>
|
||||
<a class="sourceLine" id="cb3-11" title="11"><span class="co"># as.mo("THEISL") 470 470 500 490 520 530 10</span></a>
|
||||
<a class="sourceLine" id="cb3-12" title="12"><span class="co"># as.mo("T. islandicus") 74 75 85 76 81 120 10</span></a>
|
||||
<a class="sourceLine" id="cb3-13" title="13"><span class="co"># as.mo("T. islandicus") 74 75 92 76 120 140 10</span></a>
|
||||
<a class="sourceLine" id="cb3-14" title="14"><span class="co"># as.mo("Thermus islandicus") 73 73 74 74 74 75 10</span></a></code></pre></div>
|
||||
<p>That takes 8.2 times as much time on average. A value of 100 milliseconds means it can only determine ~10 different input values per second. We can conclude that looking up arbitrary codes of less prevalent microorganisms is the worst way to go, in terms of calculation performance. Full names (like <em>Thermus islandicus</em>) are almost fast - these are the most probable input from most data sets.</p>
|
||||
<p>In the figure below, we compare <em>Escherichia coli</em> (which is very common) with <em>Prevotella brevis</em> (which is moderately common) and with <em>Thermus islandicus</em> (which is very uncommon):</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/graphics/topics/par">par</a></span>(<span class="dt">mar =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">5</span>, <span class="dv">16</span>, <span class="dv">4</span>, <span class="dv">2</span>)) <span class="co"># set more space for left margin text (16)</span></a>
|
||||
<a class="sourceLine" id="cb4-2" title="2"></a>
|
||||
@ -287,8 +287,8 @@
|
||||
<a class="sourceLine" id="cb5-24" title="24"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(run_it, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">signif =</span> <span class="dv">3</span>)</a>
|
||||
<a class="sourceLine" id="cb5-25" title="25"><span class="co"># Unit: milliseconds</span></a>
|
||||
<a class="sourceLine" id="cb5-26" title="26"><span class="co"># expr min lq mean median uq max neval</span></a>
|
||||
<a class="sourceLine" id="cb5-27" title="27"><span class="co"># mo_fullname(x) 639 681 745 720 770 910 10</span></a></code></pre></div>
|
||||
<p>So transforming 500,000 values (!!) of 50 unique values only takes 0.72 seconds (719 ms). You only lose time on your unique input values.</p>
|
||||
<a class="sourceLine" id="cb5-27" title="27"><span class="co"># mo_fullname(x) 677 770 812 790 884 988 10</span></a></code></pre></div>
|
||||
<p>So transforming 500,000 values (!!) of 50 unique values only takes 0.79 seconds (789 ms). You only lose time on your unique input values.</p>
|
||||
</div>
|
||||
<div id="precalculated-results" class="section level3">
|
||||
<h3 class="hasAnchor">
|
||||
@ -300,10 +300,10 @@
|
||||
<a class="sourceLine" id="cb6-4" title="4"> <span class="dt">times =</span> <span class="dv">10</span>)</a>
|
||||
<a class="sourceLine" id="cb6-5" title="5"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(run_it, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">signif =</span> <span class="dv">3</span>)</a>
|
||||
<a class="sourceLine" id="cb6-6" title="6"><span class="co"># Unit: milliseconds</span></a>
|
||||
<a class="sourceLine" id="cb6-7" title="7"><span class="co"># expr min lq mean median uq max neval</span></a>
|
||||
<a class="sourceLine" id="cb6-8" title="8"><span class="co"># A 12.90 13.2 13.40 13.40 13.80 14.00 10</span></a>
|
||||
<a class="sourceLine" id="cb6-9" title="9"><span class="co"># B 25.30 25.7 31.00 27.10 27.50 70.10 10</span></a>
|
||||
<a class="sourceLine" id="cb6-10" title="10"><span class="co"># C 1.38 1.6 1.69 1.69 1.72 1.97 10</span></a></code></pre></div>
|
||||
<a class="sourceLine" id="cb6-7" title="7"><span class="co"># expr min lq mean median uq max neval</span></a>
|
||||
<a class="sourceLine" id="cb6-8" title="8"><span class="co"># A 12.9 13.20 13.30 13.40 13.50 13.50 10</span></a>
|
||||
<a class="sourceLine" id="cb6-9" title="9"><span class="co"># B 25.3 25.80 30.40 25.80 26.20 71.60 10</span></a>
|
||||
<a class="sourceLine" id="cb6-10" title="10"><span class="co"># C 1.3 1.37 1.56 1.67 1.73 1.74 10</span></a></code></pre></div>
|
||||
<p>So going from <code><a href="../reference/mo_property.html">mo_fullname("Staphylococcus aureus")</a></code> to <code>"Staphylococcus aureus"</code> takes 0.0017 seconds - it doesn’t 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="cb7"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb7-1" title="1">run_it <-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/microbenchmark/topics/microbenchmark">microbenchmark</a></span>(<span class="dt">A =</span> <span class="kw"><a href="../reference/mo_property.html">mo_species</a></span>(<span class="st">"aureus"</span>),</a>
|
||||
<a class="sourceLine" id="cb7-2" title="2"> <span class="dt">B =</span> <span class="kw"><a href="../reference/mo_property.html">mo_genus</a></span>(<span class="st">"Staphylococcus"</span>),</a>
|
||||
@ -317,14 +317,14 @@
|
||||
<a class="sourceLine" id="cb7-10" title="10"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(run_it, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">signif =</span> <span class="dv">3</span>)</a>
|
||||
<a class="sourceLine" id="cb7-11" title="11"><span class="co"># Unit: milliseconds</span></a>
|
||||
<a class="sourceLine" id="cb7-12" title="12"><span class="co"># expr min lq mean median uq max neval</span></a>
|
||||
<a class="sourceLine" id="cb7-13" title="13"><span class="co"># A 0.392 0.485 0.577 0.580 0.628 0.808 10</span></a>
|
||||
<a class="sourceLine" id="cb7-14" title="14"><span class="co"># B 0.444 0.521 0.566 0.567 0.609 0.710 10</span></a>
|
||||
<a class="sourceLine" id="cb7-15" title="15"><span class="co"># C 1.380 1.680 1.750 1.760 1.820 2.160 10</span></a>
|
||||
<a class="sourceLine" id="cb7-16" title="16"><span class="co"># D 0.422 0.522 0.564 0.553 0.640 0.644 10</span></a>
|
||||
<a class="sourceLine" id="cb7-17" title="17"><span class="co"># E 0.362 0.443 0.520 0.543 0.595 0.684 10</span></a>
|
||||
<a class="sourceLine" id="cb7-18" title="18"><span class="co"># F 0.347 0.432 0.515 0.495 0.585 0.728 10</span></a>
|
||||
<a class="sourceLine" id="cb7-19" title="19"><span class="co"># G 0.377 0.417 0.479 0.463 0.495 0.681 10</span></a>
|
||||
<a class="sourceLine" id="cb7-20" title="20"><span class="co"># H 0.263 0.264 0.310 0.282 0.350 0.436 10</span></a></code></pre></div>
|
||||
<a class="sourceLine" id="cb7-13" title="13"><span class="co"># A 0.442 0.477 0.583 0.572 0.673 0.806 10</span></a>
|
||||
<a class="sourceLine" id="cb7-14" title="14"><span class="co"># B 0.442 0.502 0.626 0.611 0.761 0.826 10</span></a>
|
||||
<a class="sourceLine" id="cb7-15" title="15"><span class="co"># C 1.360 1.620 1.820 1.810 2.060 2.150 10</span></a>
|
||||
<a class="sourceLine" id="cb7-16" title="16"><span class="co"># D 0.449 0.514 0.622 0.639 0.725 0.798 10</span></a>
|
||||
<a class="sourceLine" id="cb7-17" title="17"><span class="co"># E 0.401 0.440 0.530 0.508 0.568 0.799 10</span></a>
|
||||
<a class="sourceLine" id="cb7-18" title="18"><span class="co"># F 0.353 0.391 0.502 0.494 0.635 0.695 10</span></a>
|
||||
<a class="sourceLine" id="cb7-19" title="19"><span class="co"># G 0.451 0.559 0.595 0.609 0.646 0.747 10</span></a>
|
||||
<a class="sourceLine" id="cb7-20" title="20"><span class="co"># H 0.191 0.278 0.395 0.376 0.528 0.653 10</span></a></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> too, there is no point in calculating the result. And because this package ‘knows’ all phyla of all known bacteria (according to the Catalogue of Life), it can just return the initial value immediately.</p>
|
||||
</div>
|
||||
<div id="results-in-other-languages" class="section level3">
|
||||
@ -351,13 +351,13 @@
|
||||
<a class="sourceLine" id="cb8-18" title="18"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(run_it, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">signif =</span> <span class="dv">4</span>)</a>
|
||||
<a class="sourceLine" id="cb8-19" title="19"><span class="co"># Unit: milliseconds</span></a>
|
||||
<a class="sourceLine" id="cb8-20" title="20"><span class="co"># expr min lq mean median uq max neval</span></a>
|
||||
<a class="sourceLine" id="cb8-21" title="21"><span class="co"># en 18.15 18.27 22.87 18.31 18.68 63.44 10</span></a>
|
||||
<a class="sourceLine" id="cb8-22" title="22"><span class="co"># de 23.03 23.14 27.80 23.20 23.53 68.60 10</span></a>
|
||||
<a class="sourceLine" id="cb8-23" title="23"><span class="co"># nl 36.67 36.71 41.51 37.01 37.41 81.57 10</span></a>
|
||||
<a class="sourceLine" id="cb8-24" title="24"><span class="co"># es 23.07 23.11 23.25 23.21 23.26 23.63 10</span></a>
|
||||
<a class="sourceLine" id="cb8-25" title="25"><span class="co"># it 22.93 23.04 23.17 23.08 23.19 23.62 10</span></a>
|
||||
<a class="sourceLine" id="cb8-26" title="26"><span class="co"># fr 23.13 23.21 27.71 23.30 23.31 67.70 10</span></a>
|
||||
<a class="sourceLine" id="cb8-27" title="27"><span class="co"># pt 23.08 23.18 27.85 23.23 23.98 67.96 10</span></a></code></pre></div>
|
||||
<a class="sourceLine" id="cb8-21" title="21"><span class="co"># en 18.16 18.23 22.82 18.29 18.57 63.28 10</span></a>
|
||||
<a class="sourceLine" id="cb8-22" title="22"><span class="co"># de 23.00 23.09 23.35 23.21 23.59 23.96 10</span></a>
|
||||
<a class="sourceLine" id="cb8-23" title="23"><span class="co"># nl 36.60 36.74 37.00 36.97 37.32 37.41 10</span></a>
|
||||
<a class="sourceLine" id="cb8-24" title="24"><span class="co"># es 23.10 23.15 23.40 23.29 23.63 23.97 10</span></a>
|
||||
<a class="sourceLine" id="cb8-25" title="25"><span class="co"># it 23.04 23.14 23.28 23.27 23.43 23.58 10</span></a>
|
||||
<a class="sourceLine" id="cb8-26" title="26"><span class="co"># fr 23.13 23.21 33.12 23.90 28.96 68.96 10</span></a>
|
||||
<a class="sourceLine" id="cb8-27" title="27"><span class="co"># pt 22.98 23.16 23.37 23.44 23.51 23.65 10</span></a></code></pre></div>
|
||||
<p>Currently supported are German, Dutch, Spanish, Italian, French and Portuguese.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user