<!doctype html>

<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>pyFTS.benchmarks.benchmarks &#8212; pyFTS 1.2.3 documentation</title>
    <link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" 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="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <script type="text/javascript" src="../../../_static/bizstyle.js"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <!--[if lt IE 9]>
    <script type="text/javascript" src="_static/css3-mediaqueries.js"></script>
    <![endif]-->
  </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="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.2.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../../index.html">
              <img class="logo" src="../../../_static/logo_heading2.png" alt="Logo"/>
            </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="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <h1>Source code for pyFTS.benchmarks.benchmarks</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/python</span>
<span class="c1"># -*- coding: utf8 -*-</span>

<span class="sd">&quot;&quot;&quot;Benchmarks methods for FTS methods&quot;&quot;&quot;</span>


<span class="kn">import</span> <span class="nn">datetime</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">from</span> <span class="nn">copy</span> <span class="k">import</span> <span class="n">deepcopy</span>
<span class="kn">import</span> <span class="nn">traceback</span>

<span class="kn">import</span> <span class="nn">matplotlib</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="kn">import</span> <span class="nn">matplotlib.cm</span> <span class="k">as</span> <span class="nn">cmx</span>
<span class="kn">import</span> <span class="nn">matplotlib.colors</span> <span class="k">as</span> <span class="nn">pltcolors</span>
<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">mpl_toolkits.mplot3d</span> <span class="k">import</span> <span class="n">Axes3D</span>

<span class="kn">from</span> <span class="nn">pyFTS.probabilistic</span> <span class="k">import</span> <span class="n">ProbabilityDistribution</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="k">import</span> <span class="n">Transformations</span>
<span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="k">import</span> <span class="n">song</span><span class="p">,</span> <span class="n">chen</span><span class="p">,</span> <span class="n">yu</span><span class="p">,</span> <span class="n">ismailefendi</span><span class="p">,</span> <span class="n">sadaei</span><span class="p">,</span> <span class="n">hofts</span><span class="p">,</span> <span class="n">pwfts</span><span class="p">,</span> <span class="n">ifts</span><span class="p">,</span> <span class="n">cheng</span><span class="p">,</span> <span class="n">hwang</span>
<span class="kn">from</span> <span class="nn">pyFTS.models.ensemble</span> <span class="k">import</span> <span class="n">ensemble</span>
<span class="kn">from</span> <span class="nn">pyFTS.benchmarks</span> <span class="k">import</span> <span class="n">Measures</span><span class="p">,</span> <span class="n">naive</span><span class="p">,</span> <span class="n">arima</span><span class="p">,</span> <span class="n">ResidualAnalysis</span><span class="p">,</span> <span class="n">quantreg</span><span class="p">,</span> <span class="n">knn</span>
<span class="kn">from</span> <span class="nn">pyFTS.benchmarks</span> <span class="k">import</span> <span class="n">Util</span> <span class="k">as</span> <span class="n">bUtil</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="k">import</span> <span class="n">Util</span> <span class="k">as</span> <span class="n">cUtil</span>
<span class="c1"># from sklearn.cross_validation import KFold</span>
<span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="k">import</span> <span class="n">Grid</span>
<span class="kn">from</span> <span class="nn">matplotlib</span> <span class="k">import</span> <span class="n">rc</span>

<span class="c1">#rc(&#39;font&#39;,**{&#39;family&#39;:&#39;sans-serif&#39;,&#39;sans-serif&#39;:[&#39;Helvetica&#39;]})</span>
<span class="c1">## for Palatino and other serif fonts use:</span>
<span class="c1">#rc(&#39;font&#39;,**{&#39;family&#39;:&#39;serif&#39;,&#39;serif&#39;:[&#39;Palatino&#39;]})</span>
<span class="c1">#rc(&#39;text&#39;, usetex=True)</span>

<span class="n">colors</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;grey&#39;</span><span class="p">,</span> <span class="s1">&#39;darkgrey&#39;</span><span class="p">,</span> <span class="s1">&#39;rosybrown&#39;</span><span class="p">,</span> <span class="s1">&#39;maroon&#39;</span><span class="p">,</span> <span class="s1">&#39;red&#39;</span><span class="p">,</span><span class="s1">&#39;orange&#39;</span><span class="p">,</span> <span class="s1">&#39;gold&#39;</span><span class="p">,</span> <span class="s1">&#39;yellow&#39;</span><span class="p">,</span> <span class="s1">&#39;olive&#39;</span><span class="p">,</span> <span class="s1">&#39;green&#39;</span><span class="p">,</span>
          <span class="s1">&#39;darkgreen&#39;</span><span class="p">,</span> <span class="s1">&#39;cyan&#39;</span><span class="p">,</span> <span class="s1">&#39;lightblue&#39;</span><span class="p">,</span><span class="s1">&#39;blue&#39;</span><span class="p">,</span> <span class="s1">&#39;darkblue&#39;</span><span class="p">,</span> <span class="s1">&#39;purple&#39;</span><span class="p">,</span> <span class="s1">&#39;darkviolet&#39;</span> <span class="p">]</span>

<span class="n">ncol</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">colors</span><span class="p">)</span>

<span class="n">styles</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;-&#39;</span><span class="p">,</span><span class="s1">&#39;--&#39;</span><span class="p">,</span><span class="s1">&#39;-.&#39;</span><span class="p">,</span><span class="s1">&#39;:&#39;</span><span class="p">,</span><span class="s1">&#39;.&#39;</span><span class="p">]</span>

<span class="n">nsty</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">styles</span><span class="p">)</span>


<span class="k">def</span> <span class="nf">__pop</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">default</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">):</span>
    <span class="k">if</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">default</span>


<div class="viewcode-block" id="get_benchmark_point_methods"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.get_benchmark_point_methods">[docs]</a><span class="k">def</span> <span class="nf">get_benchmark_point_methods</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;Return all non FTS methods for point forecasting&quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="p">[</span><span class="n">naive</span><span class="o">.</span><span class="n">Naive</span><span class="p">,</span> <span class="n">arima</span><span class="o">.</span><span class="n">ARIMA</span><span class="p">,</span> <span class="n">quantreg</span><span class="o">.</span><span class="n">QuantileRegression</span><span class="p">]</span></div>


<div class="viewcode-block" id="get_point_methods"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.get_point_methods">[docs]</a><span class="k">def</span> <span class="nf">get_point_methods</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;Return all FTS methods for point forecasting&quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="p">[</span><span class="n">song</span><span class="o">.</span><span class="n">ConventionalFTS</span><span class="p">,</span> <span class="n">chen</span><span class="o">.</span><span class="n">ConventionalFTS</span><span class="p">,</span> <span class="n">yu</span><span class="o">.</span><span class="n">WeightedFTS</span><span class="p">,</span> <span class="n">ismailefendi</span><span class="o">.</span><span class="n">ImprovedWeightedFTS</span><span class="p">,</span>
            <span class="n">cheng</span><span class="o">.</span><span class="n">TrendWeightedFTS</span><span class="p">,</span> <span class="n">sadaei</span><span class="o">.</span><span class="n">ExponentialyWeightedFTS</span><span class="p">,</span> <span class="n">hofts</span><span class="o">.</span><span class="n">HighOrderFTS</span><span class="p">,</span> <span class="n">hwang</span><span class="o">.</span><span class="n">HighOrderFTS</span><span class="p">,</span>
            <span class="n">pwfts</span><span class="o">.</span><span class="n">ProbabilisticWeightedFTS</span><span class="p">]</span></div>


<div class="viewcode-block" id="get_benchmark_interval_methods"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.get_benchmark_interval_methods">[docs]</a><span class="k">def</span> <span class="nf">get_benchmark_interval_methods</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;Return all non FTS methods for point_to_interval forecasting&quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="p">[</span> <span class="n">arima</span><span class="o">.</span><span class="n">ARIMA</span><span class="p">,</span> <span class="n">quantreg</span><span class="o">.</span><span class="n">QuantileRegression</span><span class="p">]</span></div>


<div class="viewcode-block" id="get_interval_methods"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.get_interval_methods">[docs]</a><span class="k">def</span> <span class="nf">get_interval_methods</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;Return all FTS methods for point_to_interval forecasting&quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="p">[</span><span class="n">ifts</span><span class="o">.</span><span class="n">IntervalFTS</span><span class="p">,</span> <span class="n">pwfts</span><span class="o">.</span><span class="n">ProbabilisticWeightedFTS</span><span class="p">]</span></div>


<div class="viewcode-block" id="get_probabilistic_methods"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.get_probabilistic_methods">[docs]</a><span class="k">def</span> <span class="nf">get_probabilistic_methods</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;Return all FTS methods for probabilistic forecasting&quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="p">[</span><span class="n">ensemble</span><span class="o">.</span><span class="n">AllMethodEnsembleFTS</span><span class="p">,</span> <span class="n">pwfts</span><span class="o">.</span><span class="n">ProbabilisticWeightedFTS</span><span class="p">]</span></div>


<div class="viewcode-block" id="get_benchmark_probabilistic_methods"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.get_benchmark_probabilistic_methods">[docs]</a><span class="k">def</span> <span class="nf">get_benchmark_probabilistic_methods</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;Return all FTS methods for probabilistic forecasting&quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="p">[</span><span class="n">arima</span><span class="o">.</span><span class="n">ARIMA</span><span class="p">,</span> <span class="n">quantreg</span><span class="o">.</span><span class="n">QuantileRegression</span><span class="p">,</span> <span class="n">knn</span><span class="o">.</span><span class="n">KNearestNeighbors</span><span class="p">]</span></div>


<div class="viewcode-block" id="sliding_window_benchmarks"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.sliding_window_benchmarks">[docs]</a><span class="k">def</span> <span class="nf">sliding_window_benchmarks</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">windowsize</span><span class="p">,</span> <span class="n">train</span><span class="o">=</span><span class="mf">0.8</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Sliding window benchmarks for FTS forecasters.</span>

<span class="sd">    For each data window, a train and test datasets will be splitted. For each train split, number of</span>
<span class="sd">    partitions and partitioning method will be created a partitioner model. And for each partitioner, order,</span>
<span class="sd">    steps ahead and FTS method a foreasting model will be trained.</span>

