| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>pypdevsbbl.extra.mathutils module — Python(P)DEVS-BBL documentation</title>
- <link rel="stylesheet" href="_static/nature.css" type="text/css" />
- <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
- <link rel="stylesheet" type="text/css" href="_static/custom.css" />
- <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
- <script type="text/javascript" src="_static/jquery.js"></script>
- <script type="text/javascript" src="_static/underscore.js"></script>
- <script type="text/javascript" src="_static/doctools.js"></script>
- <script type="text/javascript" src="_static/language_data.js"></script>
- <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
- <link rel="index" title="Index" href="genindex.html" />
- <link rel="search" title="Search" href="search.html" />
- <link rel="next" title="pypdevsbbl.extra.packaging module" href="pypdevsbbl.extra.packaging.html" />
- <link rel="prev" title="pypdevsbbl.extra.heap module" href="pypdevsbbl.extra.heap.html" />
- </head><body>
- <div class="related" role="navigation" aria-label="related navigation">
- <h3>Navigation</h3>
- <ul>
- <li class="right" style="margin-right: 10px">
- <a href="genindex.html" title="General Index"
- accesskey="I">index</a></li>
- <li class="right" >
- <a href="py-modindex.html" title="Python Module Index"
- >modules</a> |</li>
- <li class="right" >
- <a href="pypdevsbbl.extra.packaging.html" title="pypdevsbbl.extra.packaging module"
- accesskey="N">next</a> |</li>
- <li class="right" >
- <a href="pypdevsbbl.extra.heap.html" title="pypdevsbbl.extra.heap module"
- accesskey="P">previous</a> |</li>
- <li class="nav-item nav-item-0"><a href="index.html">Python(P)DEVS-BBL documentation</a> »</li>
- <li class="nav-item nav-item-1"><a href="pypdevsbbl.html" >pypdevsbbl package</a> »</li>
- <li class="nav-item nav-item-2"><a href="pypdevsbbl.extra.html" accesskey="U">pypdevsbbl.extra package</a> »</li>
- </ul>
- </div>
- <div class="document">
- <div class="documentwrapper">
- <div class="bodywrapper">
- <div class="body" role="main">
-
- <div class="section" id="module-pypdevsbbl.extra.mathutils">
- <span id="pypdevsbbl-extra-mathutils-module"></span><h1>pypdevsbbl.extra.mathutils module<a class="headerlink" href="#module-pypdevsbbl.extra.mathutils" title="Permalink to this headline">¶</a></h1>
- <p>This file contains the main functionality for having more control over boxplots.</p>
- <p>These can be used for custom computation of boxplots, histograms and some other features,
- based upon certain algorithms. This way, it is possible to compute these values in
- situations where you don’t have access over the entire dataset, but only over a few values
- thereof.</p>
- <p>There are also some additional helper functions that can be useful in other circumstances
- as well.</p>
- <dl class="class">
- <dt id="pypdevsbbl.extra.mathutils.BoxplotAlgorithm">
- <em class="property">class </em><code class="descclassname">pypdevsbbl.extra.mathutils.</code><code class="descname">BoxplotAlgorithm</code><a class="reference internal" href="_modules/pypdevsbbl/extra/mathutils.html#BoxplotAlgorithm"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.mathutils.BoxplotAlgorithm" title="Permalink to this definition">¶</a></dt>
- <dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">enum.Enum</span></code></p>
- <p>Helper enum for creating boxplots of series of <span class="math notranslate nohighlight">\(N\)</span> items.</p>
- <p>Boxplots are created with 5 values: [<cite>min</cite>, <cite>Q1</cite>, <cite>median</cite>, <cite>Q3</cite>, <cite>max</cite>]</p>
- <p>Even though <cite>Q1</cite> and <cite>Q3</cite> are also defined as being medians, some software
- packages use other algorithms for computing these values. This enum allows
- a quick and clean access of a set of these other algorithms.</p>
- <div class="admonition seealso">
- <p class="first admonition-title">See also</p>
- <p class="last"><a class="reference internal" href="#pypdevsbbl.extra.mathutils.linear_interpolation" title="pypdevsbbl.extra.mathutils.linear_interpolation"><code class="xref py py-meth docutils literal notranslate"><span class="pre">linear_interpolation()</span></code></a></p>
- </div>
- <dl class="attribute">
- <dt id="pypdevsbbl.extra.mathutils.BoxplotAlgorithm.MEDIAN">
- <code class="descname">MEDIAN</code><em class="property"> = 0</em><a class="headerlink" href="#pypdevsbbl.extra.mathutils.BoxplotAlgorithm.MEDIAN" title="Permalink to this definition">¶</a></dt>
- <dd><p>Default computation where the <cite>Q1</cite> and <cite>Q3</cite> values are the medians of the
- lower list and the upper list of the set split on its global median, respectively.</p>
- <p>The global median is not included in the computation. When there is an even amount
- of items, the two values that make up the median are both excluded from the
- computation.</p>
- <p>Computes the element at indexes <cite>Q1</cite> and <cite>Q3</cite> and determines a linear interpolation
- on the series if the index is not an integer.</p>
- <p><span class="math notranslate nohighlight">\(Q1 = \begin{cases}\dfrac{N}{4}\textrm{ if }N\textrm{ is even}\\\\
- \dfrac{N + 1}{4}\textrm{ if }N\textrm{ is odd}\end{cases}\qquad
- Q3 = \begin{cases}\dfrac{3\cdot N + 4}{4}\textrm{ if }N\textrm{ is even}\\\\
- \dfrac{3\cdot N + 3}{4}\textrm{ if }N\textrm{ is odd}\end{cases}\)</span></p>
- </dd></dl>
- <dl class="attribute">
- <dt id="pypdevsbbl.extra.mathutils.BoxplotAlgorithm.TUKEY">
- <code class="descname">TUKEY</code><em class="property"> = 1</em><a class="headerlink" href="#pypdevsbbl.extra.mathutils.BoxplotAlgorithm.TUKEY" title="Permalink to this definition">¶</a></dt>
- <dd><p>Computation that’s used by <cite>R</cite> in the <code class="xref py py-meth docutils literal notranslate"><span class="pre">fivenum()</span></code> function and by
- <code class="xref py py-mod docutils literal notranslate"><span class="pre">matplotlib</span></code> for plotting boxplots.</p>
- <p>The computation is the same as <a class="reference internal" href="#pypdevsbbl.extra.mathutils.BoxplotAlgorithm.MEDIAN" title="pypdevsbbl.extra.mathutils.BoxplotAlgorithm.MEDIAN"><code class="xref py py-attr docutils literal notranslate"><span class="pre">MEDIAN</span></code></a>, except that the median is included
- in the computation.</p>
- <p>Computes the element at indexes <cite>Q1</cite> and <cite>Q3</cite> and determines a linear interpolation
- on the series if the index is not an integer.</p>
- <p><span class="math notranslate nohighlight">\(Q1 = \begin{cases}\dfrac{N + 2}{4}\textrm{ if }N\textrm{ is even}\\\\
- \dfrac{N + 3}{4}\textrm{ if }N\textrm{ is odd}\end{cases}\qquad
- Q3 = \begin{cases}\dfrac{3\cdot N + 2}{4}\textrm{ if }N\textrm{ is even}\\\\
- \dfrac{3\cdot N + 1}{4}\textrm{ if }N\textrm{ is odd}\end{cases}\)</span></p>
- </dd></dl>
- <dl class="attribute">
- <dt id="pypdevsbbl.extra.mathutils.BoxplotAlgorithm.MINITAB">
- <code class="descname">MINITAB</code><em class="property"> = 2</em><a class="headerlink" href="#pypdevsbbl.extra.mathutils.BoxplotAlgorithm.MINITAB" title="Permalink to this definition">¶</a></dt>
- <dd><p>Computation that’s used by <cite>Minitab</cite> and by <cite>MS Excel</cite> (in any version later
- than 2007, in the <code class="xref py py-meth docutils literal notranslate"><span class="pre">QUARTILE.EXC()</span></code> function).</p>
- <p>Computes the element at indexes <cite>Q1</cite> and <cite>Q3</cite> and determines a linear interpolation
- on the series if the index is not an integer.</p>
- <p><span class="math notranslate nohighlight">\(Q1 = \dfrac{N + 1}{4}\qquad Q3 = \dfrac{3\cdot N + 3}{4}\)</span></p>
- </dd></dl>
- <dl class="attribute">
- <dt id="pypdevsbbl.extra.mathutils.BoxplotAlgorithm.FREUND_PERLES">
- <code class="descname">FREUND_PERLES</code><em class="property"> = 3</em><a class="headerlink" href="#pypdevsbbl.extra.mathutils.BoxplotAlgorithm.FREUND_PERLES" title="Permalink to this definition">¶</a></dt>
- <dd><p>Computation that’s used by <cite>MS Excel</cite> (version 2007 and earlier use <code class="xref py py-meth docutils literal notranslate"><span class="pre">QUARTILE()</span></code>,
- which was replaced in later versions by <code class="xref py py-meth docutils literal notranslate"><span class="pre">QUARTILE.INC()</span></code>), by <cite>R</cite> in the <code class="xref py py-meth docutils literal notranslate"><span class="pre">summary()</span></code>
- function and by <code class="xref py py-meth docutils literal notranslate"><span class="pre">numpy.percentile()</span></code> (with a linear interpolation).</p>
- <p>Computes the element at indexes <cite>Q1</cite> and <cite>Q3</cite> and determines a linear interpolation
- on the series if the index is not an integer.</p>
- <p><span class="math notranslate nohighlight">\(Q1 = \dfrac{N + 3}{4}\qquad Q3 = \dfrac{3\cdot N + 1}{4}\)</span></p>
- </dd></dl>
- <dl class="attribute">
- <dt id="pypdevsbbl.extra.mathutils.BoxplotAlgorithm.MOORE_MCCABE">
- <code class="descname">MOORE_MCCABE</code><em class="property"> = 4</em><a class="headerlink" href="#pypdevsbbl.extra.mathutils.BoxplotAlgorithm.MOORE_MCCABE" title="Permalink to this definition">¶</a></dt>
- <dd><p>Similar to <a class="reference internal" href="#pypdevsbbl.extra.mathutils.BoxplotAlgorithm.MEDIAN" title="pypdevsbbl.extra.mathutils.BoxplotAlgorithm.MEDIAN"><code class="xref py py-attr docutils literal notranslate"><span class="pre">MEDIAN</span></code></a>, as is it used in the <cite>TI-83</cite> calculators for boxplots.</p>
- <p>Computes the element at indexes <cite>Q1</cite> and <cite>Q3</cite> and determines a linear interpolation
- on the series if the index is not an integer.</p>
- <p><span class="math notranslate nohighlight">\(Q1 = \begin{cases}\dfrac{N + 2}{4}\textrm{ if }N\textrm{ is even}\\\\
- \dfrac{N + 1}{4}\textrm{ if }N\textrm{ is odd}\end{cases}\qquad
- Q3 = \begin{cases}\dfrac{3\cdot N + 2}{4}\textrm{ if }N\textrm{ is even}\\\\
- \dfrac{3\cdot N + 3}{4}\textrm{ if }N\textrm{ is odd}\end{cases}\)</span></p>
- </dd></dl>
- <dl class="attribute">
- <dt id="pypdevsbbl.extra.mathutils.BoxplotAlgorithm.MENDENHALL_SINCICH">
- <code class="descname">MENDENHALL_SINCICH</code><em class="property"> = 5</em><a class="headerlink" href="#pypdevsbbl.extra.mathutils.BoxplotAlgorithm.MENDENHALL_SINCICH" title="Permalink to this definition">¶</a></dt>
- <dd><p>Same as <a class="reference internal" href="#pypdevsbbl.extra.mathutils.BoxplotAlgorithm.MINITAB" title="pypdevsbbl.extra.mathutils.BoxplotAlgorithm.MINITAB"><code class="xref py py-attr docutils literal notranslate"><span class="pre">MINITAB</span></code></a>, except this method uses rounding for its computations.</p>
- <p>Computes the element at indexes <cite>Q1</cite> and <cite>Q3</cite> and determines a linear interpolation
- on the series if the index is not an integer.</p>
- <p><span class="math notranslate nohighlight">\(Q1 = \left\lfloor\dfrac{N + 1}{4}\right\rfloor\qquad
- Q3 = \left\lceil\dfrac{3\cdot N + 3}{4}\right\rceil\)</span></p>
- </dd></dl>
- <dl class="attribute">
- <dt id="pypdevsbbl.extra.mathutils.BoxplotAlgorithm.FAME">
- <code class="descname">FAME</code><em class="property"> = 6</em><a class="headerlink" href="#pypdevsbbl.extra.mathutils.BoxplotAlgorithm.FAME" title="Permalink to this definition">¶</a></dt>
- <dd><p>Computes the <cite>Q1</cite> and <cite>Q3</cite> values via the <em>Fast Algorithm for Median Estimation</em>.</p>
- <div class="admonition seealso">
- <p class="first admonition-title">See also</p>
- <p class="last"><a class="reference internal" href="#pypdevsbbl.extra.mathutils.FAME" title="pypdevsbbl.extra.mathutils.FAME"><code class="xref py py-meth docutils literal notranslate"><span class="pre">FAME()</span></code></a></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="pypdevsbbl.extra.mathutils.BoxplotAlgorithm.P_SQUARE">
- <code class="descname">P_SQUARE</code><em class="property"> = 7</em><a class="headerlink" href="#pypdevsbbl.extra.mathutils.BoxplotAlgorithm.P_SQUARE" title="Permalink to this definition">¶</a></dt>
- <dd><p>Computes the <cite>Q1</cite> and <cite>Q3</cite> values via the <em>P^2 Algorithm for Dynamic Calculation of Quantiles
- and Histograms without Scoring Observations</em>.</p>
- <div class="admonition seealso">
- <p class="first admonition-title">See also</p>
- <ul class="last simple">
- <li><a class="reference internal" href="#pypdevsbbl.extra.mathutils.histogram" title="pypdevsbbl.extra.mathutils.histogram"><code class="xref py py-meth docutils literal notranslate"><span class="pre">histogram()</span></code></a></li>
- <li><a class="reference internal" href="#pypdevsbbl.extra.mathutils.histostep" title="pypdevsbbl.extra.mathutils.histostep"><code class="xref py py-meth docutils literal notranslate"><span class="pre">histostep()</span></code></a></li>
- <li><a class="reference internal" href="#pypdevsbbl.extra.mathutils.PPP" title="pypdevsbbl.extra.mathutils.PPP"><code class="xref py py-meth docutils literal notranslate"><span class="pre">PPP()</span></code></a></li>
- </ul>
- </div>
- </dd></dl>
- </dd></dl>
- <dl class="function">
- <dt id="pypdevsbbl.extra.mathutils.compute_boxplot">
- <code class="descclassname">pypdevsbbl.extra.mathutils.</code><code class="descname">compute_boxplot</code><span class="sig-paren">(</span><em>series: list</em>, <em>algorithm: pypdevsbbl.extra.mathutils.BoxplotAlgorithm = <BoxplotAlgorithm.MEDIAN: 0></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/mathutils.html#compute_boxplot"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.mathutils.compute_boxplot" title="Permalink to this definition">¶</a></dt>
- <dd><p>Compute the boxplot values for a series.</p>
- <p>This function computes the [<cite>min</cite>, <cite>Q1</cite>, <cite>median</cite>, <cite>Q3</cite>, <cite>max</cite>] set of a series,
- based upon a certain algorithm.</p>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">The median in the result is the definition-wise median and not computed with some
- other algorithm.</p>
- </div>
- <div class="admonition seealso">
- <p class="first admonition-title">See also</p>
- <p class="last"><a class="reference internal" href="#pypdevsbbl.extra.mathutils.linear_interpolation" title="pypdevsbbl.extra.mathutils.linear_interpolation"><code class="xref py py-meth docutils literal notranslate"><span class="pre">linear_interpolation()</span></code></a></p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>series</strong> (<em>list</em>) – A list of numeric vales from which a boxplot
- must be computed.</li>
- <li><strong>algorithm</strong> (<a class="reference internal" href="#pypdevsbbl.extra.mathutils.BoxplotAlgorithm" title="pypdevsbbl.extra.mathutils.BoxplotAlgorithm"><em>BoxplotAlgorithm</em></a>) – The algorithm to use for computing the data.
- Even though the <cite>Q1</cite> and <cite>Q3</cite> values are technically defined as
- medians, some software actually use other computations for these
- values. Defaults to <a class="reference internal" href="#pypdevsbbl.extra.mathutils.BoxplotAlgorithm.MEDIAN" title="pypdevsbbl.extra.mathutils.BoxplotAlgorithm.MEDIAN"><code class="xref py py-attr docutils literal notranslate"><span class="pre">BoxplotAlgorithm.MEDIAN</span></code></a>.</li>
- </ul>
- </td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A dictionary with keys [min, Q1, median, Q3, max] and their corresponding values.</p>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="pypdevsbbl.extra.mathutils.FAME">
- <code class="descclassname">pypdevsbbl.extra.mathutils.</code><code class="descname">FAME</code><span class="sig-paren">(</span><em>series: list</em>, <em>b=0.1</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/mathutils.html#FAME"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.mathutils.FAME" title="Permalink to this definition">¶</a></dt>
- <dd><p>Do the <cite>FAME</cite> algorithm based upon a series.</p>
- <p>Loops throughout the entire series and tries to estimate the median.
- Please note that this is a mere estimate and not at all the actual
- median!</p>
- <p><cite>FAME</cite> (Fast Algorithm for Median Estimation) is described in
- <em>An Optimal Median Calculation Algorithm for Estimating Internet Link
- Delays From Active Measurements</em> by <cite>Dima Feldman</cite> and <cite>Yuval Shavitt</cite>
- at the university of Tel-Aviv, 2007.</p>
- <div class="admonition seealso">
- <p class="first admonition-title">See also</p>
- <ul class="last simple">
- <li><a class="reference external" href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.108.7376&rep=rep1&type=pdf">http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.108.7376&rep=rep1&type=pdf</a> (paper)</li>
- <li><a class="reference external" href="http://www.eng.tau.ac.il/~shavitt/courses/LargeG/streaming-median.pdf">http://www.eng.tau.ac.il/~shavitt/courses/LargeG/streaming-median.pdf</a></li>
- </ul>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>series</strong> (<em>list</em>) – The series to loop through.</li>
- <li><strong>b</strong> (<em>numeric</em>) – Minimal initial step size. Defaults to 0.1.</li>
- </ul>
- </td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">The estimated median of the series.</p>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="pypdevsbbl.extra.mathutils.histogram">
- <code class="descclassname">pypdevsbbl.extra.mathutils.</code><code class="descname">histogram</code><span class="sig-paren">(</span><em>series: list</em>, <em>b: int</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/mathutils.html#histogram"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.mathutils.histogram" title="Permalink to this definition">¶</a></dt>
- <dd><p>Computes a b-cell histogram estimate of the series.</p>
- <p>Loops throughout the series and plots an estimate for
- a b+1 point histogram, using b equiprobable cells.
- When there are less then b observations, the series
- itself becomes the histogram.</p>
- <p>The source for this algorithm is based upon the
- <em>P^2 Algorithm for Dynamic Calculation of Quantiles
- and Histograms without Scoring Observations</em> by <cite>Raj
- Jain</cite> and <cite>Imrich Chlamtac</cite> at the Washington University
- in Saint Louis, 1985.</p>
- <div class="admonition seealso">
- <p class="first admonition-title">See also</p>
- <ul class="last simple">
- <li><a class="reference external" href="https://www.cse.wustl.edu/~jain/papers/ftp/psqr.pdf">https://www.cse.wustl.edu/~jain/papers/ftp/psqr.pdf</a> (paper)</li>
- <li><a class="reference internal" href="#pypdevsbbl.extra.mathutils.histostep" title="pypdevsbbl.extra.mathutils.histostep"><code class="xref py py-meth docutils literal notranslate"><span class="pre">histostep()</span></code></a></li>
- <li><a class="reference internal" href="#pypdevsbbl.extra.mathutils.PPP" title="pypdevsbbl.extra.mathutils.PPP"><code class="xref py py-meth docutils literal notranslate"><span class="pre">PPP()</span></code></a></li>
- </ul>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>series</strong> (<em>list</em>) – The series of which to compute the
- histogram.</li>
- <li><strong>b</strong> (<em>int</em>) – The amount of cells to compute.
- Note that b+1 will identify the amount
- of ‘bars’ in the histogram.</li>
- </ul>
- </td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">An (x, y) tuple where x contains the x-locations of all
- values on the x-axis of the histogram and y contains all
- heights of all bars. Both x and y are lists of numbers of
- size b+1.</p>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="pypdevsbbl.extra.mathutils.histostep">
- <code class="descclassname">pypdevsbbl.extra.mathutils.</code><code class="descname">histostep</code><span class="sig-paren">(</span><em>xj</em>, <em>b: int</em>, <em>q: list</em>, <em>n: list</em>, <em>N: int</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/mathutils.html#histostep"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.mathutils.histostep" title="Permalink to this definition">¶</a></dt>
- <dd><p>Helper function for the histogram function.</p>
- <p>This function was extracted to make it easier for the algorithm
- to be used without knowledge of the entire series.</p>
- <div class="admonition seealso">
- <p class="first admonition-title">See also</p>
- <ul class="last simple">
- <li><a class="reference internal" href="#pypdevsbbl.extra.mathutils.histogram" title="pypdevsbbl.extra.mathutils.histogram"><code class="xref py py-meth docutils literal notranslate"><span class="pre">histogram()</span></code></a></li>
- <li><a class="reference internal" href="#pypdevsbbl.extra.mathutils.PPP" title="pypdevsbbl.extra.mathutils.PPP"><code class="xref py py-meth docutils literal notranslate"><span class="pre">PPP()</span></code></a></li>
- </ul>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>xj</strong> (<em>numeric</em>) – The new item in the series.</li>
- <li><strong>b</strong> (<em>int</em>) – The amount of cells to compute.</li>
- <li><strong>q</strong> (<em>list</em>) – The datavalues of the bars in the histogram.</li>
- <li><strong>n</strong> (<em>list</em>) – The positions of the bars in the histogram.</li>
- <li><strong>N</strong> (<em>int</em>) – The current observation index.</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="pypdevsbbl.extra.mathutils.PPP">
- <code class="descclassname">pypdevsbbl.extra.mathutils.</code><code class="descname">PPP</code><span class="sig-paren">(</span><em>q: list</em>, <em>n: list</em>, <em>i: int</em>, <em>d=1</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/mathutils.html#PPP"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.mathutils.PPP" title="Permalink to this definition">¶</a></dt>
- <dd><p>Do a Piecewise-Parabolic Prediction.</p>
- <p>Assume we have a parabola passing through
- (n[i-1], q[i-1]), (n[i], q[i]) and (n[i+1], q[i+1])
- which is of the form</p>
- <div class="math notranslate nohighlight">
- \[y = ax^2 + bx + c\]</div>
- <p>where (x, y) are coordinates in these points.
- The interpolated value (prediction) at location i can
- be determined via solving the equations set above.</p>
- <p>Based upon the PP-algorithm from
- <a class="reference external" href="https://www.cse.wustl.edu/~jain/papers/ftp/psqr.pdf">https://www.cse.wustl.edu/~jain/papers/ftp/psqr.pdf</a></p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>q</strong> (<em>list</em>) – The heights of the points.</li>
- <li><strong>n</strong> (<em>list</em>) – The location of the points.</li>
- <li><strong>i</strong> (<em>int</em>) – The index where we will look.</li>
- <li><strong>d</strong> (<em>int</em>) – Either -1 (left) or 1 (right)</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="pypdevsbbl.extra.mathutils.linear_interpolation">
- <code class="descclassname">pypdevsbbl.extra.mathutils.</code><code class="descname">linear_interpolation</code><span class="sig-paren">(</span><em>x</em>, <em>data: list</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/mathutils.html#linear_interpolation"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.mathutils.linear_interpolation" title="Permalink to this definition">¶</a></dt>
- <dd><p>Compute the linear interpolation.</p>
- <p>Using the data, it will compute the value that should appear at index idx.
- This function will do a linear interpolation between the datapoints
- i-1 and i around x. (Whereas i-1=floor(x) and i=ceil(x).)
- We assume the line through these points follows the equation</p>
- <div class="math notranslate nohighlight">
- \[\begin{split}y &= mx + q \\
- y - y1 &= (y2 - y1) / (x2 - x1) * (x - x1)\end{split}\]</div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>x</strong> (<em>numeric</em>) – The location to do the interpolation at. (the x-value)</li>
- <li><strong>data</strong> (<em>list</em>) – The list of y-values at integer values.</li>
- </ul>
- </td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">The value that corresponds with the idx in the list.</p>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="pypdevsbbl.extra.mathutils.sign">
- <code class="descclassname">pypdevsbbl.extra.mathutils.</code><code class="descname">sign</code><span class="sig-paren">(</span><em>num</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/mathutils.html#sign"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.mathutils.sign" title="Permalink to this definition">¶</a></dt>
- <dd><p>Apply the sign function.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>num</strong> (<em>numeric</em>) – The value of which the sign needs to be determined.</td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><span class="math notranslate nohighlight">\(\begin{cases}\begin{align}&1&\textrm{if num > 0}\\&-1&\textrm{if num < 0}\\&0&\textrm{otherwise }\end{align}\end{cases}\)</span></td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="pypdevsbbl.extra.mathutils.binomial">
- <code class="descclassname">pypdevsbbl.extra.mathutils.</code><code class="descname">binomial</code><span class="sig-paren">(</span><em>n</em>, <em>k</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/mathutils.html#binomial"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.mathutils.binomial" title="Permalink to this definition">¶</a></dt>
- <dd><p>The binomial computation.</p>
- <p>The amount of possible ways to choose k out of n.
- This is the computation of the binomial coefficient C(n, k).
- Instead of the basic formula of <code class="docutils literal notranslate"><span class="pre">n!</span> <span class="pre">/</span> <span class="pre">(k!</span> <span class="pre">*</span> <span class="pre">(n</span> <span class="pre">-</span> <span class="pre">k)!)</span></code>
- where ‘x!’ stands for ‘x factorial’, this method will try and
- compute a space-efficient binomial (i.e. O(1)).</p>
- <p>It is based on the explanation on:
- <a class="reference external" href="https://www.geeksforgeeks.org/space-and-time-efficient-binomial-coefficient/">https://www.geeksforgeeks.org/space-and-time-efficient-binomial-coefficient/</a></p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>n</strong> (<em>numeric</em>) – The total number (top number).</li>
- <li><strong>k</strong> (<em>numeric</em>) – The amount to choose (bottom number).</li>
- </ul>
- </td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">The binomial of (n k).</p>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="pypdevsbbl.extra.mathutils.binprob">
- <code class="descclassname">pypdevsbbl.extra.mathutils.</code><code class="descname">binprob</code><span class="sig-paren">(</span><em>t</em>, <em>n</em>, <em>p</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/mathutils.html#binprob"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.mathutils.binprob" title="Permalink to this definition">¶</a></dt>
- <dd><p>Compute the probability w.r.t. a binomial distribution.</p>
- <p>Assume X follows a discrete binomial distribution with size n
- and probability p: X ~ Bin(n, p)</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>t</strong> (<em>numeric</em>) – The value to compute.</li>
- <li><strong>n</strong> (<em>numeric</em>) – The size of the distribution.</li>
- <li><strong>p</strong> (<em>float</em>) – The probability of the distribution.</li>
- </ul>
- </td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Pr[X <= t]</p>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">The probability that X is less then t</p>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="pypdevsbbl.extra.mathutils.draw_boxplot">
- <code class="descclassname">pypdevsbbl.extra.mathutils.</code><code class="descname">draw_boxplot</code><span class="sig-paren">(</span><em>minimum</em>, <em>Q1</em>, <em>median</em>, <em>Q3</em>, <em>maximum</em>, <em>outliers=False</em>, <em>labels=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/mathutils.html#draw_boxplot"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.mathutils.draw_boxplot" title="Permalink to this definition">¶</a></dt>
- <dd><p>Get a boxplot-data object in matplotlib, based on its values.</p>
- <p>Using this function, it is possible to quickly draw a boxplot, based on
- its internal values. By default, matplotlib uses either bootstrapping or
- Gaussian-based asymptotic approximation (Tukey).</p>
- <p>This function therefore allows drawing boxplots based on other algorithms,
- but it does NOT draw the boxplots themselves. It yields a mere object, which
- can be used in the Axes.bpx method of matplotlib.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>minimum</strong> (<em>numeric</em>) – The smallest number to be drawn on the boxplot.</li>
- <li><strong>Q1</strong> (<em>numeric</em>) – The lower quartile edge of the box.</li>
- <li><strong>median</strong> (<em>numeric</em>) – The median position indicator in the box.</li>
- <li><strong>Q3</strong> (<em>numeric</em>) – The upper quartile edge of the box.</li>
- <li><strong>maximum</strong> (<em>numeric</em>) – The largest number to be drawn on the boxplot.</li>
- <li><strong>outliers</strong> (<em>bool</em>) – When true, this will make sure the whiskers are at most
- 1.5 * IQR away from the box. If the <cite>minimum</cite> and the
- <cite>maximum</cite> are outside of this range, they will be
- indicated as outliers.
- Do note that, as was the case with the compute_boxplot
- function, this method is a mere approximation of the
- boxplot, which becomes clear when comparing it to the
- actual boxplot. Theoretically, it’s a good approximation
- nonetheless.
- Defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code>.</li>
- <li><strong>labels</strong> (<em>iterable</em>) – Labels for each dataset.
- See also cbook.boxplot_stats.labels</li>
- </ul>
- </td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><p>A dictionary containing the results for each column of data.
- This is basically a transformed dictionary, based on:</p>
- <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">cbook</span><span class="o">.</span><span class="n">boxplot_stats</span><span class="p">([</span><span class="n">minimum</span><span class="p">,</span> <span class="n">Q1</span><span class="p">,</span> <span class="n">median</span><span class="p">,</span> <span class="n">Q3</span><span class="p">,</span> <span class="n">maximum</span><span class="p">],</span> <span class="n">labels</span><span class="o">=</span><span class="n">labels</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
- </pre></div>
- </div>
- </p>
- </td>
- </tr>
- </tbody>
- </table>
- <p class="rubric">Example</p>
- <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
- <span class="go">>>></span>
- <span class="gp">>>> </span><span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">()</span>
- <span class="gp">>>> </span><span class="n">boxplot</span> <span class="o">=</span> <span class="n">draw_boxplot</span><span class="p">(</span><span class="n">minimum</span><span class="p">,</span> <span class="n">Q1</span><span class="p">,</span> <span class="n">median</span><span class="p">,</span> <span class="n">Q3</span><span class="p">,</span> <span class="n">maximum</span><span class="p">)</span>
- <span class="gp">>>> </span><span class="n">ax</span><span class="o">.</span><span class="n">bpx</span><span class="p">(</span><span class="n">boxplot</span><span class="p">)</span> <span class="c1"># draws the actual boxplot</span>
- <span class="gp">>>> </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
- </pre></div>
- </div>
- </dd></dl>
- <dl class="function">
- <dt id="pypdevsbbl.extra.mathutils.mean">
- <code class="descclassname">pypdevsbbl.extra.mathutils.</code><code class="descname">mean</code><span class="sig-paren">(</span><em>seq</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/mathutils.html#mean"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.mathutils.mean" title="Permalink to this definition">¶</a></dt>
- <dd><p>Computes the mean of a sequence.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>seq</strong> (<em>iterable</em>) – The sequence to compute the mean for.</td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The mean of the sequence.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="pypdevsbbl.extra.mathutils.var">
- <code class="descclassname">pypdevsbbl.extra.mathutils.</code><code class="descname">var</code><span class="sig-paren">(</span><em>seq</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/mathutils.html#var"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.mathutils.var" title="Permalink to this definition">¶</a></dt>
- <dd><p>Computes the variance of a sequence.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>seq</strong> (<em>iterable</em>) – The sequence to compute the variance for.</td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The variance of the sequence.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="pypdevsbbl.extra.mathutils.std">
- <code class="descclassname">pypdevsbbl.extra.mathutils.</code><code class="descname">std</code><span class="sig-paren">(</span><em>seq</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/mathutils.html#std"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.mathutils.std" title="Permalink to this definition">¶</a></dt>
- <dd><p>Computes the standard derivation of a sequence.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>seq</strong> (<em>iterable</em>) – The sequence to compute the standard
- derivation for.</td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The standard derivation of the sequence.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="pypdevsbbl.extra.mathutils.harmonic">
- <code class="descclassname">pypdevsbbl.extra.mathutils.</code><code class="descname">harmonic</code><span class="sig-paren">(</span><em>n: int</em>, <em>m=1</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/mathutils.html#harmonic"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.mathutils.harmonic" title="Permalink to this definition">¶</a></dt>
- <dd><p>Computes the n-th generalized harmonic number.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>n</strong> (<em>int</em>) – The number to obtain.</li>
- <li><strong>m</strong> (<em>numeric</em>) – The power of each denominator.
- Defaults to 1, which also allows non-generalized numbers.</li>
- </ul>
- </td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">The n-th generalized harmonic number.</p>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="pypdevsbbl.extra.mathutils.harmonicinv">
- <code class="descclassname">pypdevsbbl.extra.mathutils.</code><code class="descname">harmonicinv</code><span class="sig-paren">(</span><em>y</em>, <em>m=1</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/mathutils.html#harmonicinv"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.mathutils.harmonicinv" title="Permalink to this definition">¶</a></dt>
- <dd><p>Compute the inverse general harmonic number.</p>
- <p>I.e. <span class="math notranslate nohighlight">\(GH(n, m) = y \iff IH(y, m) = n\)</span></p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>y</strong> (<em>numeric</em>) – The general harmonic number.</li>
- <li><strong>m</strong> (<em>numeric</em>) – The power to compute.
- Defaults to 1.</li>
- </ul>
- </td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">The inverse general harmonic number.</p>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- </div>
- </div>
- </div>
- </div>
- <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
- <div class="sphinxsidebarwrapper">
- <h4>Previous topic</h4>
- <p class="topless"><a href="pypdevsbbl.extra.heap.html"
- title="previous chapter">pypdevsbbl.extra.heap module</a></p>
- <h4>Next topic</h4>
- <p class="topless"><a href="pypdevsbbl.extra.packaging.html"
- title="next chapter">pypdevsbbl.extra.packaging module</a></p>
- <div id="searchbox" style="display: none" role="search">
- <h3>Quick search</h3>
- <div class="searchformwrapper">
- <form class="search" action="search.html" method="get">
- <input type="text" name="q" />
- <input type="submit" value="Go" />
- <input type="hidden" name="check_keywords" value="yes" />
- <input type="hidden" name="area" value="default" />
- </form>
- </div>
- </div>
- <script type="text/javascript">$('#searchbox').show(0);</script>
- </div>
- </div>
- <div class="clearer"></div>
- </div>
- <div class="related" role="navigation" aria-label="related navigation">
- <h3>Navigation</h3>
- <ul>
- <li class="right" style="margin-right: 10px">
- <a href="genindex.html" title="General Index"
- >index</a></li>
- <li class="right" >
- <a href="py-modindex.html" title="Python Module Index"
- >modules</a> |</li>
- <li class="right" >
- <a href="pypdevsbbl.extra.packaging.html" title="pypdevsbbl.extra.packaging module"
- >next</a> |</li>
- <li class="right" >
- <a href="pypdevsbbl.extra.heap.html" title="pypdevsbbl.extra.heap module"
- >previous</a> |</li>
- <li class="nav-item nav-item-0"><a href="index.html">Python(P)DEVS-BBL documentation</a> »</li>
- <li class="nav-item nav-item-1"><a href="pypdevsbbl.html" >pypdevsbbl package</a> »</li>
- <li class="nav-item nav-item-2"><a href="pypdevsbbl.extra.html" >pypdevsbbl.extra package</a> »</li>
- </ul>
- </div>
- <div class="footer" role="contentinfo">
- © Copyright 2020, Randy Paredis.
- Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.8.5.
- </div>
- </body>
- </html>
|