<span class="sd">    Then all trained models are benchmarked on the test data and the metrics are stored on a sqlite3 database</span>
<span class="sd">    (identified by the &#39;file&#39; parameter) for posterior analysis.</span>

<span class="sd">    All these process can be distributed on a dispy cluster, setting the atributed &#39;distributed&#39; to true and</span>
<span class="sd">    informing the list of dispy nodes on &#39;nodes&#39; parameter.</span>

<span class="sd">    The number of experiments is determined by &#39;windowsize&#39; and &#39;inc&#39; parameters.</span>

<span class="sd">    :param data: test data</span>
<span class="sd">    :param windowsize: size of sliding window</span>
<span class="sd">    :param train: percentual of sliding window data used to train the models</span>
<span class="sd">    :param kwargs: dict, optional arguments</span>

<span class="sd">    :keyword benchmark_methods:  a list with Non FTS models to benchmark. The default is None.</span>
<span class="sd">    :keyword benchmark_methods_parameters:  a list with Non FTS models parameters. The default is None.</span>
<span class="sd">    :keyword benchmark_models: A boolean value indicating if external FTS methods will be used on benchmark. The default is False.</span>
<span class="sd">    :keyword build_methods: A boolean value indicating if the default FTS methods will be used on benchmark. The default is True.</span>
<span class="sd">    :keyword dataset: the dataset name to identify the current set of benchmarks results on database.</span>
<span class="sd">    :keyword distributed: A boolean value indicating if the forecasting procedure will be distributed in a dispy cluster. . The default is False</span>
<span class="sd">    :keyword file: file path to save the results. The default is benchmarks.db.</span>
<span class="sd">    :keyword inc: a float on interval [0,1] indicating the percentage of the windowsize to move the window</span>
<span class="sd">    :keyword methods: a list with FTS class names. The default depends on the forecasting type and contains the list of all FTS methods.</span>
<span class="sd">    :keyword models: a list with prebuilt FTS objects. The default is None.</span>
<span class="sd">    :keyword nodes: a list with the dispy cluster nodes addresses. The default is [127.0.0.1].</span>
<span class="sd">    :keyword orders: a list with orders of the models (for high order models). The default is [1,2,3].</span>
<span class="sd">    :keyword partitions: a list with the numbers of partitions on the Universe of Discourse. The default is [10].</span>
<span class="sd">    :keyword partitioners_models: a list with prebuilt Universe of Discourse partitioners objects. The default is None.</span>
<span class="sd">    :keyword partitioners_methods: a list with Universe of Discourse partitioners class names. The default is [partitioners.Grid.GridPartitioner].</span>
<span class="sd">    :keyword progress: If true a progress bar will be displayed during the benchmarks. The default is False.</span>
<span class="sd">    :keyword start: in the multi step forecasting, the index of the data where to start forecasting. The default is 0.</span>
<span class="sd">    :keyword steps_ahead: a list with  the forecasting horizons, i. e., the number of steps ahead to forecast. The default is 1.</span>
<span class="sd">    :keyword tag: a name to identify the current set of benchmarks results on database.</span>
<span class="sd">    :keyword type: the forecasting type, one of these values: point(default), interval or distribution. The default is point.</span>
<span class="sd">    :keyword transformations: a list with data transformations do apply . The default is [None].</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">tag</span> <span class="o">=</span> <span class="n">__pop</span><span class="p">(</span><span class="s1">&#39;tag&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>
    <span class="n">dataset</span> <span class="o">=</span> <span class="n">__pop</span><span class="p">(</span><span class="s1">&#39;dataset&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>

    <span class="n">distributed</span> <span class="o">=</span> <span class="n">__pop</span><span class="p">(</span><span class="s1">&#39;distributed&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>

    <span class="n">transformations</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;transformations&#39;</span><span class="p">,</span> <span class="p">[</span><span class="kc">None</span><span class="p">])</span>
    <span class="n">progress</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;progress&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
    <span class="nb">type</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;type&quot;</span><span class="p">,</span> <span class="s1">&#39;point&#39;</span><span class="p">)</span>

    <span class="n">orders</span> <span class="o">=</span> <span class="n">__pop</span><span class="p">(</span><span class="s2">&quot;orders&quot;</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">)</span>

    <span class="n">partitioners_models</span> <span class="o">=</span> <span class="n">__pop</span><span class="p">(</span><span class="s2">&quot;partitioners_models&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>
    <span class="n">partitioners_methods</span> <span class="o">=</span> <span class="n">__pop</span><span class="p">(</span><span class="s2">&quot;partitioners_methods&quot;</span><span class="p">,</span> <span class="p">[</span><span class="n">Grid</span><span class="o">.</span><span class="n">GridPartitioner</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">)</span>
    <span class="n">partitions</span> <span class="o">=</span> <span class="n">__pop</span><span class="p">(</span><span class="s2">&quot;partitions&quot;</span><span class="p">,</span> <span class="p">[</span><span class="mi">10</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">)</span>

    <span class="n">steps_ahead</span> <span class="o">=</span> <span class="n">__pop</span><span class="p">(</span><span class="s1">&#39;steps_ahead&#39;</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">)</span>

    <span class="n">methods</span> <span class="o">=</span> <span class="n">__pop</span><span class="p">(</span><span class="s1">&#39;methods&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>

    <span class="n">models</span> <span class="o">=</span> <span class="n">__pop</span><span class="p">(</span><span class="s1">&#39;models&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>

    <span class="n">pool</span> <span class="o">=</span> <span class="p">[]</span> <span class="k">if</span> <span class="n">models</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">models</span>

    <span class="k">if</span> <span class="n">methods</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="k">if</span> <span class="nb">type</span>  <span class="o">==</span> <span class="s1">&#39;point&#39;</span><span class="p">:</span>
            <span class="n">methods</span> <span class="o">=</span> <span class="n">get_point_methods</span><span class="p">()</span>
        <span class="k">elif</span> <span class="nb">type</span> <span class="o">==</span> <span class="s1">&#39;interval&#39;</span><span class="p">:</span>
            <span class="n">methods</span> <span class="o">=</span> <span class="n">get_interval_methods</span><span class="p">()</span>
        <span class="k">elif</span> <span class="nb">type</span> <span class="o">==</span> <span class="s1">&#39;distribution&#39;</span><span class="p">:</span>
            <span class="n">methods</span> <span class="o">=</span> <span class="n">get_probabilistic_methods</span><span class="p">()</span>

    <span class="n">build_methods</span> <span class="o">=</span> <span class="n">__pop</span><span class="p">(</span><span class="s2">&quot;build_methods&quot;</span><span class="p">,</span> <span class="kc">True</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">build_methods</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">method</span> <span class="ow">in</span> <span class="n">methods</span><span class="p">:</span>
            <span class="n">mfts</span> <span class="o">=</span> <span class="n">method</span><span class="p">()</span>

            <span class="k">if</span> <span class="n">mfts</span><span class="o">.</span><span class="n">is_high_order</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">order</span> <span class="ow">in</span> <span class="n">orders</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">order</span> <span class="o">&gt;=</span> <span class="n">mfts</span><span class="o">.</span><span class="n">min_order</span><span class="p">:</span>
                        <span class="n">mfts</span> <span class="o">=</span> <span class="n">method</span><span class="p">()</span>
                        <span class="n">mfts</span><span class="o">.</span><span class="n">order</span> <span class="o">=</span> <span class="n">order</span>
                        <span class="n">pool</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mfts</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">mfts</span><span class="o">.</span><span class="n">order</span> <span class="o">=</span> <span class="mi">1</span>
                <span class="n">pool</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mfts</span><span class="p">)</span>

    <span class="n">benchmark_models</span> <span class="o">=</span> <span class="n">__pop</span><span class="p">(</span><span class="s2">&quot;benchmark_models&quot;</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">benchmark_models</span> <span class="o">!=</span> <span class="kc">False</span><span class="p">:</span>

        <span class="n">benchmark_methods</span> <span class="o">=</span> <span class="n">__pop</span><span class="p">(</span><span class="s2">&quot;benchmark_methods&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>
        <span class="n">benchmark_methods_parameters</span> <span class="o">=</span> <span class="n">__pop</span><span class="p">(</span><span class="s2">&quot;benchmark_methods_parameters&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>

        <span class="n">benchmark_pool</span> <span class="o">=</span> <span class="p">[]</span> <span class="k">if</span> <span class="p">(</span> <span class="n">benchmark_models</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">benchmark_models</span><span class="p">,</span> <span class="nb">list</span><span class="p">))</span> \
            <span class="k">else</span> <span class="n">benchmark_models</span>

        <span class="k">if</span> <span class="n">benchmark_models</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">benchmark_methods</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">type</span> <span class="o">==</span> <span class="s1">&#39;point&#39;</span><span class="ow">or</span> <span class="nb">type</span>  <span class="o">==</span> <span class="s1">&#39;partition&#39;</span><span class="p">:</span>
                <span class="n">benchmark_methods</span> <span class="o">=</span> <span class="n">get_benchmark_point_methods</span><span class="p">()</span>
            <span class="k">elif</span> <span class="nb">type</span> <span class="o">==</span> <span class="s1">&#39;interval&#39;</span><span class="p">:</span>
                <span class="n">benchmark_methods</span> <span class="o">=</span> <span class="n">get_benchmark_interval_methods</span><span class="p">()</span>
            <span class="k">elif</span> <span class="nb">type</span> <span class="o">==</span> <span class="s1">&#39;distribution&#39;</span><span class="p">:</span>
                <span class="n">benchmark_methods</span> <span class="o">=</span> <span class="n">get_benchmark_probabilistic_methods</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">benchmark_methods</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">transformation</span> <span class="ow">in</span> <span class="n">transformations</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">count</span><span class="p">,</span> <span class="n">model</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">benchmark_methods</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
                    <span class="n">par</span> <span class="o">=</span> <span class="n">benchmark_methods_parameters</span><span class="p">[</span><span class="n">count</span><span class="p">]</span>
                    <span class="n">mfts</span> <span class="o">=</span> <span class="n">model</span><span class="p">(</span><span class="o">**</span><span class="n">par</span><span class="p">)</span>
                    <span class="n">mfts</span><span class="o">.</span><span class="n">append_transformation</span><span class="p">(</span><span class="n">transformation</span><span class="p">)</span>
                    <span class="n">benchmark_pool</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mfts</span><span class="p">)</span>

    <span class="k">if</span> <span class="nb">type</span> <span class="o">==</span> <span class="s1">&#39;point&#39;</span><span class="p">:</span>
        <span class="n">experiment_method</span> <span class="o">=</span> <span class="n">run_point</span>
        <span class="n">synthesis_method</span> <span class="o">=</span> <span class="n">process_point_jobs</span>
    <span class="k">elif</span> <span class="nb">type</span> <span class="o">==</span> <span class="s1">&#39;interval&#39;</span><span class="p">:</span>
        <span class="n">experiment_method</span> <span class="o">=</span> <span class="n">run_interval</span>
        <span class="n">synthesis_method</span> <span class="o">=</span> <span class="n">process_interval_jobs</span>
    <span class="k">elif</span> <span class="nb">type</span> <span class="o">==</span> <span class="s1">&#39;distribution&#39;</span><span class="p">:</span>
        <span class="n">experiment_method</span> <span class="o">=</span> <span class="n">run_probabilistic</span>
        <span class="n">synthesis_method</span> <span class="o">=</span> <span class="n">process_probabilistic_jobs</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Type parameter has a unkown value!&quot;</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">distributed</span><span class="p">:</span>
        <span class="kn">import</span> <span class="nn">dispy</span><span class="o">,</span> <span class="nn">dispy.httpd</span>

        <span class="n">nodes</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;nodes&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;127.0.0.1&#39;</span><span class="p">])</span>
        <span class="n">cluster</span><span class="p">,</span> <span class="n">http_server</span> <span class="o">=</span> <span class="n">cUtil</span><span class="o">.</span><span class="n">start_dispy_cluster</span><span class="p">(</span><span class="n">experiment_method</span><span class="p">,</span> <span class="n">nodes</span><span class="p">)</span>

    <span class="n">jobs</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="n">inc</span> <span class="o">=</span> <span class="n">__pop</span><span class="p">(</span><span class="s2">&quot;inc&quot;</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">progress</span><span class="p">:</span>
        <span class="kn">from</span> <span class="nn">tqdm</span> <span class="k">import</span> <span class="n">tqdm</span>
        <span class="n">_tdata</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">windowsize</span> <span class="o">*</span> <span class="n">inc</span><span class="p">)</span>
        <span class="n">_tasks</span> <span class="o">=</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">partitioners_models</span><span class="p">)</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">orders</span><span class="p">)</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">partitions</span><span class="p">)</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">transformations</span><span class="p">)</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">steps_ahead</span><span class="p">))</span>
        <span class="n">_tbcmk</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">benchmark_pool</span><span class="p">)</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">steps_ahead</span><span class="p">)</span>
        <span class="n">progressbar</span> <span class="o">=</span> <span class="n">tqdm</span><span class="p">(</span><span class="n">total</span><span class="o">=</span><span class="n">_tdata</span><span class="o">*</span><span class="n">_tasks</span> <span class="o">+</span> <span class="n">_tdata</span><span class="o">*</span><span class="n">_tbcmk</span><span class="p">,</span> <span class="n">desc</span><span class="o">=</span><span class="s2">&quot;Benchmarks:&quot;</span><span class="p">)</span>

    <span class="n">file</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;file&#39;</span><span class="p">,</span> <span class="s2">&quot;benchmarks.db&quot;</span><span class="p">)</span>

    <span class="n">conn</span> <span class="o">=</span> <span class="n">bUtil</span><span class="o">.</span><span class="n">open_benchmark_db</span><span class="p">(</span><span class="n">file</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">train</span><span class="p">,</span> <span class="n">test</span> <span class="ow">in</span> <span class="n">cUtil</span><span class="o">.</span><span class="n">sliding_window</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">windowsize</span><span class="p">,</span> <span class="n">train</span><span class="p">,</span> <span class="n">inc</span><span class="o">=</span><span class="n">inc</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">benchmark_models</span> <span class="o">!=</span> <span class="kc">False</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">model</span> <span class="ow">in</span> <span class="n">benchmark_pool</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">step</span> <span class="ow">in</span> <span class="n">steps_ahead</span><span class="p">:</span>

                    <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;steps_ahead&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">step</span>

                    <span class="k">if</span> <span class="ow">not</span> <span class="n">distributed</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">progress</span><span class="p">:</span>
                            <span class="n">progressbar</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
                        <span class="k">try</span><span class="p">:</span>
                            <span class="n">job</span> <span class="o">=</span> <span class="n">experiment_method</span><span class="p">(</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">model</span><span class="p">),</span> <span class="kc">None</span><span class="p">,</span> <span class="n">train</span><span class="p">,</span> <span class="n">test</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
                            <span class="n">synthesis_method</span><span class="p">(</span><span class="n">dataset</span><span class="p">,</span> <span class="n">tag</span><span class="p">,</span> <span class="n">job</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
                        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
                            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;EXCEPTION! &#39;</span><span class="p">,</span> <span class="n">model</span><span class="o">.</span><span class="n">shortname</span><span class="p">,</span> <span class="n">model</span><span class="o">.</span><span class="n">order</span><span class="p">)</span>
                            <span class="n">traceback</span><span class="o">.</span><span class="n">print_exc</span><span class="p">()</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">job</span> <span class="o">=</span> <span class="n">cluster</span><span class="o">.</span><span class="n">submit</span><span class="p">(</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">model</span><span class="p">),</span> <span class="kc">None</span><span class="p">,</span> <span class="n">train</span><span class="p">,</span> <span class="n">test</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
                        <span class="n">jobs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">job</span><span class="p">)</span>

        <span class="n">partitioners_pool</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">if</span> <span class="n">partitioners_models</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>

            <span class="k">for</span> <span class="n">transformation</span> <span class="ow">in</span> <span class="n">transformations</span><span class="p">:</span>

                <span class="k">for</span> <span class="n">partition</span> <span class="ow">in</span> <span class="n">partitions</span><span class="p">:</span>

                    <span class="k">for</span> <span class="n">partitioner</span> <span class="ow">in</span> <span class="n">partitioners_methods</span><span class="p">:</span>

                        <span class="n">data_train_fs</span> <span class="o">=</span> <span class="n">partitioner</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">train</span><span class="p">,</span> <span class="n">npart</span><span class="o">=</span><span class="n">partition</span><span class="p">,</span> <span class="n">transformation</span><span class="o">=</span><span class="n">transformation</span><span class="p">)</span>

                        <span class="n">partitioners_pool</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">data_train_fs</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">partitioners_pool</span> <span class="o">=</span> <span class="n">partitioners_models</span>

        <span class="k">for</span> <span class="n">step</span> <span class="ow">in</span> <span class="n">steps_ahead</span><span class="p">:</span>

            <span class="k">for</span> <span class="n">partitioner</span> <span class="ow">in</span> <span class="n">partitioners_pool</span><span class="p">:</span>

                <span class="k">for</span> <span class="n">_id</span><span class="p">,</span> <span class="n">model</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">pool</span><span class="p">,</span><span class="n">start</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>

                    <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;steps_ahead&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">step</span>

                    <span class="k">if</span> <span class="ow">not</span> <span class="n">distributed</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">progress</span><span class="p">:</span>
                            <span class="n">progressbar</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
                        <span class="k">try</span><span class="p">:</span>
                            <span class="n">job</span> <span class="o">=</span> <span class="n">experiment_method</span><span class="p">(</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">model</span><span class="p">),</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">partitioner</span><span class="p">),</span> <span class="n">train</span><span class="p">,</span> <span class="n">test</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
                            <span class="n">synthesis_method</span><span class="p">(</span><span class="n">dataset</span><span class="p">,</span> <span class="n">tag</span><span class="p">,</span> <span class="n">job</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
                        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
                            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;EXCEPTION! &#39;</span><span class="p">,</span><span class="n">model</span><span class="o">.</span><span class="n">shortname</span><span class="p">,</span> <span class="n">model</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">partitioner</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                                  <span class="n">partitioner</span><span class="o">.</span><span class="n">partitions</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">partitioner</span><span class="o">.</span><span class="n">transformation</span><span class="p">))</span>
                            <span class="n">traceback</span><span class="o">.</span><span class="n">print_exc</span><span class="p">()</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">job</span> <span class="o">=</span> <span class="n">cluster</span><span class="o">.</span><span class="n">submit</span><span class="p">(</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">model</span><span class="p">),</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">partitioner</span><span class="p">),</span> <span class="n">train</span><span class="p">,</span> <span class="n">test</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
                        <span class="n">job</span><span class="o">.</span><span class="n">id</span> <span class="o">=</span> <span class="nb">id</span>  <span class="c1"># associate an ID to identify jobs (if needed later)</span>
                        <span class="n">jobs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">job</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">progress</span><span class="p">:</span>
        <span class="n">progressbar</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

    <span class="k">if</span> <span class="n">distributed</span><span class="p">:</span>

        <span class="k">for</span> <span class="n">job</span> <span class="ow">in</span> <span class="n">jobs</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">progress</span><span class="p">:</span>
                <span class="n">progressbar</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
            <span class="n">job</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">job</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="n">dispy</span><span class="o">.</span><span class="n">DispyJob</span><span class="o">.</span><span class="n">Finished</span> <span class="ow">and</span> <span class="n">job</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">tmp</span> <span class="o">=</span> <span class="n">job</span><span class="o">.</span><span class="n">result</span>
                <span class="n">synthesis_method</span><span class="p">(</span><span class="n">dataset</span><span class="p">,</span> <span class="n">tag</span><span class="p">,</span> <span class="n">tmp</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;status&quot;</span><span class="p">,</span><span class="n">job</span><span class="o">.</span><span class="n">status</span><span class="p">)</span>
                <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;result&quot;</span><span class="p">,</span><span class="n">job</span><span class="o">.</span><span class="n">result</span><span class="p">)</span>
                <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;stdout&quot;</span><span class="p">,</span><span class="n">job</span><span class="o">.</span><span class="n">stdout</span><span class="p">)</span>
                <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;stderr&quot;</span><span class="p">,</span><span class="n">job</span><span class="o">.</span><span class="n">exception</span><span class="p">)</span>

        <span class="n">cluster</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>  <span class="c1"># wait for all jobs to finish</span>

        <span class="n">cUtil</span><span class="o">.</span><span class="n">stop_dispy_cluster</span><span class="p">(</span><span class="n">cluster</span><span class="p">,</span> <span class="n">http_server</span><span class="p">)</span>

    <span class="n">conn</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div>




<div class="viewcode-block" id="run_point"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.run_point">[docs]</a><span class="k">def</span> <span class="nf">run_point</span><span class="p">(</span><span class="n">mfts</span><span class="p">,</span> <span class="n">partitioner</span><span class="p">,</span> <span class="n">train_data</span><span class="p">,</span> <span class="n">test_data</span><span class="p">,</span> <span class="n">window_key</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Run the point forecasting benchmarks</span>

<span class="sd">    :param mfts: FTS model</span>
<span class="sd">    :param partitioner: Universe of Discourse partitioner</span>
<span class="sd">    :param train_data: data used to train the model</span>
<span class="sd">    :param test_data: ata used to test the model</span>
<span class="sd">    :param window_key: id of the sliding window</span>
<span class="sd">    :param transformation: data transformation</span>
<span class="sd">    :param indexer: seasonal indexer</span>
<span class="sd">    :return: a dictionary with the benchmark results</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="kn">import</span> <span class="nn">time</span>
    <span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="k">import</span> <span class="n">yu</span><span class="p">,</span> <span class="n">chen</span><span class="p">,</span> <span class="n">hofts</span><span class="p">,</span> <span class="n">pwfts</span><span class="p">,</span><span class="n">ismailefendi</span><span class="p">,</span><span class="n">sadaei</span><span class="p">,</span> <span class="n">song</span><span class="p">,</span> <span class="n">cheng</span><span class="p">,</span> <span class="n">hwang</span>
    <span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="k">import</span> <span class="n">Grid</span><span class="p">,</span> <span class="n">Entropy</span><span class="p">,</span> <span class="n">FCM</span>
    <span class="kn">from</span> <span class="nn">pyFTS.benchmarks</span> <span class="k">import</span> <span class="n">Measures</span><span class="p">,</span> <span class="n">naive</span><span class="p">,</span> <span class="n">arima</span><span class="p">,</span> <span class="n">quantreg</span>
    <span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="k">import</span> <span class="n">Transformations</span>

    <span class="n">tmp</span> <span class="o">=</span> <span class="p">[</span><span class="n">song</span><span class="o">.</span><span class="n">ConventionalFTS</span><span class="p">,</span> <span class="n">chen</span><span class="o">.</span><span class="n">ConventionalFTS</span><span class="p">,</span> <span class="n">yu</span><span class="o">.</span><span class="n">WeightedFTS</span><span class="p">,</span> <span class="n">ismailefendi</span><span class="o">.</span><span class="n">ImprovedWeightedFTS</span><span class="p">,</span>
           <span class="n">cheng</span><span class="o">.</span><span class="n">TrendWeightedFTS</span><span class="p">,</span> <span class="n">sadaei</span><span class="o">.</span><span class="n">ExponentialyWeightedFTS</span><span class="p">,</span> <span class="n">hofts</span><span class="o">.</span><span class="n">HighOrderFTS</span><span class="p">,</span> <span class="n">hwang</span><span class="o">.</span><span class="n">HighOrderFTS</span><span class="p">,</span>
           <span class="n">pwfts</span><span class="o">.</span><span class="n">ProbabilisticWeightedFTS</span><span class="p">]</span>

    <span class="n">tmp2</span> <span class="o">=</span> <span class="p">[</span><span class="n">Grid</span><span class="o">.</span><span class="n">GridPartitioner</span><span class="p">,</span> <span class="n">Entropy</span><span class="o">.</span><span class="n">EntropyPartitioner</span><span class="p">,</span> <span class="n">FCM</span><span class="o">.</span><span class="n">FCMPartitioner</span><span class="p">]</span>

    <span class="n">tmp4</span> <span class="o">=</span> <span class="p">[</span><span class="n">naive</span><span class="o">.</span><span class="n">Naive</span><span class="p">,</span> <span class="n">arima</span><span class="o">.</span><span class="n">ARIMA</span><span class="p">,</span> <span class="n">quantreg</span><span class="o">.</span><span class="n">QuantileRegression</span><span class="p">]</span>

    <span class="n">tmp3</span> <span class="o">=</span> <span class="p">[</span><span class="n">Measures</span><span class="o">.</span><span class="n">get_point_statistics</span><span class="p">]</span>

    <span class="n">tmp5</span> <span class="o">=</span> <span class="p">[</span><span class="n">Transformations</span><span class="o">.</span><span class="n">Differential</span><span class="p">]</span>

    <span class="n">indexer</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;indexer&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="n">steps_ahead</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;steps_ahead&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
    <span class="n">method</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;method&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">mfts</span><span class="o">.</span><span class="n">benchmark_only</span><span class="p">:</span>
        <span class="n">_key</span> <span class="o">=</span> <span class="n">mfts</span><span class="o">.</span><span class="n">shortname</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">mfts</span><span class="o">.</span><span class="n">order</span> <span class="k">if</span> <span class="n">mfts</span><span class="o">.</span><span class="n">order</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">pttr</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">partitioner</span><span class="o">.</span><span class="vm">__module__</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">_key</span> <span class="o">=</span> <span class="n">mfts</span><span class="o">.</span><span class="n">shortname</span> <span class="o">+</span> <span class="s2">&quot; n = &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">mfts</span><span class="o">.</span><span class="n">order</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="n">pttr</span> <span class="o">+</span> <span class="s2">&quot; q = &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">partitioner</span><span class="o">.</span><span class="n">partitions</span><span class="p">)</span>
        <span class="n">mfts</span><span class="o">.</span><span class="n">partitioner</span> <span class="o">=</span> <span class="n">partitioner</span>
        <span class="n">mfts</span><span class="o">.</span><span class="n">append_transformation</span><span class="p">(</span><span class="n">partitioner</span><span class="o">.</span><span class="n">transformation</span><span class="p">)</span>

    <span class="n">_key</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">steps_ahead</span><span class="p">)</span>
    <span class="n">_key</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">method</span><span class="p">)</span> <span class="k">if</span> <span class="n">method</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="s2">&quot;&quot;</span>

    <span class="n">_start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
    <span class="n">mfts</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">train_data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="n">_end</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
    <span class="n">times</span> <span class="o">=</span> <span class="n">_end</span> <span class="o">-</span> <span class="n">_start</span>


    <span class="n">_start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
    <span class="n">_rmse</span><span class="p">,</span> <span class="n">_smape</span><span class="p">,</span> <span class="n">_u</span> <span class="o">=</span> <span class="n">Measures</span><span class="o">.</span><span class="n">get_point_statistics</span><span class="p">(</span><span class="n">test_data</span><span class="p">,</span> <span class="n">mfts</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="n">_end</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
    <span class="n">times</span> <span class="o">+=</span> <span class="n">_end</span> <span class="o">-</span> <span class="n">_start</span>

    <span class="n">ret</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;key&#39;</span><span class="p">:</span> <span class="n">_key</span><span class="p">,</span> <span class="s1">&#39;obj&#39;</span><span class="p">:</span> <span class="n">mfts</span><span class="p">,</span> <span class="s1">&#39;rmse&#39;</span><span class="p">:</span> <span class="n">_rmse</span><span class="p">,</span> <span class="s1">&#39;smape&#39;</span><span class="p">:</span> <span class="n">_smape</span><span class="p">,</span> <span class="s1">&#39;u&#39;</span><span class="p">:</span> <span class="n">_u</span><span class="p">,</span> <span class="s1">&#39;time&#39;</span><span class="p">:</span> <span class="n">times</span><span class="p">,</span> <span class="s1">&#39;window&#39;</span><span class="p">:</span> <span class="n">window_key</span><span class="p">,</span>
           <span class="s1">&#39;steps&#39;</span><span class="p">:</span> <span class="n">steps_ahead</span><span class="p">,</span> <span class="s1">&#39;method&#39;</span><span class="p">:</span> <span class="n">method</span><span class="p">}</span>

    <span class="k">return</span> <span class="n">ret</span></div>


<div class="viewcode-block" id="run_interval"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.run_interval">[docs]</a><span class="k">def</span> <span class="nf">run_interval</span><span class="p">(</span><span class="n">mfts</span><span class="p">,</span> <span class="n">partitioner</span><span class="p">,</span> <span class="n">train_data</span><span class="p">,</span> <span class="n">test_data</span><span class="p">,</span> <span class="n">window_key</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Run the interval forecasting benchmarks</span>

<span class="sd">    :param mfts: FTS model</span>
<span class="sd">    :param partitioner: Universe of Discourse partitioner</span>
<span class="sd">    :param train_data: data used to train the model</span>
<span class="sd">    :param test_data: ata used to test the model</span>
<span class="sd">    :param window_key: id of the sliding window</span>
<span class="sd">    :param transformation: data transformation</span>
<span class="sd">    :param indexer: seasonal indexer</span>
<span class="sd">    :return: a dictionary with the benchmark results</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="kn">import</span> <span class="nn">time</span>
    <span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="k">import</span> <span class="n">hofts</span><span class="p">,</span><span class="n">ifts</span><span class="p">,</span><span class="n">pwfts</span>
    <span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="k">import</span> <span class="n">Grid</span><span class="p">,</span> <span class="n">Entropy</span><span class="p">,</span> <span class="n">FCM</span>
    <span class="kn">from</span> <span class="nn">pyFTS.benchmarks</span> <span class="k">import</span> <span class="n">Measures</span><span class="p">,</span> <span class="n">arima</span><span class="p">,</span> <span class="n">quantreg</span>

    <span class="n">tmp</span> <span class="o">=</span> <span class="p">[</span><span class="n">hofts</span><span class="o">.</span><span class="n">HighOrderFTS</span><span class="p">,</span> <span class="n">ifts</span><span class="o">.</span><span class="n">IntervalFTS</span><span class="p">,</span>  <span class="n">pwfts</span><span class="o">.</span><span class="n">ProbabilisticWeightedFTS</span><span class="p">]</span>

    <span class="n">tmp2</span> <span class="o">=</span> <span class="p">[</span><span class="n">Grid</span><span class="o">.</span><span class="n">GridPartitioner</span><span class="p">,</span> <span class="n">Entropy</span><span class="o">.</span><span class="n">EntropyPartitioner</span><span class="p">,</span> <span class="n">FCM</span><span class="o">.</span><span class="n">FCMPartitioner</span><span class="p">]</span>

    <span class="n">tmp4</span> <span class="o">=</span> <span class="p">[</span><span class="n">arima</span><span class="o">.</span><span class="n">ARIMA</span><span class="p">,</span> <span class="n">quantreg</span><span class="o">.</span><span class="n">QuantileRegression</span><span class="p">]</span>

    <span class="n">tmp3</span> <span class="o">=</span> <span class="p">[</span><span class="n">Measures</span><span class="o">.</span><span class="n">get_interval_statistics</span><span class="p">]</span>

    <span class="n">steps_ahead</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;steps_ahead&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
    <span class="n">method</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;method&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">mfts</span><span class="o">.</span><span class="n">benchmark_only</span><span class="p">:</span>
        <span class="n">_key</span> <span class="o">=</span> <span class="n">mfts</span><span class="o">.</span><span class="n">shortname</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">mfts</span><span class="o">.</span><span class="n">order</span> <span class="k">if</span> <span class="n">mfts</span><span class="o">.</span><span class="n">order</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="s2">&quot;&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">mfts</span><span class="o">.</span><span class="n">alpha</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">pttr</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">partitioner</span><span class="o">.</span><span class="vm">__module__</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">_key</span> <span class="o">=</span> <span class="n">mfts</span><span class="o">.</span><span class="n">shortname</span> <span class="o">+</span> <span class="s2">&quot; n = &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">mfts</span><span class="o">.</span><span class="n">order</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="n">pttr</span> <span class="o">+</span> <span class="s2">&quot; q = &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">partitioner</span><span class="o">.</span><span class="n">partitions</span><span class="p">)</span>
        <span class="n">mfts</span><span class="o">.</span><span class="n">partitioner</span> <span class="o">=</span> <span class="n">partitioner</span>
        <span class="n">mfts</span><span class="o">.</span><span class="n">append_transformation</span><span class="p">(</span><span class="n">partitioner</span><span class="o">.</span><span class="n">transformation</span><span class="p">)</span>

    <span class="n">_key</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">steps_ahead</span><span class="p">)</span>
    <span class="n">_key</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">method</span><span class="p">)</span> <span class="k">if</span> <span class="n">method</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="s2">&quot;&quot;</span>

    <span class="n">_start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
    <span class="n">mfts</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">train_data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="n">_end</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
    <span class="n">times</span> <span class="o">=</span> <span class="n">_end</span> <span class="o">-</span> <span class="n">_start</span>

    <span class="n">_start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
    <span class="c1">#_sharp, _res, _cov, _q05, _q25, _q75, _q95, _w05, _w25</span>
    <span class="n">metrics</span> <span class="o">=</span> <span class="n">Measures</span><span class="o">.</span><span class="n">get_interval_statistics</span><span class="p">(</span><span class="n">test_data</span><span class="p">,</span> <span class="n">mfts</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="n">_end</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
    <span class="n">times</span> <span class="o">+=</span> <span class="n">_end</span> <span class="o">-</span> <span class="n">_start</span>

    <span class="n">ret</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;key&#39;</span><span class="p">:</span> <span class="n">_key</span><span class="p">,</span> <span class="s1">&#39;obj&#39;</span><span class="p">:</span> <span class="n">mfts</span><span class="p">,</span> <span class="s1">&#39;sharpness&#39;</span><span class="p">:</span> <span class="n">metrics</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s1">&#39;resolution&#39;</span><span class="p">:</span> <span class="n">metrics</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="s1">&#39;coverage&#39;</span><span class="p">:</span> <span class="n">metrics</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span>
           <span class="s1">&#39;time&#39;</span><span class="p">:</span> <span class="n">times</span><span class="p">,</span><span class="s1">&#39;Q05&#39;</span><span class="p">:</span> <span class="n">metrics</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="s1">&#39;Q25&#39;</span><span class="p">:</span> <span class="n">metrics</span><span class="p">[</span><span class="mi">4</span><span class="p">],</span> <span class="s1">&#39;Q75&#39;</span><span class="p">:</span> <span class="n">metrics</span><span class="p">[</span><span class="mi">5</span><span class="p">],</span> <span class="s1">&#39;Q95&#39;</span><span class="p">:</span> <span class="n">metrics</span><span class="p">[</span><span class="mi">6</span><span class="p">],</span>
           <span class="s1">&#39;winkler05&#39;</span><span class="p">:</span> <span class="n">metrics</span><span class="p">[</span><span class="mi">7</span><span class="p">],</span> <span class="s1">&#39;winkler25&#39;</span><span class="p">:</span> <span class="n">metrics</span><span class="p">[</span><span class="mi">8</span><span class="p">],</span>
           <span class="s1">&#39;window&#39;</span><span class="p">:</span> <span class="n">window_key</span><span class="p">,</span><span class="s1">&#39;steps&#39;</span><span class="p">:</span> <span class="n">steps_ahead</span><span class="p">,</span> <span class="s1">&#39;method&#39;</span><span class="p">:</span> <span class="n">method</span><span class="p">}</span>

    <span class="k">return</span> <span class="n">ret</span></div>


<div class="viewcode-block" id="run_probabilistic"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.run_probabilistic">[docs]</a><span class="k">def</span> <span class="nf">run_probabilistic</span><span class="p">(</span><span class="n">mfts</span><span class="p">,</span> <span class="n">partitioner</span><span class="p">,</span> <span class="n">train_data</span><span class="p">,</span> <span class="n">test_data</span><span class="p">,</span> <span class="n">window_key</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Run the probabilistic forecasting benchmarks</span>

<span class="sd">    :param mfts: FTS model</span>
<span class="sd">    :param partitioner: Universe of Discourse partitioner</span>
<span class="sd">    :param train_data: data used to train the model</span>
<span class="sd">    :param test_data: ata used to test the model</span>
<span class="sd">    :param steps:</span>
<span class="sd">    :param resolution:</span>
<span class="sd">    :param window_key: id of the sliding window</span>
<span class="sd">    :param transformation: data transformation</span>
<span class="sd">    :param indexer: seasonal indexer</span>
<span class="sd">    :return: a dictionary with the benchmark results</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="kn">import</span> <span class="nn">time</span>
    <span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
    <span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="k">import</span> <span class="n">hofts</span><span class="p">,</span> <span class="n">ifts</span><span class="p">,</span> <span class="n">pwfts</span>
    <span class="kn">from</span> <span class="nn">pyFTS.models.ensemble</span> <span class="k">import</span> <span class="n">ensemble</span>
    <span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="k">import</span> <span class="n">Grid</span><span class="p">,</span> <span class="n">Entropy</span><span class="p">,</span> <span class="n">FCM</span>
    <span class="kn">from</span> <span class="nn">pyFTS.benchmarks</span> <span class="k">import</span> <span class="n">Measures</span><span class="p">,</span> <span class="n">arima</span><span class="p">,</span> <span class="n">quantreg</span><span class="p">,</span> <span class="n">knn</span>
    <span class="kn">from</span> <span class="nn">pyFTS.models.seasonal</span> <span class="k">import</span> <span class="n">SeasonalIndexer</span>

    <span class="n">tmp</span> <span class="o">=</span> <span class="p">[</span><span class="n">hofts</span><span class="o">.</span><span class="n">HighOrderFTS</span><span class="p">,</span> <span class="n">ifts</span><span class="o">.</span><span class="n">IntervalFTS</span><span class="p">,</span> <span class="n">pwfts</span><span class="o">.</span><span class="n">ProbabilisticWeightedFTS</span><span class="p">,</span> <span class="n">arima</span><span class="o">.</span><span class="n">ARIMA</span><span class="p">,</span>
           <span class="n">ensemble</span><span class="o">.</span><span class="n">AllMethodEnsembleFTS</span><span class="p">,</span> <span class="n">knn</span><span class="o">.</span><span class="n">KNearestNeighbors</span><span class="p">]</span>

    <span class="n">tmp2</span> <span class="o">=</span> <span class="p">[</span><span class="n">Grid</span><span class="o">.</span><span class="n">GridPartitioner</span><span class="p">,</span> <span class="n">Entropy</span><span class="o">.</span><span class="n">EntropyPartitioner</span><span class="p">,</span> <span class="n">FCM</span><span class="o">.</span><span class="n">FCMPartitioner</span><span class="p">]</span>

    <span class="n">tmp3</span> <span class="o">=</span> <span class="p">[</span><span class="n">Measures</span><span class="o">.</span><span class="n">get_distribution_statistics</span><span class="p">,</span> <span class="n">SeasonalIndexer</span><span class="o">.</span><span class="n">SeasonalIndexer</span><span class="p">,</span> <span class="n">SeasonalIndexer</span><span class="o">.</span><span class="n">LinearSeasonalIndexer</span><span class="p">]</span>

    <span class="n">indexer</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;indexer&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="n">steps_ahead</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;steps_ahead&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
    <span class="n">method</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;method&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">mfts</span><span class="o">.</span><span class="n">benchmark_only</span><span class="p">:</span>
        <span class="n">_key</span> <span class="o">=</span> <span class="n">mfts</span><span class="o">.</span><span class="n">shortname</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">mfts</span><span class="o">.</span><span class="n">order</span> <span class="k">if</span> <span class="n">mfts</span><span class="o">.</span><span class="n">order</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="s2">&quot;&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">mfts</span><span class="o">.</span><span class="n">alpha</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">pttr</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">partitioner</span><span class="o">.</span><span class="vm">__module__</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">_key</span> <span class="o">=</span> <span class="n">mfts</span><span class="o">.</span><span class="n">shortname</span> <span class="o">+</span> <span class="s2">&quot; n = &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">mfts</span><span class="o">.</span><span class="n">order</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="n">pttr</span> <span class="o">+</span> <span class="s2">&quot; q = &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">partitioner</span><span class="o">.</span><span class="n">partitions</span><span class="p">)</span>
        <span class="n">mfts</span><span class="o">.</span><span class="n">partitioner</span> <span class="o">=</span> <span class="n">partitioner</span>
        <span class="n">mfts</span><span class="o">.</span><span class="n">append_transformation</span><span class="p">(</span><span class="n">partitioner</span><span class="o">.</span><span class="n">transformation</span><span class="p">)</span>

    <span class="n">_key</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">steps_ahead</span><span class="p">)</span>
    <span class="n">_key</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">method</span><span class="p">)</span> <span class="k">if</span> <span class="n">method</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="s2">&quot;&quot;</span>

    <span class="k">if</span> <span class="n">mfts</span><span class="o">.</span><span class="n">has_seasonality</span><span class="p">:</span>
        <span class="n">mfts</span><span class="o">.</span><span class="n">indexer</span> <span class="o">=</span> <span class="n">indexer</span>

    <span class="n">_start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
    <span class="n">mfts</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">train_data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="n">_end</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
    <span class="n">times</span> <span class="o">=</span> <span class="n">_end</span> <span class="o">-</span> <span class="n">_start</span>

    <span class="n">_crps1</span><span class="p">,</span> <span class="n">_t1</span><span class="p">,</span> <span class="n">_brier</span> <span class="o">=</span> <span class="n">Measures</span><span class="o">.</span><span class="n">get_distribution_statistics</span><span class="p">(</span><span class="n">test_data</span><span class="p">,</span> <span class="n">mfts</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="n">_t1</span> <span class="o">+=</span> <span class="n">times</span>

    <span class="n">ret</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;key&#39;</span><span class="p">:</span> <span class="n">_key</span><span class="p">,</span> <span class="s1">&#39;obj&#39;</span><span class="p">:</span> <span class="n">mfts</span><span class="p">,</span> <span class="s1">&#39;CRPS&#39;</span><span class="p">:</span> <span class="n">_crps1</span><span class="p">,</span> <span class="s1">&#39;time&#39;</span><span class="p">:</span> <span class="n">_t1</span><span class="p">,</span> <span class="s1">&#39;brier&#39;</span><span class="p">:</span> <span class="n">_brier</span><span class="p">,</span> <span class="s1">&#39;window&#39;</span><span class="p">:</span> <span class="n">window_key</span><span class="p">,</span>
           <span class="s1">&#39;steps&#39;</span><span class="p">:</span> <span class="n">steps_ahead</span><span class="p">,</span> <span class="s1">&#39;method&#39;</span><span class="p">:</span> <span class="n">method</span><span class="p">}</span>

    <span class="k">return</span> <span class="n">ret</span></div>


<div class="viewcode-block" id="process_point_jobs"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.process_point_jobs">[docs]</a><span class="k">def</span> <span class="nf">process_point_jobs</span><span class="p">(</span><span class="n">dataset</span><span class="p">,</span> <span class="n">tag</span><span class="p">,</span>  <span class="n">job</span><span class="p">,</span> <span class="n">conn</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Extract information from a dictionary with point benchmark results and save it on a database</span>

<span class="sd">    :param dataset: the benchmark dataset name</span>
<span class="sd">    :param tag: alias for the benchmark group being executed</span>
<span class="sd">    :param job: a dictionary with the benchmark results</span>
<span class="sd">    :param conn: a connection to a Sqlite database</span>
<span class="sd">    :return:</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">data</span> <span class="o">=</span> <span class="n">bUtil</span><span class="o">.</span><span class="n">process_common_data</span><span class="p">(</span><span class="n">dataset</span><span class="p">,</span> <span class="n">tag</span><span class="p">,</span> <span class="s1">&#39;point&#39;</span><span class="p">,</span><span class="n">job</span><span class="p">)</span>

    <span class="n">rmse</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="n">rmse</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;rmse&quot;</span><span class="p">,</span> <span class="n">job</span><span class="p">[</span><span class="s2">&quot;rmse&quot;</span><span class="p">]])</span>
    <span class="n">bUtil</span><span class="o">.</span><span class="n">insert_benchmark</span><span class="p">(</span><span class="n">rmse</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
    <span class="n">smape</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="n">smape</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;smape&quot;</span><span class="p">,</span> <span class="n">job</span><span class="p">[</span><span class="s2">&quot;smape&quot;</span><span class="p">]])</span>
    <span class="n">bUtil</span><span class="o">.</span><span class="n">insert_benchmark</span><span class="p">(</span><span class="n">smape</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
    <span class="n">u</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="n">u</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;u&quot;</span><span class="p">,</span> <span class="n">job</span><span class="p">[</span><span class="s2">&quot;u&quot;</span><span class="p">]])</span>
    <span class="n">bUtil</span><span class="o">.</span><span class="n">insert_benchmark</span><span class="p">(</span><span class="n">u</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
    <span class="n">time</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="n">time</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;time&quot;</span><span class="p">,</span> <span class="n">job</span><span class="p">[</span><span class="s2">&quot;time&quot;</span><span class="p">]])</span>
    <span class="n">bUtil</span><span class="o">.</span><span class="n">insert_benchmark</span><span class="p">(</span><span class="n">time</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span></div>


<div class="viewcode-block" id="process_interval_jobs"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.process_interval_jobs">[docs]</a><span class="k">def</span> <span class="nf">process_interval_jobs</span><span class="p">(</span><span class="n">dataset</span><span class="p">,</span> <span class="n">tag</span><span class="p">,</span> <span class="n">job</span><span class="p">,</span> <span class="n">conn</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Extract information from an dictionary with interval benchmark results and save it on a database</span>

<span class="sd">    :param dataset: the benchmark dataset name</span>
<span class="sd">    :param tag: alias for the benchmark group being executed</span>
<span class="sd">    :param job: a dictionary with the benchmark results</span>
<span class="sd">    :param conn: a connection to a Sqlite database</span>
<span class="sd">    :return:</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">data</span> <span class="o">=</span> <span class="n">bUtil</span><span class="o">.</span><span class="n">process_common_data</span><span class="p">(</span><span class="n">dataset</span><span class="p">,</span> <span class="n">tag</span><span class="p">,</span> <span class="s1">&#39;interval&#39;</span><span class="p">,</span> <span class="n">job</span><span class="p">)</span>

    <span class="n">sharpness</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="n">sharpness</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;sharpness&quot;</span><span class="p">,</span> <span class="n">job</span><span class="p">[</span><span class="s2">&quot;sharpness&quot;</span><span class="p">]])</span>
    <span class="n">bUtil</span><span class="o">.</span><span class="n">insert_benchmark</span><span class="p">(</span><span class="n">sharpness</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
    <span class="n">resolution</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="n">resolution</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;resolution&quot;</span><span class="p">,</span> <span class="n">job</span><span class="p">[</span><span class="s2">&quot;resolution&quot;</span><span class="p">]])</span>
    <span class="n">bUtil</span><span class="o">.</span><span class="n">insert_benchmark</span><span class="p">(</span><span class="n">resolution</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
    <span class="n">coverage</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="n">coverage</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;coverage&quot;</span><span class="p">,</span> <span class="n">job</span><span class="p">[</span><span class="s2">&quot;coverage&quot;</span><span class="p">]])</span>
    <span class="n">bUtil</span><span class="o">.</span><span class="n">insert_benchmark</span><span class="p">(</span><span class="n">coverage</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
    <span class="n">time</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="n">time</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;time&quot;</span><span class="p">,</span> <span class="n">job</span><span class="p">[</span><span class="s2">&quot;time&quot;</span><span class="p">]])</span>
    <span class="n">bUtil</span><span class="o">.</span><span class="n">insert_benchmark</span><span class="p">(</span><span class="n">time</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
    <span class="n">Q05</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="n">Q05</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;Q05&quot;</span><span class="p">,</span> <span class="n">job</span><span class="p">[</span><span class="s2">&quot;Q05&quot;</span><span class="p">]])</span>
    <span class="n">bUtil</span><span class="o">.</span><span class="n">insert_benchmark</span><span class="p">(</span><span class="n">Q05</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
    <span class="n">Q25</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="n">Q25</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;Q25&quot;</span><span class="p">,</span> <span class="n">job</span><span class="p">[</span><span class="s2">&quot;Q25&quot;</span><span class="p">]])</span>
    <span class="n">bUtil</span><span class="o">.</span><span class="n">insert_benchmark</span><span class="p">(</span><span class="n">Q25</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
    <span class="n">Q75</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="n">Q75</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;Q75&quot;</span><span class="p">,</span> <span class="n">job</span><span class="p">[</span><span class="s2">&quot;Q75&quot;</span><span class="p">]])</span>
    <span class="n">bUtil</span><span class="o">.</span><span class="n">insert_benchmark</span><span class="p">(</span><span class="n">Q75</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
    <span class="n">Q95</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="n">Q95</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;Q95&quot;</span><span class="p">,</span> <span class="n">job</span><span class="p">[</span><span class="s2">&quot;Q95&quot;</span><span class="p">]])</span>
    <span class="n">bUtil</span><span class="o">.</span><span class="n">insert_benchmark</span><span class="p">(</span><span class="n">Q95</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
    <span class="n">W05</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="n">W05</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;winkler05&quot;</span><span class="p">,</span> <span class="n">job</span><span class="p">[</span><span class="s2">&quot;winkler05&quot;</span><span class="p">]])</span>
    <span class="n">bUtil</span><span class="o">.</span><span class="n">insert_benchmark</span><span class="p">(</span><span class="n">W05</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
    <span class="n">W25</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="n">W25</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;winkler25&quot;</span><span class="p">,</span> <span class="n">job</span><span class="p">[</span><span class="s2">&quot;winkler25&quot;</span><span class="p">]])</span>
    <span class="n">bUtil</span><span class="o">.</span><span class="n">insert_benchmark</span><span class="p">(</span><span class="n">W25</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span></div>


<div class="viewcode-block" id="process_probabilistic_jobs"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.process_probabilistic_jobs">[docs]</a><span class="k">def</span> <span class="nf">process_probabilistic_jobs</span><span class="p">(</span><span class="n">dataset</span><span class="p">,</span> <span class="n">tag</span><span class="p">,</span>  <span class="n">job</span><span class="p">,</span> <span class="n">conn</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Extract information from an dictionary with probabilistic benchmark results and save it on a database</span>

<span class="sd">    :param dataset: the benchmark dataset name</span>
<span class="sd">    :param tag: alias for the benchmark group being executed</span>
<span class="sd">    :param job: a dictionary with the benchmark results</span>
<span class="sd">    :param conn: a connection to a Sqlite database</span>
<span class="sd">    :return:</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">data</span> <span class="o">=</span> <span class="n">bUtil</span><span class="o">.</span><span class="n">process_common_data</span><span class="p">(</span><span class="n">dataset</span><span class="p">,</span> <span class="n">tag</span><span class="p">,</span>  <span class="s1">&#39;density&#39;</span><span class="p">,</span> <span class="n">job</span><span class="p">)</span>

    <span class="n">crps</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="n">crps</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;crps&quot;</span><span class="p">,</span><span class="n">job</span><span class="p">[</span><span class="s2">&quot;CRPS&quot;</span><span class="p">]])</span>
    <span class="n">bUtil</span><span class="o">.</span><span class="n">insert_benchmark</span><span class="p">(</span><span class="n">crps</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
    <span class="n">time</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="n">time</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;time&quot;</span><span class="p">,</span> <span class="n">job</span><span class="p">[</span><span class="s2">&quot;time&quot;</span><span class="p">]])</span>
    <span class="n">bUtil</span><span class="o">.</span><span class="n">insert_benchmark</span><span class="p">(</span><span class="n">time</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
    <span class="n">brier</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="n">brier</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;brier&quot;</span><span class="p">,</span> <span class="n">job</span><span class="p">[</span><span class="s2">&quot;brier&quot;</span><span class="p">]])</span>
    <span class="n">bUtil</span><span class="o">.</span><span class="n">insert_benchmark</span><span class="p">(</span><span class="n">brier</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span></div>


<div class="viewcode-block" id="print_point_statistics"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.print_point_statistics">[docs]</a><span class="k">def</span> <span class="nf">print_point_statistics</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">models</span><span class="p">,</span> <span class="n">externalmodels</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">externalforecasts</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">indexers</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Run point benchmarks on given models and data and print the results</span>

<span class="sd">    :param data: test data</span>
<span class="sd">    :param models: a list of FTS models to benchmark</span>
<span class="sd">    :param externalmodels: a list with benchmark models (façades for other methods)</span>
<span class="sd">    :param externalforecasts:</span>
<span class="sd">    :param indexers:</span>
<span class="sd">    :return:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">ret</span> <span class="o">=</span> <span class="s2">&quot;Model		&amp; Order     &amp; RMSE		&amp; SMAPE      &amp; Theil&#39;s U		</span><span class="se">\\\\</span><span class="s2"> </span><span class="se">\n</span><span class="s2">&quot;</span>
    <span class="k">for</span> <span class="n">count</span><span class="p">,</span><span class="n">model</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">models</span><span class="p">,</span><span class="n">start</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="n">_rmse</span><span class="p">,</span> <span class="n">_smape</span><span class="p">,</span> <span class="n">_u</span> <span class="o">=</span> <span class="n">Measures</span><span class="o">.</span><span class="n">get_point_statistics</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">indexers</span><span class="p">)</span>
        <span class="n">ret</span> <span class="o">+=</span> <span class="n">model</span><span class="o">.</span><span class="n">shortname</span> <span class="o">+</span> <span class="s2">&quot;		&amp; &quot;</span>
        <span class="n">ret</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">order</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;		&amp; &quot;</span>
        <span class="n">ret</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">_rmse</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;		&amp; &quot;</span>
        <span class="n">ret</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">_smape</span><span class="p">)</span><span class="o">+</span> <span class="s2">&quot;		&amp; &quot;</span>
        <span class="n">ret</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">_u</span><span class="p">)</span>
        <span class="c1">#ret += str(round(Measures.TheilsInequality(np.array(data[fts.order:]), np.array(forecasts[:-1])), 4))</span>
        <span class="n">ret</span> <span class="o">+=</span> <span class="s2">&quot;	</span><span class="se">\\\\</span><span class="s2"> </span><span class="se">\n</span><span class="s2">&quot;</span>
    <span class="k">if</span> <span class="n">externalmodels</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
        <span class="n">l</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">externalmodels</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">l</span><span class="p">):</span>
            <span class="n">ret</span> <span class="o">+=</span> <span class="n">externalmodels</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">+</span> <span class="s2">&quot;		&amp; &quot;</span>
            <span class="n">ret</span> <span class="o">+=</span> <span class="s2">&quot; 1		&amp; &quot;</span>
            <span class="n">ret</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">Measures</span><span class="o">.</span><span class="n">rmse</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">externalforecasts</span><span class="p">[</span><span class="n">k</span><span class="p">][:</span><span class="o">-</span><span class="mi">1</span><span class="p">]),</span> <span class="mi">2</span><span class="p">))</span> <span class="o">+</span> <span class="s2">&quot;		&amp; &quot;</span>
            <span class="n">ret</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">Measures</span><span class="o">.</span><span class="n">smape</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">externalforecasts</span><span class="p">[</span><span class="n">k</span><span class="p">][:</span><span class="o">-</span><span class="mi">1</span><span class="p">]),</span> <span class="mi">2</span><span class="p">))</span><span class="o">+</span> <span class="s2">&quot;		&amp; &quot;</span>
            <span class="n">ret</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">Measures</span><span class="o">.</span><span class="n">UStatistic</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">externalforecasts</span><span class="p">[</span><span class="n">k</span><span class="p">][:</span><span class="o">-</span><span class="mi">1</span><span class="p">]),</span> <span class="mi">2</span><span class="p">))</span>
            <span class="n">ret</span> <span class="o">+=</span> <span class="s2">&quot;	</span><span class="se">\\\\</span><span class="s2"> </span><span class="se">\n</span><span class="s2">&quot;</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span></div>


<div class="viewcode-block" id="print_interval_statistics"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.print_interval_statistics">[docs]</a><span class="k">def</span> <span class="nf">print_interval_statistics</span><span class="p">(</span><span class="n">original</span><span class="p">,</span> <span class="n">models</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Run interval benchmarks on given models and data and print the results</span>

<span class="sd">    :param data: test data</span>
<span class="sd">    :param models: a list of FTS models to benchmark</span>
<span class="sd">    :return:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">ret</span> <span class="o">=</span> <span class="s2">&quot;Model	&amp; Order     &amp; Sharpness		&amp; Resolution		&amp; Coverage &amp; .05  &amp; .25 &amp; .75 &amp; .95	</span><span class="se">\\\\</span><span class="s2"> </span><span class="se">\n</span><span class="s2">&quot;</span>
    <span class="k">for</span> <span class="n">fts</span> <span class="ow">in</span> <span class="n">models</span><span class="p">:</span>
        <span class="n">_sharp</span><span class="p">,</span> <span class="n">_res</span><span class="p">,</span> <span class="n">_cov</span><span class="p">,</span> <span class="n">_q5</span><span class="p">,</span> <span class="n">_q25</span><span class="p">,</span> <span class="n">_q75</span><span class="p">,</span> <span class="n">_q95</span>  <span class="o">=</span> <span class="n">Measures</span><span class="o">.</span><span class="n">get_interval_statistics</span><span class="p">(</span><span class="n">original</span><span class="p">,</span> <span class="n">fts</span><span class="p">)</span>
        <span class="n">ret</span> <span class="o">+=</span> <span class="n">fts</span><span class="o">.</span><span class="n">shortname</span> <span class="o">+</span> <span class="s2">&quot;		&amp; &quot;</span>
        <span class="n">ret</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">order</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;		&amp; &quot;</span>
        <span class="n">ret</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">_sharp</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;		&amp; &quot;</span>
        <span class="n">ret</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">_res</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;		&amp; &quot;</span>
        <span class="n">ret</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">_cov</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;        &amp;&quot;</span>
        <span class="n">ret</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">_q5</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;        &amp;&quot;</span>
        <span class="n">ret</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">_q25</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;        &amp;&quot;</span>
        <span class="n">ret</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">_q75</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;        &amp;&quot;</span>
        <span class="n">ret</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">_q95</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\\\\</span><span class="s2"> </span><span class="se">\n</span><span class="s2">&quot;</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span></div>


<div class="viewcode-block" id="print_distribution_statistics"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.print_distribution_statistics">[docs]</a><span class="k">def</span> <span class="nf">print_distribution_statistics</span><span class="p">(</span><span class="n">original</span><span class="p">,</span> <span class="n">models</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="n">resolution</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Run probabilistic benchmarks on given models and data and print the results</span>

<span class="sd">    :param data: test data</span>
<span class="sd">    :param models: a list of FTS models to benchmark</span>
<span class="sd">    :return:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">ret</span> <span class="o">=</span> <span class="s2">&quot;Model	&amp; Order     &amp;  Interval &amp; Distribution	</span><span class="se">\\\\</span><span class="s2"> </span><span class="se">\n</span><span class="s2">&quot;</span>
    <span class="k">for</span> <span class="n">fts</span> <span class="ow">in</span> <span class="n">models</span><span class="p">:</span>
        <span class="n">_crps1</span><span class="p">,</span> <span class="n">_crps2</span><span class="p">,</span> <span class="n">_t1</span><span class="p">,</span> <span class="n">_t2</span> <span class="o">=</span> <span class="n">Measures</span><span class="o">.</span><span class="n">get_distribution_statistics</span><span class="p">(</span><span class="n">original</span><span class="p">,</span> <span class="n">fts</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="n">resolution</span><span class="p">)</span>
        <span class="n">ret</span> <span class="o">+=</span> <span class="n">fts</span><span class="o">.</span><span class="n">shortname</span> <span class="o">+</span> <span class="s2">&quot;		&amp; &quot;</span>
        <span class="n">ret</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">order</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;		&amp; &quot;</span>
        <span class="n">ret</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">_crps1</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;		&amp; &quot;</span>
        <span class="n">ret</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">_crps2</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;	</span><span class="se">\\\\</span><span class="s2"> </span><span class="se">\n</span><span class="s2">&quot;</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span></div>



<div class="viewcode-block" id="plot_compared_intervals_ahead"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.plot_compared_intervals_ahead">[docs]</a><span class="k">def</span> <span class="nf">plot_compared_intervals_ahead</span><span class="p">(</span><span class="n">original</span><span class="p">,</span> <span class="n">models</span><span class="p">,</span> <span class="n">colors</span><span class="p">,</span> <span class="n">distributions</span><span class="p">,</span> <span class="n">time_from</span><span class="p">,</span> <span class="n">time_to</span><span class="p">,</span> <span class="n">intervals</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span>
                               <span class="n">save</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">file</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">tam</span><span class="o">=</span><span class="p">[</span><span class="mi">20</span><span class="p">,</span> <span class="mi">5</span><span class="p">],</span> <span class="n">resolution</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                               <span class="n">cmap</span><span class="o">=</span><span class="s1">&#39;Blues&#39;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mf">1.5</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Plot the forecasts of several one step ahead models, by point or by interval</span>

<span class="sd">    :param original: Original time series data (list)</span>
<span class="sd">    :param models: List of models to compare</span>
<span class="sd">    :param colors: List of models colors</span>
<span class="sd">    :param distributions: True to plot a distribution</span>
<span class="sd">    :param time_from: index of data poit to start the ahead forecasting</span>
<span class="sd">    :param time_to: number of steps ahead to forecast</span>
<span class="sd">    :param interpol: Fill space between distribution plots</span>
<span class="sd">    :param save: Save the picture on file</span>
<span class="sd">    :param file: Filename to save the picture</span>
<span class="sd">    :param tam: Size of the picture</span>
<span class="sd">    :param resolution: </span>
<span class="sd">    :param cmap: Color map to be used on distribution plot </span>
<span class="sd">    :param option: Distribution type to be passed for models</span>
<span class="sd">    :return: </span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="n">tam</span><span class="p">)</span>
    <span class="n">ax</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="mi">111</span><span class="p">)</span>

    <span class="n">cm</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">get_cmap</span><span class="p">(</span><span class="n">cmap</span><span class="p">)</span>
    <span class="n">cNorm</span> <span class="o">=</span> <span class="n">pltcolors</span><span class="o">.</span><span class="n">Normalize</span><span class="p">(</span><span class="n">vmin</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">vmax</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
    <span class="n">scalarMap</span> <span class="o">=</span> <span class="n">cmx</span><span class="o">.</span><span class="n">ScalarMappable</span><span class="p">(</span><span class="n">norm</span><span class="o">=</span><span class="n">cNorm</span><span class="p">,</span> <span class="n">cmap</span><span class="o">=</span><span class="n">cm</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">resolution</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> <span class="n">resolution</span> <span class="o">=</span> <span class="p">(</span><span class="nb">max</span><span class="p">(</span><span class="n">original</span><span class="p">)</span> <span class="o">-</span> <span class="nb">min</span><span class="p">(</span><span class="n">original</span><span class="p">))</span> <span class="o">/</span> <span class="mi">100</span>

    <span class="n">mi</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">ma</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">for</span> <span class="n">count</span><span class="p">,</span> <span class="n">fts</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">models</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">fts</span><span class="o">.</span><span class="n">has_probability_forecasting</span> <span class="ow">and</span> <span class="n">distributions</span><span class="p">[</span><span class="n">count</span><span class="p">]:</span>
            <span class="n">density</span> <span class="o">=</span> <span class="n">fts</span><span class="o">.</span><span class="n">forecast_ahead_distribution</span><span class="p">(</span><span class="n">original</span><span class="p">[</span><span class="n">time_from</span> <span class="o">-</span> <span class="n">fts</span><span class="o">.</span><span class="n">order</span><span class="p">:</span><span class="n">time_from</span><span class="p">],</span> <span class="n">time_to</span><span class="p">,</span>
                                                      <span class="n">resolution</span><span class="o">=</span><span class="n">resolution</span><span class="p">)</span>

            <span class="c1">#plot_density_scatter(ax, cmap, density, fig, resolution, time_from, time_to)</span>
            <span class="n">plot_density_rectange</span><span class="p">(</span><span class="n">ax</span><span class="p">,</span> <span class="n">cm</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">fig</span><span class="p">,</span> <span class="n">resolution</span><span class="p">,</span> <span class="n">time_from</span><span class="p">,</span> <span class="n">time_to</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">fts</span><span class="o">.</span><span class="n">has_interval_forecasting</span> <span class="ow">and</span> <span class="n">intervals</span><span class="p">:</span>
            <span class="n">forecasts</span> <span class="o">=</span> <span class="n">fts</span><span class="o">.</span><span class="n">forecast_ahead_interval</span><span class="p">(</span><span class="n">original</span><span class="p">[</span><span class="n">time_from</span> <span class="o">-</span> <span class="n">fts</span><span class="o">.</span><span class="n">order</span><span class="p">:</span><span class="n">time_from</span><span class="p">],</span> <span class="n">time_to</span><span class="p">)</span>
            <span class="n">lower</span> <span class="o">=</span> <span class="p">[</span><span class="n">kk</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">kk</span> <span class="ow">in</span> <span class="n">forecasts</span><span class="p">]</span>
            <span class="n">upper</span> <span class="o">=</span> <span class="p">[</span><span class="n">kk</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">kk</span> <span class="ow">in</span> <span class="n">forecasts</span><span class="p">]</span>
            <span class="n">mi</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">min</span><span class="p">(</span><span class="n">lower</span><span class="p">))</span>
            <span class="n">ma</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">max</span><span class="p">(</span><span class="n">upper</span><span class="p">))</span>
            <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">time_from</span> <span class="o">-</span> <span class="n">fts</span><span class="o">.</span><span class="n">order</span><span class="p">):</span>
                <span class="n">lower</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
                <span class="n">upper</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">lower</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">colors</span><span class="p">[</span><span class="n">count</span><span class="p">],</span> <span class="n">label</span><span class="o">=</span><span class="n">fts</span><span class="o">.</span><span class="n">shortname</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="n">linewidth</span><span class="p">)</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">upper</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">colors</span><span class="p">[</span><span class="n">count</span><span class="p">],</span> <span class="n">linewidth</span><span class="o">=</span><span class="n">linewidth</span><span class="o">*</span><span class="mf">1.5</span><span class="p">)</span>

    <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">original</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&#39;black&#39;</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;Original&quot;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="n">linewidth</span><span class="o">*</span><span class="mf">1.5</span><span class="p">)</span>
    <span class="n">handles0</span><span class="p">,</span> <span class="n">labels0</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">get_legend_handles_labels</span><span class="p">()</span>
    <span class="k">if</span> <span class="kc">True</span> <span class="ow">in</span> <span class="n">distributions</span><span class="p">:</span>
        <span class="n">lgd</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">handles0</span><span class="p">,</span> <span class="n">labels0</span><span class="p">,</span> <span class="n">loc</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">lgd</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">handles0</span><span class="p">,</span> <span class="n">labels0</span><span class="p">,</span> <span class="n">loc</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">bbox_to_anchor</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
    <span class="n">_mi</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">mi</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">_mi</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
        <span class="n">_mi</span> <span class="o">*=</span> <span class="mf">1.1</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">_mi</span> <span class="o">*=</span> <span class="mf">0.9</span>
    <span class="n">_ma</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">ma</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">_ma</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
        <span class="n">_ma</span> <span class="o">*=</span> <span class="mf">0.9</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">_ma</span> <span class="o">*=</span> <span class="mf">1.1</span>

    <span class="n">ax</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">([</span><span class="n">_mi</span><span class="p">,</span> <span class="n">_ma</span><span class="p">])</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;F(T)&#39;</span><span class="p">)</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;T&#39;</span><span class="p">)</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">original</span><span class="p">)])</span>

    <span class="n">cUtil</span><span class="o">.</span><span class="n">show_and_save_image</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">file</span><span class="p">,</span> <span class="n">save</span><span class="p">,</span> <span class="n">lgd</span><span class="o">=</span><span class="n">lgd</span><span class="p">)</span></div>



<div class="viewcode-block" id="plot_density_rectange"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.plot_density_rectange">[docs]</a><span class="k">def</span> <span class="nf">plot_density_rectange</span><span class="p">(</span><span class="n">ax</span><span class="p">,</span> <span class="n">cmap</span><span class="p">,</span> <span class="n">density</span><span class="p">,</span> <span class="n">fig</span><span class="p">,</span> <span class="n">resolution</span><span class="p">,</span> <span class="n">time_from</span><span class="p">,</span> <span class="n">time_to</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Auxiliar function to plot_compared_intervals_ahead</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="kn">from</span> <span class="nn">matplotlib.patches</span> <span class="k">import</span> <span class="n">Rectangle</span>
    <span class="kn">from</span> <span class="nn">matplotlib.collections</span> <span class="k">import</span> <span class="n">PatchCollection</span>
    <span class="n">patches</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">colors</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">density</span><span class="o">.</span><span class="n">index</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">y</span> <span class="ow">in</span> <span class="n">density</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">=</span> <span class="n">Rectangle</span><span class="p">((</span><span class="n">time_from</span> <span class="o">+</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">),</span> <span class="mi">1</span><span class="p">,</span> <span class="n">resolution</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">lw</span> <span class="o">=</span> <span class="mi">0</span><span class="p">)</span>
            <span class="n">patches</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
            <span class="n">colors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">density</span><span class="p">[</span><span class="n">y</span><span class="p">][</span><span class="n">x</span><span class="p">]</span><span class="o">*</span><span class="mi">5</span><span class="p">)</span>
    <span class="n">pc</span> <span class="o">=</span> <span class="n">PatchCollection</span><span class="p">(</span><span class="n">patches</span><span class="o">=</span><span class="n">patches</span><span class="p">,</span> <span class="n">match_original</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="n">pc</span><span class="o">.</span><span class="n">set_clim</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
    <span class="n">pc</span><span class="o">.</span><span class="n">set_cmap</span><span class="p">(</span><span class="n">cmap</span><span class="p">)</span>
    <span class="n">pc</span><span class="o">.</span><span class="n">set_array</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">colors</span><span class="p">))</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">add_collection</span><span class="p">(</span><span class="n">pc</span><span class="p">)</span>
    <span class="n">cb</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">colorbar</span><span class="p">(</span><span class="n">pc</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">)</span>
    <span class="n">cb</span><span class="o">.</span><span class="n">set_label</span><span class="p">(</span><span class="s1">&#39;Density&#39;</span><span class="p">)</span></div>


<div class="viewcode-block" id="plot_distribution"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.plot_distribution">[docs]</a><span class="k">def</span> <span class="nf">plot_distribution</span><span class="p">(</span><span class="n">ax</span><span class="p">,</span> <span class="n">cmap</span><span class="p">,</span> <span class="n">probabilitydist</span><span class="p">,</span> <span class="n">fig</span><span class="p">,</span> <span class="n">time_from</span><span class="p">,</span> <span class="n">reference_data</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="kn">from</span> <span class="nn">matplotlib.patches</span> <span class="k">import</span> <span class="n">Rectangle</span>
    <span class="kn">from</span> <span class="nn">matplotlib.collections</span> <span class="k">import</span> <span class="n">PatchCollection</span>
    <span class="n">patches</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">colors</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">dt</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">probabilitydist</span><span class="p">):</span>
        <span class="n">disp</span> <span class="o">=</span> <span class="mf">0.0</span>
        <span class="k">if</span> <span class="n">reference_data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">disp</span> <span class="o">=</span> <span class="n">reference_data</span><span class="p">[</span><span class="n">time_from</span><span class="o">+</span><span class="n">ct</span><span class="p">]</span>

        <span class="k">for</span> <span class="n">y</span> <span class="ow">in</span> <span class="n">dt</span><span class="o">.</span><span class="n">bins</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">=</span> <span class="n">Rectangle</span><span class="p">((</span><span class="n">time_from</span><span class="o">+</span><span class="n">ct</span><span class="p">,</span> <span class="n">y</span><span class="o">+</span><span class="n">disp</span><span class="p">),</span> <span class="mi">1</span><span class="p">,</span> <span class="n">dt</span><span class="o">.</span><span class="n">resolution</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">lw</span> <span class="o">=</span> <span class="mi">0</span><span class="p">)</span>
            <span class="n">patches</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
            <span class="n">colors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dt</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">y</span><span class="p">))</span>
    <span class="n">scale</span> <span class="o">=</span> <span class="n">Transformations</span><span class="o">.</span><span class="n">Scale</span><span class="p">()</span>
    <span class="n">colors</span> <span class="o">=</span> <span class="n">scale</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">colors</span><span class="p">)</span>
    <span class="n">pc</span> <span class="o">=</span> <span class="n">PatchCollection</span><span class="p">(</span><span class="n">patches</span><span class="o">=</span><span class="n">patches</span><span class="p">,</span> <span class="n">match_original</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="n">pc</span><span class="o">.</span><span class="n">set_clim</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
    <span class="n">pc</span><span class="o">.</span><span class="n">set_cmap</span><span class="p">(</span><span class="n">cmap</span><span class="p">)</span>
    <span class="n">pc</span><span class="o">.</span><span class="n">set_array</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">colors</span><span class="p">))</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">add_collection</span><span class="p">(</span><span class="n">pc</span><span class="p">)</span>
    <span class="n">cb</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">colorbar</span><span class="p">(</span><span class="n">pc</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">)</span>
    <span class="n">cb</span><span class="o">.</span><span class="n">set_label</span><span class="p">(</span><span class="s1">&#39;Density&#39;</span><span class="p">)</span></div>


<div class="viewcode-block" id="plot_interval"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.plot_interval">[docs]</a><span class="k">def</span> <span class="nf">plot_interval</span><span class="p">(</span><span class="n">axis</span><span class="p">,</span> <span class="n">intervals</span><span class="p">,</span> <span class="n">order</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&#39;red&#39;</span><span class="p">,</span> <span class="n">typeonlegend</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">ls</span><span class="o">=</span><span class="s1">&#39;-&#39;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
    <span class="n">lower</span> <span class="o">=</span> <span class="p">[</span><span class="n">kk</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">kk</span> <span class="ow">in</span> <span class="n">intervals</span><span class="p">]</span>
    <span class="n">upper</span> <span class="o">=</span> <span class="p">[</span><span class="n">kk</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">kk</span> <span class="ow">in</span> <span class="n">intervals</span><span class="p">]</span>
    <span class="n">mi</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">lower</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.95</span>
    <span class="n">ma</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">upper</span><span class="p">)</span> <span class="o">*</span> <span class="mf">1.05</span>
    <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">order</span><span class="p">):</span>
        <span class="n">lower</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">upper</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">typeonlegend</span><span class="p">:</span> <span class="n">label</span> <span class="o">+=</span> <span class="s2">&quot; (Interval)&quot;</span>
    <span class="n">axis</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">lower</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span> <span class="n">ls</span><span class="o">=</span><span class="n">ls</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="n">linewidth</span><span class="p">)</span>
    <span class="n">axis</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">upper</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span> <span class="n">ls</span><span class="o">=</span><span class="n">ls</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="n">linewidth</span><span class="p">)</span>
    <span class="k">return</span> <span class="p">[</span><span class="n">mi</span><span class="p">,</span> <span class="n">ma</span><span class="p">]</span></div>


<div class="viewcode-block" id="plot_point"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.plot_point">[docs]</a><span class="k">def</span> <span class="nf">plot_point</span><span class="p">(</span><span class="n">axis</span><span class="p">,</span> <span class="n">points</span><span class="p">,</span> <span class="n">order</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&#39;red&#39;</span><span class="p">,</span> <span class="n">ls</span><span class="o">=</span><span class="s1">&#39;-&#39;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
    <span class="n">mi</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">points</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.95</span>
    <span class="n">ma</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">points</span><span class="p">)</span> <span class="o">*</span> <span class="mf">1.05</span>
    <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">order</span><span class="p">):</span>
        <span class="n">points</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
    <span class="n">axis</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">points</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span> <span class="n">ls</span><span class="o">=</span><span class="n">ls</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="n">linewidth</span><span class="p">)</span>
    <span class="k">return</span> <span class="p">[</span><span class="n">mi</span><span class="p">,</span> <span class="n">ma</span><span class="p">]</span></div>



<div class="viewcode-block" id="plot_compared_series"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.plot_compared_series">[docs]</a><span class="k">def</span> <span class="nf">plot_compared_series</span><span class="p">(</span><span class="n">original</span><span class="p">,</span> <span class="n">models</span><span class="p">,</span> <span class="n">colors</span><span class="p">,</span> <span class="n">typeonlegend</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">save</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">file</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">tam</span><span class="o">=</span><span class="p">[</span><span class="mi">20</span><span class="p">,</span> <span class="mi">5</span><span class="p">],</span>
                         <span class="n">points</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">intervals</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mf">1.5</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Plot the forecasts of several one step ahead models, by point or by interval</span>

<span class="sd">    :param original: Original time series data (list)</span>
<span class="sd">    :param models: List of models to compare</span>
<span class="sd">    :param colors: List of models colors</span>
<span class="sd">    :param typeonlegend: Add the type of forecast (point / interval) on legend</span>
<span class="sd">    :param save: Save the picture on file</span>
<span class="sd">    :param file: Filename to save the picture</span>
<span class="sd">    :param tam: Size of the picture</span>
<span class="sd">    :param points: True to plot the point forecasts, False otherwise</span>
<span class="sd">    :param intervals: True to plot the interval forecasts, False otherwise</span>
<span class="sd">    :param linewidth:</span>
<span class="sd">    :return:</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="n">tam</span><span class="p">)</span>
    <span class="n">ax</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="mi">111</span><span class="p">)</span>

    <span class="n">mi</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">ma</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="n">legends</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">original</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&#39;black&#39;</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;Original&quot;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="n">linewidth</span><span class="o">*</span><span class="mf">1.5</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">count</span><span class="p">,</span> <span class="n">fts</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">models</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">fts</span><span class="o">.</span><span class="n">has_point_forecasting</span> <span class="ow">and</span> <span class="n">points</span><span class="p">:</span>
                <span class="n">forecasts</span> <span class="o">=</span> <span class="n">fts</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">original</span><span class="p">)</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">forecasts</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">):</span>
                    <span class="n">forecasts</span> <span class="o">=</span> <span class="n">forecasts</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
                <span class="n">mi</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">min</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.95</span><span class="p">)</span>
                <span class="n">ma</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">max</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span> <span class="o">*</span> <span class="mf">1.05</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">fts</span><span class="o">.</span><span class="n">order</span><span class="p">):</span>
                    <span class="n">forecasts</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
                <span class="n">lbl</span> <span class="o">=</span> <span class="n">fts</span><span class="o">.</span><span class="n">shortname</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">order</span> <span class="k">if</span> <span class="n">fts</span><span class="o">.</span><span class="n">is_high_order</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">fts</span><span class="o">.</span><span class="n">benchmark_only</span> <span class="k">else</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">typeonlegend</span><span class="p">:</span> <span class="n">lbl</span> <span class="o">+=</span> <span class="s2">&quot; (Point)&quot;</span>
                <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">forecasts</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">colors</span><span class="p">[</span><span class="n">count</span><span class="p">],</span> <span class="n">label</span><span class="o">=</span><span class="n">lbl</span><span class="p">,</span> <span class="n">ls</span><span class="o">=</span><span class="s2">&quot;-&quot;</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="n">linewidth</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">fts</span><span class="o">.</span><span class="n">has_interval_forecasting</span> <span class="ow">and</span> <span class="n">intervals</span><span class="p">:</span>
                <span class="n">forecasts</span> <span class="o">=</span> <span class="n">fts</span><span class="o">.</span><span class="n">forecast_interval</span><span class="p">(</span><span class="n">original</span><span class="p">)</span>
                <span class="n">lbl</span> <span class="o">=</span> <span class="n">fts</span><span class="o">.</span><span class="n">shortname</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">order</span> <span class="k">if</span> <span class="n">fts</span><span class="o">.</span><span class="n">is_high_order</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">fts</span><span class="o">.</span><span class="n">benchmark_only</span> <span class="k">else</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">points</span> <span class="ow">and</span> <span class="n">intervals</span><span class="p">:</span>
                    <span class="n">ls</span> <span class="o">=</span> <span class="s2">&quot;-&quot;</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">ls</span> <span class="o">=</span> <span class="s2">&quot;--&quot;</span>
                <span class="n">tmpmi</span><span class="p">,</span> <span class="n">tmpma</span> <span class="o">=</span> <span class="n">plot_interval</span><span class="p">(</span><span class="n">ax</span><span class="p">,</span> <span class="n">forecasts</span><span class="p">,</span> <span class="n">fts</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">lbl</span><span class="p">,</span> <span class="n">typeonlegend</span><span class="o">=</span><span class="n">typeonlegend</span><span class="p">,</span>
                                             <span class="n">color</span><span class="o">=</span><span class="n">colors</span><span class="p">[</span><span class="n">count</span><span class="p">],</span> <span class="n">ls</span><span class="o">=</span><span class="n">ls</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="n">linewidth</span><span class="p">)</span>
                <span class="n">mi</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmpmi</span><span class="p">)</span>
                <span class="n">ma</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmpma</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">shortname</span><span class="p">)</span>

        <span class="n">handles0</span><span class="p">,</span> <span class="n">labels0</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">get_legend_handles_labels</span><span class="p">()</span>
        <span class="n">lgd</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">handles0</span><span class="p">,</span> <span class="n">labels0</span><span class="p">,</span> <span class="n">loc</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">bbox_to_anchor</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
        <span class="n">legends</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">lgd</span><span class="p">)</span>

    <span class="c1"># ax.set_title(fts.name)</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">([</span><span class="nb">min</span><span class="p">(</span><span class="n">mi</span><span class="p">),</span> <span class="nb">max</span><span class="p">(</span><span class="n">ma</span><span class="p">)])</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;F(T)&#39;</span><span class="p">)</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;T&#39;</span><span class="p">)</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">original</span><span class="p">)])</span></div>

    <span class="c1">#Util.show_and_save_image(fig, file, save, lgd=legends)</span>


<div class="viewcode-block" id="plot_probability_distributions"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.plot_probability_distributions">[docs]</a><span class="k">def</span> <span class="nf">plot_probability_distributions</span><span class="p">(</span><span class="n">pmfs</span><span class="p">,</span> <span class="n">lcolors</span><span class="p">,</span> <span class="n">tam</span><span class="o">=</span><span class="p">[</span><span class="mi">15</span><span class="p">,</span> <span class="mi">7</span><span class="p">]):</span>
    <span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="n">tam</span><span class="p">)</span>
    <span class="n">ax</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="mi">111</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">k</span><span class="p">,</span><span class="n">m</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">pmfs</span><span class="p">,</span><span class="n">start</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="n">m</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">ax</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">lcolors</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>

    <span class="n">handles0</span><span class="p">,</span> <span class="n">labels0</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">get_legend_handles_labels</span><span class="p">()</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">handles0</span><span class="p">,</span> <span class="n">labels0</span><span class="p">)</span></div>



<div class="viewcode-block" id="plotCompared"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.plotCompared">[docs]</a><span class="k">def</span> <span class="nf">plotCompared</span><span class="p">(</span><span class="n">original</span><span class="p">,</span> <span class="n">forecasts</span><span class="p">,</span> <span class="n">labels</span><span class="p">,</span> <span class="n">title</span><span class="p">):</span>
    <span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">[</span><span class="mi">13</span><span class="p">,</span> <span class="mi">6</span><span class="p">])</span>
    <span class="n">ax</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="mi">111</span><span class="p">)</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">original</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&#39;k&#39;</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;Original&quot;</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)):</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">forecasts</span><span class="p">[</span><span class="n">c</span><span class="p">],</span> <span class="n">label</span><span class="o">=</span><span class="n">labels</span><span class="p">[</span><span class="n">c</span><span class="p">])</span>
    <span class="n">handles0</span><span class="p">,</span> <span class="n">labels0</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">get_legend_handles_labels</span><span class="p">()</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">handles0</span><span class="p">,</span> <span class="n">labels0</span><span class="p">)</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="n">title</span><span class="p">)</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;F(T)&#39;</span><span class="p">)</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;T&#39;</span><span class="p">)</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">original</span><span class="p">)])</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">([</span><span class="nb">min</span><span class="p">(</span><span class="n">original</span><span class="p">),</span> <span class="nb">max</span><span class="p">(</span><span class="n">original</span><span class="p">)])</span></div>


<div class="viewcode-block" id="SelecaoSimples_MenorRMSE"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.SelecaoSimples_MenorRMSE">[docs]</a><span class="k">def</span> <span class="nf">SelecaoSimples_MenorRMSE</span><span class="p">(</span><span class="n">original</span><span class="p">,</span> <span class="n">parameters</span><span class="p">,</span> <span class="n">modelo</span><span class="p">):</span>
    <span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">forecasted_best</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Série Original&quot;</span><span class="p">)</span>
    <span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">[</span><span class="mi">20</span><span class="p">,</span> <span class="mi">12</span><span class="p">])</span>
    <span class="n">fig</span><span class="o">.</span><span class="n">suptitle</span><span class="p">(</span><span class="s2">&quot;Comparação de modelos &quot;</span><span class="p">)</span>
    <span class="n">ax0</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_axes</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.65</span><span class="p">,</span> <span class="mf">0.45</span><span class="p">])</span>  <span class="c1"># left, bottom, width, height</span>
    <span class="n">ax0</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">original</span><span class="p">)])</span>
    <span class="n">ax0</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">([</span><span class="nb">min</span><span class="p">(</span><span class="n">original</span><span class="p">),</span> <span class="nb">max</span><span class="p">(</span><span class="n">original</span><span class="p">)])</span>
    <span class="n">ax0</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">&#39;Série Temporal&#39;</span><span class="p">)</span>
    <span class="n">ax0</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;F(T)&#39;</span><span class="p">)</span>
    <span class="n">ax0</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;T&#39;</span><span class="p">)</span>
    <span class="n">ax0</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">original</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;Original&quot;</span><span class="p">)</span>
    <span class="n">min_rmse</span> <span class="o">=</span> <span class="mf">100000.0</span>
    <span class="n">best</span> <span class="o">=</span> <span class="kc">None</span>
    <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">parameters</span><span class="p">:</span>
        <span class="n">sets</span> <span class="o">=</span> <span class="n">Grid</span><span class="o">.</span><span class="n">GridPartitioner</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">original</span><span class="p">,</span> <span class="n">npart</span><span class="o">=</span><span class="n">p</span><span class="p">)</span><span class="o">.</span><span class="n">sets</span>
        <span class="n">fts</span> <span class="o">=</span> <span class="n">modelo</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">p</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; particoes&quot;</span><span class="p">)</span>
        <span class="n">fts</span><span class="o">.</span><span class="n">train</span><span class="p">(</span><span class="n">original</span><span class="p">,</span> <span class="n">sets</span><span class="o">=</span><span class="n">sets</span><span class="p">)</span>
        <span class="c1"># print(original)</span>
        <span class="n">forecasted</span> <span class="o">=</span> <span class="n">fts</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">original</span><span class="p">)</span>
        <span class="n">forecasted</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">original</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="c1"># print(forecasted)</span>
        <span class="n">ax0</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">forecasted</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">fts</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
        <span class="n">error</span> <span class="o">=</span> <span class="n">Measures</span><span class="o">.</span><span class="n">rmse</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">forecasted</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">original</span><span class="p">))</span>
        <span class="nb">print</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">error</span><span class="p">)</span>
        <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">error</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">error</span> <span class="o">&lt;</span> <span class="n">min_rmse</span><span class="p">:</span>
            <span class="n">min_rmse</span> <span class="o">=</span> <span class="n">error</span>
            <span class="n">best</span> <span class="o">=</span> <span class="n">fts</span>
            <span class="n">forecasted_best</span> <span class="o">=</span> <span class="n">forecasted</span>
    <span class="n">handles0</span><span class="p">,</span> <span class="n">labels0</span> <span class="o">=</span> <span class="n">ax0</span><span class="o">.</span><span class="n">get_legend_handles_labels</span><span class="p">()</span>
    <span class="n">ax0</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">handles0</span><span class="p">,</span> <span class="n">labels0</span><span class="p">)</span>
    <span class="n">ax1</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_axes</span><span class="p">([</span><span class="mf">0.7</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.45</span><span class="p">])</span>  <span class="c1"># left, bottom, width, height</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">&#39;Comparação dos Erros Quadráticos Médios&#39;</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;RMSE&#39;</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;Quantidade de Partições&#39;</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">([</span><span class="nb">min</span><span class="p">(</span><span class="n">parameters</span><span class="p">),</span> <span class="nb">max</span><span class="p">(</span><span class="n">parameters</span><span class="p">)])</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">parameters</span><span class="p">,</span> <span class="n">errors</span><span class="p">)</span>
    <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">best</span><span class="p">)</span>
    <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">forecasted_best</span><span class="p">)</span>
    <span class="c1"># Modelo diferencial</span>
    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Série Diferencial&quot;</span><span class="p">)</span>
    <span class="n">difffts</span> <span class="o">=</span> <span class="n">Transformations</span><span class="o">.</span><span class="n">differential</span><span class="p">(</span><span class="n">original</span><span class="p">)</span>
    <span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">forecastedd_best</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">ax2</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_axes</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mf">0.65</span><span class="p">,</span> <span class="mf">0.45</span><span class="p">])</span>  <span class="c1"># left, bottom, width, height</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">difffts</span><span class="p">)])</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">([</span><span class="nb">min</span><span class="p">(</span><span class="n">difffts</span><span class="p">),</span> <span class="nb">max</span><span class="p">(</span><span class="n">difffts</span><span class="p">)])</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">&#39;Série Temporal&#39;</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;F(T)&#39;</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;T&#39;</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">difffts</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;Original&quot;</span><span class="p">)</span>
    <span class="n">min_rmse</span> <span class="o">=</span> <span class="mf">100000.0</span>
    <span class="n">bestd</span> <span class="o">=</span> <span class="kc">None</span>
    <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">parameters</span><span class="p">:</span>
        <span class="n">sets</span> <span class="o">=</span> <span class="n">Grid</span><span class="o">.</span><span class="n">GridPartitioner</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">difffts</span><span class="p">,</span> <span class="n">npart</span><span class="o">=</span><span class="n">p</span><span class="p">)</span>
        <span class="n">fts</span> <span class="o">=</span> <span class="n">modelo</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">p</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; particoes&quot;</span><span class="p">)</span>
        <span class="n">fts</span><span class="o">.</span><span class="n">train</span><span class="p">(</span><span class="n">difffts</span><span class="p">,</span> <span class="n">sets</span><span class="o">=</span><span class="n">sets</span><span class="p">)</span>
        <span class="n">forecasted</span> <span class="o">=</span> <span class="n">fts</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">difffts</span><span class="p">)</span>
        <span class="n">forecasted</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">difffts</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="n">ax2</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">forecasted</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">fts</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
        <span class="n">error</span> <span class="o">=</span> <span class="n">Measures</span><span class="o">.</span><span class="n">rmse</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">forecasted</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">difffts</span><span class="p">))</span>
        <span class="nb">print</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">error</span><span class="p">)</span>
        <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">error</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">error</span> <span class="o">&lt;</span> <span class="n">min_rmse</span><span class="p">:</span>
            <span class="n">min_rmse</span> <span class="o">=</span> <span class="n">error</span>
            <span class="n">bestd</span> <span class="o">=</span> <span class="n">fts</span>
            <span class="n">forecastedd_best</span> <span class="o">=</span> <span class="n">forecasted</span>
    <span class="n">handles0</span><span class="p">,</span> <span class="n">labels0</span> <span class="o">=</span> <span class="n">ax2</span><span class="o">.</span><span class="n">get_legend_handles_labels</span><span class="p">()</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">handles0</span><span class="p">,</span> <span class="n">labels0</span><span class="p">)</span>
    <span class="n">ax3</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_axes</span><span class="p">([</span><span class="mf">0.7</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.45</span><span class="p">])</span>  <span class="c1"># left, bottom, width, height</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">&#39;Comparação dos Erros Quadráticos Médios&#39;</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;RMSE&#39;</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;Quantidade de Partições&#39;</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">([</span><span class="nb">min</span><span class="p">(</span><span class="n">parameters</span><span class="p">),</span> <span class="nb">max</span><span class="p">(</span><span class="n">parameters</span><span class="p">)])</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">parameters</span><span class="p">,</span> <span class="n">errors</span><span class="p">)</span>
    <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">bestd</span><span class="p">)</span>
    <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">forecastedd_best</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">ret</span></div>


<div class="viewcode-block" id="compareModelsPlot"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.compareModelsPlot">[docs]</a><span class="k">def</span> <span class="nf">compareModelsPlot</span><span class="p">(</span><span class="n">original</span><span class="p">,</span> <span class="n">models_fo</span><span class="p">,</span> <span class="n">models_ho</span><span class="p">):</span>
    <span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">[</span><span class="mi">13</span><span class="p">,</span> <span class="mi">6</span><span class="p">])</span>
    <span class="n">fig</span><span class="o">.</span><span class="n">suptitle</span><span class="p">(</span><span class="s2">&quot;Comparação de modelos &quot;</span><span class="p">)</span>
    <span class="n">ax0</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_axes</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>  <span class="c1"># left, bottom, width, height</span>
    <span class="n">rows</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">model</span> <span class="ow">in</span> <span class="n">models_fo</span><span class="p">:</span>
        <span class="n">fts</span> <span class="o">=</span> <span class="n">model</span><span class="p">[</span><span class="s2">&quot;model&quot;</span><span class="p">]</span>
        <span class="n">ax0</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">model</span><span class="p">[</span><span class="s2">&quot;forecasted&quot;</span><span class="p">],</span> <span class="n">label</span><span class="o">=</span><span class="n">model</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">])</span>
    <span class="k">for</span> <span class="n">model</span> <span class="ow">in</span> <span class="n">models_ho</span><span class="p">:</span>
        <span class="n">fts</span> <span class="o">=</span> <span class="n">model</span><span class="p">[</span><span class="s2">&quot;model&quot;</span><span class="p">]</span>
        <span class="n">ax0</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">model</span><span class="p">[</span><span class="s2">&quot;forecasted&quot;</span><span class="p">],</span> <span class="n">label</span><span class="o">=</span><span class="n">model</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">])</span>
    <span class="n">handles0</span><span class="p">,</span> <span class="n">labels0</span> <span class="o">=</span> <span class="n">ax0</span><span class="o">.</span><span class="n">get_legend_handles_labels</span><span class="p">()</span>
    <span class="n">ax0</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">handles0</span><span class="p">,</span> <span class="n">labels0</span><span class="p">)</span></div>


<div class="viewcode-block" id="compareModelsTable"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.compareModelsTable">[docs]</a><span class="k">def</span> <span class="nf">compareModelsTable</span><span class="p">(</span><span class="n">original</span><span class="p">,</span> <span class="n">models_fo</span><span class="p">,</span> <span class="n">models_ho</span><span class="p">):</span>
    <span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">[</span><span class="mi">12</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span>
    <span class="n">fig</span><span class="o">.</span><span class="n">suptitle</span><span class="p">(</span><span class="s2">&quot;Comparação de modelos &quot;</span><span class="p">)</span>
    <span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;Modelo&#39;</span><span class="p">,</span> <span class="s1">&#39;Ordem&#39;</span><span class="p">,</span> <span class="s1">&#39;Partições&#39;</span><span class="p">,</span> <span class="s1">&#39;RMSE&#39;</span><span class="p">,</span> <span class="s1">&#39;MAPE (%)&#39;</span><span class="p">]</span>
    <span class="n">rows</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">model</span> <span class="ow">in</span> <span class="n">models_fo</span><span class="p">:</span>
        <span class="n">fts</span> <span class="o">=</span> <span class="n">model</span><span class="p">[</span><span class="s2">&quot;model&quot;</span><span class="p">]</span>
        <span class="n">error_r</span> <span class="o">=</span> <span class="n">Measures</span><span class="o">.</span><span class="n">rmse</span><span class="p">(</span><span class="n">model</span><span class="p">[</span><span class="s2">&quot;forecasted&quot;</span><span class="p">],</span> <span class="n">original</span><span class="p">)</span>
        <span class="n">error_m</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">Measures</span><span class="o">.</span><span class="n">mape</span><span class="p">(</span><span class="n">model</span><span class="p">[</span><span class="s2">&quot;forecasted&quot;</span><span class="p">],</span> <span class="n">original</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
        <span class="n">rows</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">model</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">],</span> <span class="n">fts</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">sets</span><span class="p">),</span> <span class="n">error_r</span><span class="p">,</span> <span class="n">error_m</span><span class="p">])</span>
    <span class="k">for</span> <span class="n">model</span> <span class="ow">in</span> <span class="n">models_ho</span><span class="p">:</span>
        <span class="n">fts</span> <span class="o">=</span> <span class="n">model</span><span class="p">[</span><span class="s2">&quot;model&quot;</span><span class="p">]</span>
        <span class="n">error_r</span> <span class="o">=</span> <span class="n">Measures</span><span class="o">.</span><span class="n">rmse</span><span class="p">(</span><span class="n">model</span><span class="p">[</span><span class="s2">&quot;forecasted&quot;</span><span class="p">][</span><span class="n">fts</span><span class="o">.</span><span class="n">order</span><span class="p">:],</span> <span class="n">original</span><span class="p">[</span><span class="n">fts</span><span class="o">.</span><span class="n">order</span><span class="p">:])</span>
        <span class="n">error_m</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">Measures</span><span class="o">.</span><span class="n">mape</span><span class="p">(</span><span class="n">model</span><span class="p">[</span><span class="s2">&quot;forecasted&quot;</span><span class="p">][</span><span class="n">fts</span><span class="o">.</span><span class="n">order</span><span class="p">:],</span> <span class="n">original</span><span class="p">[</span><span class="n">fts</span><span class="o">.</span><span class="n">order</span><span class="p">:])</span> <span class="o">*</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
        <span class="n">rows</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">model</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">],</span> <span class="n">fts</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">sets</span><span class="p">),</span> <span class="n">error_r</span><span class="p">,</span> <span class="n">error_m</span><span class="p">])</span>
    <span class="n">ax1</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_axes</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>  <span class="c1"># left, bottom, width, height</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">set_xticks</span><span class="p">([])</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">set_yticks</span><span class="p">([])</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">table</span><span class="p">(</span><span class="n">cellText</span><span class="o">=</span><span class="n">rows</span><span class="p">,</span>
              <span class="n">colLabels</span><span class="o">=</span><span class="n">columns</span><span class="p">,</span>
              <span class="n">cellLoc</span><span class="o">=</span><span class="s1">&#39;center&#39;</span><span class="p">,</span>
              <span class="n">bbox</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
    <span class="n">sup</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="se">\\</span><span class="s2">begin</span><span class="si">{tabular}</span><span class="s2">{&quot;</span>
    <span class="n">header</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
    <span class="n">body</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
    <span class="n">footer</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>

    <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">columns</span><span class="p">:</span>
        <span class="n">sup</span> <span class="o">=</span> <span class="n">sup</span> <span class="o">+</span> <span class="s2">&quot;|c&quot;</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">header</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">header</span> <span class="o">=</span> <span class="n">header</span> <span class="o">+</span> <span class="s2">&quot; &amp; &quot;</span>
        <span class="n">header</span> <span class="o">=</span> <span class="n">header</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\\</span><span class="s2">textbf{&quot;</span> <span class="o">+</span> <span class="n">c</span> <span class="o">+</span> <span class="s2">&quot;} &quot;</span>
    <span class="n">sup</span> <span class="o">=</span> <span class="n">sup</span> <span class="o">+</span> <span class="s2">&quot;|} </span><span class="se">\\</span><span class="s2">hline</span><span class="se">\n</span><span class="s2">&quot;</span>
    <span class="n">header</span> <span class="o">=</span> <span class="n">header</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\\\\</span><span class="s2"> </span><span class="se">\\</span><span class="s2">hline </span><span class="se">\n</span><span class="s2">&quot;</span>

    <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">rows</span><span class="p">:</span>
        <span class="n">lin</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
        <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">r</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">lin</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">lin</span> <span class="o">=</span> <span class="n">lin</span> <span class="o">+</span> <span class="s2">&quot; &amp; &quot;</span>
            <span class="n">lin</span> <span class="o">=</span> <span class="n">lin</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>

        <span class="n">body</span> <span class="o">=</span> <span class="n">body</span> <span class="o">+</span> <span class="n">lin</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\\\\</span><span class="s2"> </span><span class="se">\\</span><span class="s2">hline </span><span class="se">\n</span><span class="s2">&quot;</span>

    <span class="k">return</span> <span class="n">sup</span> <span class="o">+</span> <span class="n">header</span> <span class="o">+</span> <span class="n">body</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\\</span><span class="s2">end</span><span class="si">{tabular}</span><span class="s2">&quot;</span></div>


<div class="viewcode-block" id="simpleSearch_RMSE"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.simpleSearch_RMSE">[docs]</a><span class="k">def</span> <span class="nf">simpleSearch_RMSE</span><span class="p">(</span><span class="n">train</span><span class="p">,</span> <span class="n">test</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">partitions</span><span class="p">,</span> <span class="n">orders</span><span class="p">,</span> <span class="n">save</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">file</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">tam</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span> <span class="mi">15</span><span class="p">],</span>
                      <span class="n">plotforecasts</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">elev</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> <span class="n">azim</span><span class="o">=</span><span class="mi">144</span><span class="p">,</span> <span class="n">intervals</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span><span class="n">parameters</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                      <span class="n">partitioner</span><span class="o">=</span><span class="n">Grid</span><span class="o">.</span><span class="n">GridPartitioner</span><span class="p">,</span><span class="n">transformation</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span><span class="n">indexer</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="n">_3d</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">orders</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span>
    <span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">if</span> <span class="n">_3d</span><span class="p">:</span>
        <span class="n">errors</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">0</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">partitions</span><span class="p">))]</span> <span class="k">for</span> <span class="n">kk</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">orders</span><span class="p">))])</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">forecasted_best</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="n">tam</span><span class="p">)</span>
    <span class="c1"># fig.suptitle(&quot;Comparação de modelos &quot;)</span>
    <span class="k">if</span> <span class="n">plotforecasts</span><span class="p">:</span>
        <span class="n">ax0</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_axes</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">])</span>  <span class="c1"># left, bottom, width, height</span>
        <span class="n">ax0</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">train</span><span class="p">)])</span>
        <span class="n">ax0</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">([</span><span class="nb">min</span><span class="p">(</span><span class="n">train</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.9</span><span class="p">,</span> <span class="nb">max</span><span class="p">(</span><span class="n">train</span><span class="p">)</span> <span class="o">*</span> <span class="mf">1.1</span><span class="p">])</span>
        <span class="n">ax0</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">&#39;Forecasts&#39;</span><span class="p">)</span>
        <span class="n">ax0</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;F(T)&#39;</span><span class="p">)</span>
        <span class="n">ax0</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;T&#39;</span><span class="p">)</span>
    <span class="n">min_rmse</span> <span class="o">=</span> <span class="mf">1000000.0</span>
    <span class="n">best</span> <span class="o">=</span> <span class="kc">None</span>

    <span class="k">for</span> <span class="n">pc</span><span class="p">,</span> <span class="n">p</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">partitions</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>

        <span class="n">sets</span> <span class="o">=</span> <span class="n">partitioner</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">train</span><span class="p">,</span> <span class="n">npart</span><span class="o">=</span><span class="n">p</span><span class="p">,</span> <span class="n">transformation</span><span class="o">=</span><span class="n">transformation</span><span class="p">)</span><span class="o">.</span><span class="n">sets</span>
        <span class="k">for</span> <span class="n">oc</span><span class="p">,</span> <span class="n">o</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">orders</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
            <span class="n">fts</span> <span class="o">=</span> <span class="n">model</span><span class="p">(</span><span class="s2">&quot;q = &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">p</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; n = &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">o</span><span class="p">))</span>
            <span class="n">fts</span><span class="o">.</span><span class="n">append_transformation</span><span class="p">(</span><span class="n">transformation</span><span class="p">)</span>
            <span class="n">fts</span><span class="o">.</span><span class="n">train</span><span class="p">(</span><span class="n">train</span><span class="p">,</span> <span class="n">sets</span><span class="o">=</span><span class="n">sets</span><span class="p">,</span> <span class="n">order</span><span class="o">=</span><span class="n">o</span><span class="p">,</span> <span class="n">parameters</span><span class="o">=</span><span class="n">parameters</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">intervals</span><span class="p">:</span>
                <span class="n">forecasted</span> <span class="o">=</span> <span class="n">fts</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">test</span><span class="p">)</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">fts</span><span class="o">.</span><span class="n">has_seasonality</span><span class="p">:</span>
                    <span class="n">error</span> <span class="o">=</span> <span class="n">Measures</span><span class="o">.</span><span class="n">rmse</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">test</span><span class="p">[</span><span class="n">o</span><span class="p">:]),</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">forecasted</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">error</span> <span class="o">=</span> <span class="n">Measures</span><span class="o">.</span><span class="n">rmse</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">test</span><span class="p">[</span><span class="n">o</span><span class="p">:]),</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">forecasted</span><span class="p">))</span>
                <span class="k">for</span> <span class="n">kk</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">o</span><span class="p">):</span>
                    <span class="n">forecasted</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">plotforecasts</span><span class="p">:</span> <span class="n">ax0</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">forecasted</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">fts</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">forecasted</span> <span class="o">=</span> <span class="n">fts</span><span class="o">.</span><span class="n">forecast_interval</span><span class="p">(</span><span class="n">test</span><span class="p">)</span>
                <span class="n">error</span> <span class="o">=</span> <span class="mf">1.0</span> <span class="o">-</span> <span class="n">Measures</span><span class="o">.</span><span class="n">rmse_interval</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">test</span><span class="p">[</span><span class="n">o</span><span class="p">:]),</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">forecasted</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]))</span>
            <span class="k">if</span> <span class="n">_3d</span><span class="p">:</span>
                <span class="n">errors</span><span class="p">[</span><span class="n">oc</span><span class="p">,</span> <span class="n">pc</span><span class="p">]</span> <span class="o">=</span> <span class="n">error</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span> <span class="n">error</span> <span class="p">)</span>
            <span class="k">if</span> <span class="n">error</span> <span class="o">&lt;</span> <span class="n">min_rmse</span><span class="p">:</span>
                <span class="n">min_rmse</span> <span class="o">=</span> <span class="n">error</span>
                <span class="n">best</span> <span class="o">=</span> <span class="n">fts</span>
                <span class="n">forecasted_best</span> <span class="o">=</span> <span class="n">forecasted</span>

    <span class="c1"># print(min_rmse)</span>
    <span class="k">if</span> <span class="n">plotforecasts</span><span class="p">:</span>
        <span class="c1"># handles0, labels0 = ax0.get_legend_handles_labels()</span>
        <span class="c1"># ax0.legend(handles0, labels0)</span>
        <span class="n">ax0</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">test</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;Original&quot;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mf">3.0</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s2">&quot;black&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">_3d</span><span class="p">:</span> <span class="n">ax1</span> <span class="o">=</span> <span class="n">Axes3D</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">rect</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">],</span> <span class="n">elev</span><span class="o">=</span><span class="n">elev</span><span class="p">,</span> <span class="n">azim</span><span class="o">=</span><span class="n">azim</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">_3d</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">plotforecasts</span><span class="p">:</span>
        <span class="n">ax1</span> <span class="o">=</span> <span class="n">Axes3D</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">rect</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">],</span> <span class="n">elev</span><span class="o">=</span><span class="n">elev</span><span class="p">,</span> <span class="n">azim</span><span class="o">=</span><span class="n">azim</span><span class="p">)</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">&#39;Error Surface&#39;</span><span class="p">)</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Model order&#39;</span><span class="p">)</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;Number of partitions&#39;</span><span class="p">)</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">set_zlabel</span><span class="p">(</span><span class="s1">&#39;RMSE&#39;</span><span class="p">)</span>
        <span class="n">X</span><span class="p">,</span> <span class="n">Y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">meshgrid</span><span class="p">(</span><span class="n">partitions</span><span class="p">,</span> <span class="n">orders</span><span class="p">)</span>
        <span class="n">surf</span> <span class="o">=</span> <span class="n">ax1</span><span class="o">.</span><span class="n">plot_surface</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span><span class="p">,</span> <span class="n">errors</span><span class="p">,</span> <span class="n">rstride</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">cstride</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">antialiased</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ax1</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_axes</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">])</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">&#39;Error Curve&#39;</span><span class="p">)</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;Number of partitions&#39;</span><span class="p">)</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;RMSE&#39;</span><span class="p">)</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">partitions</span><span class="p">,</span> <span class="n">errors</span><span class="p">)</span>
    <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">best</span><span class="p">)</span>
    <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">forecasted_best</span><span class="p">)</span>
    <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">min_rmse</span><span class="p">)</span>

    <span class="c1"># plt.tight_layout()</span>

    <span class="n">cUtil</span><span class="o">.</span><span class="n">show_and_save_image</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">file</span><span class="p">,</span> <span class="n">save</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">ret</span></div>



<div class="viewcode-block" id="pftsExploreOrderAndPartitions"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.benchmarks.pftsExploreOrderAndPartitions">[docs]</a><span class="k">def</span> <span class="nf">pftsExploreOrderAndPartitions</span><span class="p">(</span><span class="n">data</span><span class="p">,</span><span class="n">save</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">file</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="n">fig</span><span class="p">,</span> <span class="n">axes</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="n">nrows</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span> <span class="n">ncols</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">[</span><span class="mi">6</span><span class="p">,</span> <span class="mi">8</span><span class="p">])</span>
    <span class="n">data_fs1</span> <span class="o">=</span> <span class="n">Grid</span><span class="o">.</span><span class="n">GridPartitioner</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span> <span class="n">npart</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span><span class="o">.</span><span class="n">sets</span>
    <span class="n">mi</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">ma</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="n">axes</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">&#39;Point Forecasts by Order&#39;</span><span class="p">)</span>
    <span class="n">axes</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">&#39;Interval Forecasts by Order&#39;</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">order</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">6</span><span class="p">):</span>
        <span class="n">fts</span> <span class="o">=</span> <span class="n">pwfts</span><span class="o">.</span><span class="n">ProbabilisticWeightedFTS</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
        <span class="n">fts</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;n = &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">order</span><span class="p">)</span>
        <span class="n">fts</span><span class="o">.</span><span class="n">train</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">sets</span><span class="o">=</span><span class="n">data_fs1</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">order</span><span class="o">=</span><span class="n">order</span><span class="p">)</span>
        <span class="n">point_forecasts</span> <span class="o">=</span> <span class="n">fts</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
        <span class="n">interval_forecasts</span> <span class="o">=</span> <span class="n">fts</span><span class="o">.</span><span class="n">forecast_interval</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
        <span class="n">lower</span> <span class="o">=</span> <span class="p">[</span><span class="n">kk</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">kk</span> <span class="ow">in</span> <span class="n">interval_forecasts</span><span class="p">]</span>
        <span class="n">upper</span> <span class="o">=</span> <span class="p">[</span><span class="n">kk</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">kk</span> <span class="ow">in</span> <span class="n">interval_forecasts</span><span class="p">]</span>
        <span class="n">mi</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">min</span><span class="p">(</span><span class="n">lower</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.95</span><span class="p">)</span>
        <span class="n">ma</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">max</span><span class="p">(</span><span class="n">upper</span><span class="p">)</span> <span class="o">*</span> <span class="mf">1.05</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">order</span><span class="p">):</span>
            <span class="n">point_forecasts</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
            <span class="n">lower</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
            <span class="n">upper</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">axes</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">point_forecasts</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">fts</span><span class="o">.</span><span class="n">shortname</span><span class="p">)</span>
        <span class="n">axes</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">lower</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">fts</span><span class="o">.</span><span class="n">shortname</span><span class="p">)</span>
        <span class="n">axes</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">upper</span><span class="p">)</span>

    <span class="n">axes</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">&#39;Point Forecasts by Number of Partitions&#39;</span><span class="p">)</span>
    <span class="n">axes</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">&#39;Interval Forecasts by Number of Partitions&#39;</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">partitions</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">11</span><span class="p">):</span>
        <span class="n">data_fs</span> <span class="o">=</span> <span class="n">Grid</span><span class="o">.</span><span class="n">GridPartitioner</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span> <span class="n">npart</span><span class="o">=</span><span class="n">partitions</span><span class="p">)</span><span class="o">.</span><span class="n">sets</span>
        <span class="n">fts</span> <span class="o">=</span> <span class="n">pwfts</span><span class="o">.</span><span class="n">ProbabilisticWeightedFTS</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
        <span class="n">fts</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;q = &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">partitions</span><span class="p">)</span>
        <span class="n">fts</span><span class="o">.</span><span class="n">train</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">sets</span><span class="o">=</span><span class="n">data_fs</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">order</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">point_forecasts</span> <span class="o">=</span> <span class="n">fts</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
        <span class="n">interval_forecasts</span> <span class="o">=</span> <span class="n">fts</span><span class="o">.</span><span class="n">forecast_interval</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
        <span class="n">lower</span> <span class="o">=</span> <span class="p">[</span><span class="n">kk</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">kk</span> <span class="ow">in</span> <span class="n">interval_forecasts</span><span class="p">]</span>
        <span class="n">upper</span> <span class="o">=</span> <span class="p">[</span><span class="n">kk</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">kk</span> <span class="ow">in</span> <span class="n">interval_forecasts</span><span class="p">]</span>
        <span class="n">mi</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">min</span><span class="p">(</span><span class="n">lower</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.95</span><span class="p">)</span>
        <span class="n">ma</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">max</span><span class="p">(</span><span class="n">upper</span><span class="p">)</span> <span class="o">*</span> <span class="mf">1.05</span><span class="p">)</span>
        <span class="n">point_forecasts</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">lower</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">upper</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">axes</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">point_forecasts</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">fts</span><span class="o">.</span><span class="n">shortname</span><span class="p">)</span>
        <span class="n">axes</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">lower</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">fts</span><span class="o">.</span><span class="n">shortname</span><span class="p">)</span>
        <span class="n">axes</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">upper</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">ax</span> <span class="ow">in</span> <span class="n">axes</span><span class="p">:</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;F(T)&#39;</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;T&#39;</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;Original&quot;</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s2">&quot;black&quot;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mf">1.5</span><span class="p">)</span>
        <span class="n">handles</span><span class="p">,</span> <span class="n">labels</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">get_legend_handles_labels</span><span class="p">()</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">handles</span><span class="p">,</span> <span class="n">labels</span><span class="p">,</span> <span class="n">loc</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">bbox_to_anchor</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">([</span><span class="nb">min</span><span class="p">(</span><span class="n">mi</span><span class="p">),</span> <span class="nb">max</span><span class="p">(</span><span class="n">ma</span><span class="p">)])</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)])</span>

    <span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span>

    <span class="n">cUtil</span><span class="o">.</span><span class="n">show_and_save_image</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">file</span><span class="p">,</span> <span class="n">save</span><span class="p">)</span></div>

</pre></div>

          </div>
        </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="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.2.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.7.2.
    </div>
  </body>
</html>