Documentation update

This commit is contained in:
Petrônio Cândido 2021-01-12 18:04:42 -03:00
parent d1fb71c30d
commit 01198b8b08
86 changed files with 24697 additions and 293 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -54,12 +54,24 @@
<div class="body" role="main">
<h1>All modules for which code is available</h1>
<ul><li><a href="pyFTS/common/Composite.html">pyFTS.common.Composite</a></li>
<ul><li><a href="pyFTS/benchmarks/BSTS.html">pyFTS.benchmarks.BSTS</a></li>
<li><a href="pyFTS/benchmarks/Measures.html">pyFTS.benchmarks.Measures</a></li>
<li><a href="pyFTS/benchmarks/ResidualAnalysis.html">pyFTS.benchmarks.ResidualAnalysis</a></li>
<li><a href="pyFTS/benchmarks/Tests.html">pyFTS.benchmarks.Tests</a></li>
<li><a href="pyFTS/benchmarks/Util.html">pyFTS.benchmarks.Util</a></li>
<li><a href="pyFTS/benchmarks/arima.html">pyFTS.benchmarks.arima</a></li>
<li><a href="pyFTS/benchmarks/benchmarks.html">pyFTS.benchmarks.benchmarks</a></li>
<li><a href="pyFTS/benchmarks/knn.html">pyFTS.benchmarks.knn</a></li>
<li><a href="pyFTS/benchmarks/naive.html">pyFTS.benchmarks.naive</a></li>
<li><a href="pyFTS/benchmarks/quantreg.html">pyFTS.benchmarks.quantreg</a></li>
<li><a href="pyFTS/common/Composite.html">pyFTS.common.Composite</a></li>
<li><a href="pyFTS/common/FLR.html">pyFTS.common.FLR</a></li>
<li><a href="pyFTS/common/FuzzySet.html">pyFTS.common.FuzzySet</a></li>
<li><a href="pyFTS/common/Membership.html">pyFTS.common.Membership</a></li>
<li><a href="pyFTS/common/SortedCollection.html">pyFTS.common.SortedCollection</a></li>
<li><a href="pyFTS/common/Util.html">pyFTS.common.Util</a></li>
<li><a href="pyFTS/common/flrg.html">pyFTS.common.flrg</a></li>
<li><a href="pyFTS/common/fts.html">pyFTS.common.fts</a></li>
<li><a href="pyFTS/common/tree.html">pyFTS.common.tree</a></li>
<li><a href="pyFTS/data/AirPassengers.html">pyFTS.data.AirPassengers</a></li>
<li><a href="pyFTS/data/Bitcoin.html">pyFTS.data.Bitcoin</a></li>
@ -83,27 +95,61 @@
<li><a href="pyFTS/data/mackey_glass.html">pyFTS.data.mackey_glass</a></li>
<li><a href="pyFTS/data/rossler.html">pyFTS.data.rossler</a></li>
<li><a href="pyFTS/data/sunspots.html">pyFTS.data.sunspots</a></li>
<li><a href="pyFTS/distributed/dispy.html">pyFTS.distributed.dispy</a></li>
<li><a href="pyFTS/hyperparam/Evolutionary.html">pyFTS.hyperparam.Evolutionary</a></li>
<li><a href="pyFTS/hyperparam/GridSearch.html">pyFTS.hyperparam.GridSearch</a></li>
<li><a href="pyFTS/hyperparam/Util.html">pyFTS.hyperparam.Util</a></li>
<li><a href="pyFTS/models/chen.html">pyFTS.models.chen</a></li>
<li><a href="pyFTS/models/cheng.html">pyFTS.models.cheng</a></li>
<li><a href="pyFTS/models/ensemble/ensemble.html">pyFTS.models.ensemble.ensemble</a></li>
<li><a href="pyFTS/models/ensemble/multiseasonal.html">pyFTS.models.ensemble.multiseasonal</a></li>
<li><a href="pyFTS/models/hofts.html">pyFTS.models.hofts</a></li>
<li><a href="pyFTS/models/hwang.html">pyFTS.models.hwang</a></li>
<li><a href="pyFTS/models/ifts.html">pyFTS.models.ifts</a></li>
<li><a href="pyFTS/models/incremental/IncrementalEnsemble.html">pyFTS.models.incremental.IncrementalEnsemble</a></li>
<li><a href="pyFTS/models/incremental/TimeVariant.html">pyFTS.models.incremental.TimeVariant</a></li>
<li><a href="pyFTS/models/ismailefendi.html">pyFTS.models.ismailefendi</a></li>
<li><a href="pyFTS/models/multivariate/FLR.html">pyFTS.models.multivariate.FLR</a></li>
<li><a href="pyFTS/models/multivariate/cmvfts.html">pyFTS.models.multivariate.cmvfts</a></li>
<li><a href="pyFTS/models/multivariate/common.html">pyFTS.models.multivariate.common</a></li>
<li><a href="pyFTS/models/multivariate/flrg.html">pyFTS.models.multivariate.flrg</a></li>
<li><a href="pyFTS/models/multivariate/granular.html">pyFTS.models.multivariate.granular</a></li>
<li><a href="pyFTS/models/multivariate/grid.html">pyFTS.models.multivariate.grid</a></li>
<li><a href="pyFTS/models/multivariate/mvfts.html">pyFTS.models.multivariate.mvfts</a></li>
<li><a href="pyFTS/models/multivariate/partitioner.html">pyFTS.models.multivariate.partitioner</a></li>
<li><a href="pyFTS/models/multivariate/variable.html">pyFTS.models.multivariate.variable</a></li>
<li><a href="pyFTS/models/multivariate/wmvfts.html">pyFTS.models.multivariate.wmvfts</a></li>
<li><a href="pyFTS/models/nonstationary/common.html">pyFTS.models.nonstationary.common</a></li>
<li><a href="pyFTS/models/nonstationary/cvfts.html">pyFTS.models.nonstationary.cvfts</a></li>
<li><a href="pyFTS/models/nonstationary/flrg.html">pyFTS.models.nonstationary.flrg</a></li>
<li><a href="pyFTS/models/nonstationary/honsfts.html">pyFTS.models.nonstationary.honsfts</a></li>
<li><a href="pyFTS/models/nonstationary/nsfts.html">pyFTS.models.nonstationary.nsfts</a></li>
<li><a href="pyFTS/models/nonstationary/partitioners.html">pyFTS.models.nonstationary.partitioners</a></li>
<li><a href="pyFTS/models/nonstationary/perturbation.html">pyFTS.models.nonstationary.perturbation</a></li>
<li><a href="pyFTS/models/nonstationary/util.html">pyFTS.models.nonstationary.util</a></li>
<li><a href="pyFTS/models/pwfts.html">pyFTS.models.pwfts</a></li>
<li><a href="pyFTS/models/sadaei.html">pyFTS.models.sadaei</a></li>
<li><a href="pyFTS/models/seasonal/SeasonalIndexer.html">pyFTS.models.seasonal.SeasonalIndexer</a></li>
<li><a href="pyFTS/models/seasonal/cmsfts.html">pyFTS.models.seasonal.cmsfts</a></li>
<li><a href="pyFTS/models/seasonal/common.html">pyFTS.models.seasonal.common</a></li>
<li><a href="pyFTS/models/seasonal/msfts.html">pyFTS.models.seasonal.msfts</a></li>
<li><a href="pyFTS/models/seasonal/partitioner.html">pyFTS.models.seasonal.partitioner</a></li>
<li><a href="pyFTS/models/seasonal/sfts.html">pyFTS.models.seasonal.sfts</a></li>
<li><a href="pyFTS/models/song.html">pyFTS.models.song</a></li>
<li><a href="pyFTS/models/yu.html">pyFTS.models.yu</a></li>
<li><a href="pyFTS/partitioners/CMeans.html">pyFTS.partitioners.CMeans</a></li>
<li><a href="pyFTS/partitioners/Entropy.html">pyFTS.partitioners.Entropy</a></li>
<li><a href="pyFTS/partitioners/FCM.html">pyFTS.partitioners.FCM</a></li>
<li><a href="pyFTS/partitioners/Grid.html">pyFTS.partitioners.Grid</a></li>
<li><a href="pyFTS/partitioners/Huarng.html">pyFTS.partitioners.Huarng</a></li>
<li><a href="pyFTS/partitioners/Simple.html">pyFTS.partitioners.Simple</a></li>
<li><a href="pyFTS/partitioners/Singleton.html">pyFTS.partitioners.Singleton</a></li>
<li><a href="pyFTS/partitioners/SubClust.html">pyFTS.partitioners.SubClust</a></li>
<li><a href="pyFTS/partitioners/Util.html">pyFTS.partitioners.Util</a></li>
<li><a href="pyFTS/partitioners/parallel_util.html">pyFTS.partitioners.parallel_util</a></li>
<li><a href="pyFTS/partitioners/partitioner.html">pyFTS.partitioners.partitioner</a></li>
<li><a href="pyFTS/probabilistic/ProbabilityDistribution.html">pyFTS.probabilistic.ProbabilityDistribution</a></li>
<li><a href="pyFTS/probabilistic/kde.html">pyFTS.probabilistic.kde</a></li>
</ul>
<div class="clearer"></div>

View File

@ -0,0 +1,220 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.benchmarks.BSTS &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.benchmarks.BSTS</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.benchmarks.BSTS</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/python</span>
<span class="c1"># -*- coding: utf8 -*-</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">import</span> <span class="nn">scipy.stats</span> <span class="k">as</span> <span class="nn">st</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">SortedCollection</span><span class="p">,</span> <span class="n">fts</span>
<span class="kn">from</span> <span class="nn">pyFTS.probabilistic</span> <span class="kn">import</span> <span class="n">ProbabilityDistribution</span>
<div class="viewcode-block" id="ARIMA"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.BSTS.ARIMA">[docs]</a><span class="k">class</span> <span class="nc">ARIMA</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Façade for statsmodels.tsa.arima_model</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">ARIMA</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;BSTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;Bayesian Structural Time Series&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_point_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_interval_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_probability_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">uod_clip</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model_fit</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">trained_data</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">p</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">d</span> <span class="o">=</span> <span class="mi">0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">q</span> <span class="o">=</span> <span class="mi">0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">benchmark_only</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_order</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">alpha</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;alpha&quot;</span><span class="p">,</span> <span class="mf">0.05</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</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;order&quot;</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</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="bp">self</span><span class="o">.</span><span class="n">_decompose_order</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">def</span> <span class="nf">_decompose_order</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">order</span><span class="p">):</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">order</span><span class="p">,</span> <span class="p">(</span><span class="nb">tuple</span><span class="p">,</span> <span class="nb">set</span><span class="p">,</span> <span class="nb">list</span><span class="p">)):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">p</span> <span class="o">=</span> <span class="n">order</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">d</span> <span class="o">=</span> <span class="n">order</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">q</span> <span class="o">=</span> <span class="n">order</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">q</span> <span class="o">+</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">q</span> <span class="o">-</span> <span class="mi">1</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">q</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span>
<span class="bp">self</span><span class="o">.</span><span class="n">d</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transformations</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;BSTS(</span><span class="si">{}</span><span class="s2">,</span><span class="si">{}</span><span class="s2">,</span><span class="si">{}</span><span class="s2">)-</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">d</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">q</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">alpha</span><span class="p">)</span>
<div class="viewcode-block" id="ARIMA.train"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.BSTS.ARIMA.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="kn">import</span> <span class="nn">pyflux</span> <span class="k">as</span> <span class="nn">pf</span>
<span class="k">if</span> <span class="s1">&#39;order&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="n">order</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;order&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_decompose_order</span><span class="p">(</span><span class="n">order</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">indexer</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">indexer</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="n">pf</span><span class="o">.</span><span class="n">ARIMA</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">ar</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">,</span> <span class="n">ma</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">q</span><span class="p">,</span> <span class="n">integ</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">d</span><span class="p">,</span> <span class="n">family</span><span class="o">=</span><span class="n">pf</span><span class="o">.</span><span class="n">Normal</span><span class="p">())</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model_fit</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="s1">&#39;M-H&#39;</span><span class="p">,</span> <span class="n">nsims</span><span class="o">=</span><span class="mi">20000</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="n">ex</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model_fit</span> <span class="o">=</span> <span class="kc">None</span></div>
<div class="viewcode-block" id="ARIMA.inference"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.BSTS.ARIMA.inference">[docs]</a> <span class="k">def</span> <span class="nf">inference</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">steps</span><span class="p">):</span>
<span class="n">t_z</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">transform_z</span><span class="p">()</span>
<span class="n">mu</span><span class="p">,</span> <span class="n">Y</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">_model</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">latent_variables</span><span class="o">.</span><span class="n">get_z_values</span><span class="p">())</span>
<span class="n">date_index</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">shift_dates</span><span class="p">(</span><span class="n">steps</span><span class="p">)</span>
<span class="n">sim_vector</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">_sim_prediction</span><span class="p">(</span><span class="n">mu</span><span class="p">,</span> <span class="n">Y</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="n">t_z</span><span class="p">,</span> <span class="mi">1000</span><span class="p">)</span>
<span class="k">return</span> <span class="n">sim_vector</span></div>
<div class="viewcode-block" id="ARIMA.forecast"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.BSTS.ARIMA.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">()</span></div>
<div class="viewcode-block" id="ARIMA.forecast_ahead"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.BSTS.ARIMA.forecast_ahead">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">steps</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="o">.</span><span class="n">values</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span></div>
<div class="viewcode-block" id="ARIMA.forecast_interval"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.BSTS.ARIMA.forecast_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">()</span></div>
<div class="viewcode-block" id="ARIMA.forecast_ahead_interval"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.BSTS.ARIMA.forecast_ahead_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">sim_vector</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">inference</span><span class="p">(</span><span class="n">steps</span><span class="p">)</span>
<span class="k">if</span> <span class="s1">&#39;alpha&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="n">alpha</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;alpha&#39;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">alpha</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">alpha</span>
<span class="n">ret</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">sample</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">sim_vector</span><span class="p">):</span>
<span class="n">i</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">percentile</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="p">[</span><span class="n">alpha</span><span class="o">*</span><span class="mi">100</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</span><span class="o">-</span><span class="n">alpha</span><span class="p">)</span><span class="o">*</span><span class="mi">100</span><span class="p">])</span><span class="o">.</span><span class="n">tolist</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">i</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="ARIMA.forecast_distribution"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.BSTS.ARIMA.forecast_distribution">[docs]</a> <span class="k">def</span> <span class="nf">forecast_distribution</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="kn">import</span> <span class="nn">pyflux</span> <span class="k">as</span> <span class="nn">pf</span>
<span class="n">sim_vector</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">inference</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="n">ret</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">sample</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">sim_vector</span><span class="p">):</span>
<span class="n">pd</span> <span class="o">=</span> <span class="n">ProbabilityDistribution</span><span class="o">.</span><span class="n">ProbabilityDistribution</span><span class="p">(</span><span class="nb">type</span><span class="o">=</span><span class="s1">&#39;histogram&#39;</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">sample</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">500</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">pd</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="ARIMA.forecast_ahead_distribution"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.BSTS.ARIMA.forecast_ahead_distribution">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_distribution</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">sim_vector</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">inference</span><span class="p">(</span><span class="n">steps</span><span class="p">)</span>
<span class="n">ret</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">sample</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">sim_vector</span><span class="p">):</span>
<span class="n">pd</span> <span class="o">=</span> <span class="n">ProbabilityDistribution</span><span class="o">.</span><span class="n">ProbabilityDistribution</span><span class="p">(</span><span class="nb">type</span><span class="o">=</span><span class="s1">&#39;histogram&#39;</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">sample</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">500</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">pd</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.benchmarks.BSTS</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,663 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.benchmarks.Measures &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.benchmarks.Measures</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.benchmarks.Measures</h1><div class="highlight"><pre>
<span></span><span class="c1"># -*- coding: utf8 -*-</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">pyFTS module for common benchmark metrics</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">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">SortedCollection</span>
<span class="kn">from</span> <span class="nn">pyFTS.probabilistic</span> <span class="kn">import</span> <span class="n">ProbabilityDistribution</span>
<div class="viewcode-block" id="acf"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.acf">[docs]</a><span class="k">def</span> <span class="nf">acf</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">k</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Autocorrelation function estimative</span>
<span class="sd"> :param data: </span>
<span class="sd"> :param k: </span>
<span class="sd"> :return: </span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">mu</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmean</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">sigma</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">n</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="n">s</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">t</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">n</span> <span class="o">-</span> <span class="n">k</span><span class="p">):</span>
<span class="n">s</span> <span class="o">+=</span> <span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">t</span><span class="p">]</span> <span class="o">-</span> <span class="n">mu</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">t</span> <span class="o">+</span> <span class="n">k</span><span class="p">]</span> <span class="o">-</span> <span class="n">mu</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span> <span class="o">/</span> <span class="p">((</span><span class="n">n</span> <span class="o">-</span> <span class="n">k</span><span class="p">)</span> <span class="o">*</span> <span class="n">sigma</span><span class="p">)</span> <span class="o">*</span> <span class="n">s</span></div>
<div class="viewcode-block" id="rmse"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.rmse">[docs]</a><span class="k">def</span> <span class="nf">rmse</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="n">forecasts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Root Mean Squared Error</span>
<span class="sd"> :param targets: </span>
<span class="sd"> :param forecasts: </span>
<span class="sd"> :return: </span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
<span class="n">targets</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="n">targets</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="nb">list</span><span class="p">):</span>
<span class="n">forecasts</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="n">forecasts</span><span class="p">)</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">nanmean</span><span class="p">((</span><span class="n">targets</span> <span class="o">-</span> <span class="n">forecasts</span><span class="p">)</span> <span class="o">**</span> <span class="mi">2</span><span class="p">))</span></div>
<div class="viewcode-block" id="rmse_interval"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.rmse_interval">[docs]</a><span class="k">def</span> <span class="nf">rmse_interval</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="n">forecasts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Root Mean Squared Error</span>
<span class="sd"> :param targets: </span>
<span class="sd"> :param forecasts: </span>
<span class="sd"> :return: </span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">fmean</span> <span class="o">=</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">forecasts</span><span class="p">]</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">nanmean</span><span class="p">((</span><span class="n">fmean</span> <span class="o">-</span> <span class="n">targets</span><span class="p">)</span> <span class="o">**</span> <span class="mi">2</span><span class="p">))</span></div>
<div class="viewcode-block" id="mape"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.mape">[docs]</a><span class="k">def</span> <span class="nf">mape</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="n">forecasts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Mean Average Percentual Error</span>
<span class="sd"> :param targets: </span>
<span class="sd"> :param forecasts: </span>
<span class="sd"> :return: </span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
<span class="n">targets</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="n">targets</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="nb">list</span><span class="p">):</span>
<span class="n">forecasts</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="n">forecasts</span><span class="p">)</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmean</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">divide</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">subtract</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="n">forecasts</span><span class="p">),</span> <span class="n">targets</span><span class="p">)))</span> <span class="o">*</span> <span class="mi">100</span></div>
<div class="viewcode-block" id="smape"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.smape">[docs]</a><span class="k">def</span> <span class="nf">smape</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="n">forecasts</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="mi">2</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Symmetric Mean Average Percentual Error</span>
<span class="sd"> :param targets: </span>
<span class="sd"> :param forecasts: </span>
<span class="sd"> :param type: </span>
<span class="sd"> :return: </span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
<span class="n">targets</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="n">targets</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="nb">list</span><span class="p">):</span>
<span class="n">forecasts</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="n">forecasts</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">type</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmean</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">forecasts</span> <span class="o">-</span> <span class="n">targets</span><span class="p">)</span> <span class="o">/</span> <span class="p">((</span><span class="n">forecasts</span> <span class="o">+</span> <span class="n">targets</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">))</span>
<span class="k">elif</span> <span class="nb">type</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmean</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">forecasts</span> <span class="o">-</span> <span class="n">targets</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span> <span class="o">+</span> <span class="nb">abs</span><span class="p">(</span><span class="n">targets</span><span class="p">)))</span> <span class="o">*</span> <span class="mi">100</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">forecasts</span> <span class="o">-</span> <span class="n">targets</span><span class="p">))</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">forecasts</span> <span class="o">+</span> <span class="n">targets</span><span class="p">)</span></div>
<div class="viewcode-block" id="mape_interval"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.mape_interval">[docs]</a><span class="k">def</span> <span class="nf">mape_interval</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="n">forecasts</span><span class="p">):</span>
<span class="n">fmean</span> <span class="o">=</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">forecasts</span><span class="p">]</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">fmean</span> <span class="o">-</span> <span class="n">targets</span><span class="p">)</span> <span class="o">/</span> <span class="n">fmean</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span></div>
<div class="viewcode-block" id="UStatistic"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.UStatistic">[docs]</a><span class="k">def</span> <span class="nf">UStatistic</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="n">forecasts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Theil&#39;s U Statistic</span>
<span class="sd"> :param targets: </span>
<span class="sd"> :param forecasts: </span>
<span class="sd"> :return: </span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">forecasts</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</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">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">forecasts</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">forecasts</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="n">forecasts</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</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">targets</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="n">targets</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">targets</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="n">targets</span><span class="p">)</span>
<span class="n">l</span> <span class="o">=</span> <span class="n">forecasts</span><span class="o">.</span><span class="n">size</span>
<span class="n">l</span> <span class="o">=</span> <span class="mi">2</span> <span class="k">if</span> <span class="n">l</span> <span class="o">==</span> <span class="mi">1</span> <span class="k">else</span> <span class="n">l</span>
<span class="n">naive</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">y</span> <span class="o">=</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="o">-</span> <span class="mi">1</span><span class="p">):</span>
<span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">subtract</span><span class="p">(</span><span class="n">forecasts</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">targets</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span>
<span class="n">naive</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">subtract</span><span class="p">(</span><span class="n">targets</span><span class="p">[</span><span class="n">k</span> <span class="o">+</span> <span class="mi">1</span><span class="p">],</span> <span class="n">targets</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">divide</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">y</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">naive</span><span class="p">)))</span></div>
<div class="viewcode-block" id="TheilsInequality"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.TheilsInequality">[docs]</a><span class="k">def</span> <span class="nf">TheilsInequality</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="n">forecasts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Theils Inequality Coefficient</span>
<span class="sd"> :param targets: </span>
<span class="sd"> :param forecasts: </span>
<span class="sd"> :return: </span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">res</span> <span class="o">=</span> <span class="n">targets</span> <span class="o">-</span> <span class="n">forecasts</span>
<span class="n">t</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
<span class="n">us</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">([</span><span class="n">u</span> <span class="o">**</span> <span class="mi">2</span> <span class="k">for</span> <span class="n">u</span> <span class="ow">in</span> <span class="n">res</span><span class="p">]))</span>
<span class="n">ys</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">([</span><span class="n">y</span> <span class="o">**</span> <span class="mi">2</span> <span class="k">for</span> <span class="n">y</span> <span class="ow">in</span> <span class="n">targets</span><span class="p">]))</span>
<span class="n">fs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">([</span><span class="n">f</span> <span class="o">**</span> <span class="mi">2</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">forecasts</span><span class="p">]))</span>
<span class="k">return</span> <span class="n">us</span> <span class="o">/</span> <span class="p">(</span><span class="n">ys</span> <span class="o">+</span> <span class="n">fs</span><span class="p">)</span></div>
<div class="viewcode-block" id="sharpness"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.sharpness">[docs]</a><span class="k">def</span> <span class="nf">sharpness</span><span class="p">(</span><span class="n">forecasts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Sharpness - Mean size of the intervals&quot;&quot;&quot;</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">i</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">forecasts</span><span class="p">]</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span></div>
<div class="viewcode-block" id="resolution"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.resolution">[docs]</a><span class="k">def</span> <span class="nf">resolution</span><span class="p">(</span><span class="n">forecasts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Resolution - Standard deviation of the intervals&quot;&quot;&quot;</span>
<span class="n">shp</span> <span class="o">=</span> <span class="n">sharpness</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="p">[</span><span class="nb">abs</span><span class="p">((</span><span class="n">i</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">i</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">-</span> <span class="n">shp</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">forecasts</span><span class="p">]</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span></div>
<div class="viewcode-block" id="coverage"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.coverage">[docs]</a><span class="k">def</span> <span class="nf">coverage</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="n">forecasts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Percent of target values that fall inside forecasted interval&quot;&quot;&quot;</span>
<span class="n">preds</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">i</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="nb">len</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)):</span>
<span class="k">if</span> <span class="n">targets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&gt;=</span> <span class="n">forecasts</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="ow">and</span> <span class="n">targets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">forecasts</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">1</span><span class="p">]:</span>
<span class="n">preds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">preds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmean</span><span class="p">(</span><span class="n">preds</span><span class="p">)</span></div>
<div class="viewcode-block" id="pinball"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.pinball">[docs]</a><span class="k">def</span> <span class="nf">pinball</span><span class="p">(</span><span class="n">tau</span><span class="p">,</span> <span class="n">target</span><span class="p">,</span> <span class="n">forecast</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Pinball loss function. Measure the distance of forecast to the tau-quantile of the target</span>
<span class="sd"> :param tau: quantile value in the range (0,1)</span>
<span class="sd"> :param target: </span>
<span class="sd"> :param forecast: </span>
<span class="sd"> :return: float, distance of forecast to the tau-quantile of the target</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">target</span> <span class="o">&gt;=</span> <span class="n">forecast</span><span class="p">:</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">subtract</span><span class="p">(</span><span class="n">target</span><span class="p">,</span> <span class="n">forecast</span><span class="p">)</span> <span class="o">*</span> <span class="n">tau</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">subtract</span><span class="p">(</span><span class="n">forecast</span><span class="p">,</span> <span class="n">target</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">tau</span><span class="p">)</span></div>
<div class="viewcode-block" id="pinball_mean"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.pinball_mean">[docs]</a><span class="k">def</span> <span class="nf">pinball_mean</span><span class="p">(</span><span class="n">tau</span><span class="p">,</span> <span class="n">targets</span><span class="p">,</span> <span class="n">forecasts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Mean pinball loss value of the forecast for a given tau-quantile of the targets</span>
<span class="sd"> :param tau: quantile value in the range (0,1)</span>
<span class="sd"> :param targets: list of target values</span>
<span class="sd"> :param forecasts: list of prediction intervals</span>
<span class="sd"> :return: float, the pinball loss mean for tau quantile</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">tau</span> <span class="o">&lt;=</span> <span class="mf">0.5</span><span class="p">:</span>
<span class="n">preds</span> <span class="o">=</span> <span class="p">[</span><span class="n">pinball</span><span class="p">(</span><span class="n">tau</span><span class="p">,</span> <span class="n">targets</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">forecasts</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="k">for</span> <span class="n">i</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="nb">len</span><span class="p">(</span><span class="n">forecasts</span><span class="p">))]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">preds</span> <span class="o">=</span> <span class="p">[</span><span class="n">pinball</span><span class="p">(</span><span class="n">tau</span><span class="p">,</span> <span class="n">targets</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">forecasts</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="k">for</span> <span class="n">i</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="nb">len</span><span class="p">(</span><span class="n">forecasts</span><span class="p">))]</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmean</span><span class="p">(</span><span class="n">preds</span><span class="p">)</span></div>
<div class="viewcode-block" id="winkler_score"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.winkler_score">[docs]</a><span class="k">def</span> <span class="nf">winkler_score</span><span class="p">(</span><span class="n">tau</span><span class="p">,</span> <span class="n">target</span><span class="p">,</span> <span class="n">forecast</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> R. L. Winkler, A Decision-Theoretic Approach to Interval Estimation, J. Am. Stat. Assoc. 67 (337) (1972) 187191. doi:10.2307/2284720.</span>
<span class="sd"> :param tau:</span>
<span class="sd"> :param target:</span>
<span class="sd"> :param forecast:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">delta</span> <span class="o">=</span> <span class="n">forecast</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">forecast</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">if</span> <span class="n">forecast</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">target</span> <span class="o">&lt;=</span> <span class="n">forecast</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span>
<span class="k">return</span> <span class="n">delta</span>
<span class="k">elif</span> <span class="n">forecast</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">target</span><span class="p">:</span>
<span class="k">return</span> <span class="n">delta</span> <span class="o">+</span> <span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="p">(</span><span class="n">forecast</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">target</span><span class="p">))</span> <span class="o">/</span> <span class="n">tau</span>
<span class="k">elif</span> <span class="n">forecast</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">target</span><span class="p">:</span>
<span class="k">return</span> <span class="n">delta</span> <span class="o">+</span> <span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="p">(</span><span class="n">target</span> <span class="o">-</span> <span class="n">forecast</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span> <span class="o">/</span> <span class="n">tau</span></div>
<div class="viewcode-block" id="winkler_mean"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.winkler_mean">[docs]</a><span class="k">def</span> <span class="nf">winkler_mean</span><span class="p">(</span><span class="n">tau</span><span class="p">,</span> <span class="n">targets</span><span class="p">,</span> <span class="n">forecasts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Mean Winkler score value of the forecast for a given tau-quantile of the targets</span>
<span class="sd"> :param tau: quantile value in the range (0,1)</span>
<span class="sd"> :param targets: list of target values</span>
<span class="sd"> :param forecasts: list of prediction intervals</span>
<span class="sd"> :return: float, the Winkler score mean for tau quantile</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">preds</span> <span class="o">=</span> <span class="p">[</span><span class="n">winkler_score</span><span class="p">(</span><span class="n">tau</span><span class="p">,</span> <span class="n">targets</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">forecasts</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="k">for</span> <span class="n">i</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="nb">len</span><span class="p">(</span><span class="n">forecasts</span><span class="p">))]</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmean</span><span class="p">(</span><span class="n">preds</span><span class="p">)</span></div>
<div class="viewcode-block" id="brier_score"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.brier_score">[docs]</a><span class="k">def</span> <span class="nf">brier_score</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="n">densities</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Brier Score for probabilistic forecasts.</span>
<span class="sd"> Brier (1950). &quot;Verification of Forecasts Expressed in Terms of Probability&quot;. Monthly Weather Review. 78: 13.</span>
<span class="sd"> :param targets: a list with the target values</span>
<span class="sd"> :param densities: a list with pyFTS.probabil objectsistic.ProbabilityDistribution</span>
<span class="sd"> :return: float</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">densities</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
<span class="n">densities</span> <span class="o">=</span> <span class="p">[</span><span class="n">densities</span><span class="p">]</span>
<span class="n">targets</span> <span class="o">=</span> <span class="p">[</span><span class="n">targets</span><span class="p">]</span>
<span class="n">ret</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">d</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">densities</span><span class="p">):</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">v</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">bin_index</span><span class="o">.</span><span class="n">find_le</span><span class="p">(</span><span class="n">targets</span><span class="p">[</span><span class="n">ct</span><span class="p">])</span>
<span class="n">score</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">([</span><span class="n">d</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="o">**</span> <span class="mi">2</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">bins</span> <span class="k">if</span> <span class="n">k</span> <span class="o">!=</span> <span class="n">v</span><span class="p">])</span>
<span class="n">score</span> <span class="o">+=</span> <span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">**</span> <span class="mi">2</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">score</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="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">([</span><span class="n">d</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="o">**</span> <span class="mi">2</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">bins</span><span class="p">]))</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span></div>
<div class="viewcode-block" id="logarithm_score"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.logarithm_score">[docs]</a><span class="k">def</span> <span class="nf">logarithm_score</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="n">densities</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Logarithm Score for probabilistic forecasts.</span>
<span class="sd"> Good IJ (1952). “Rational Decisions.”Journal of the Royal Statistical Society B,14(1),107114. URLhttps://www.jstor.org/stable/2984087.</span>
<span class="sd"> :param targets: a list with the target values</span>
<span class="sd"> :param densities: a list with pyFTS.probabil objectsistic.ProbabilityDistribution</span>
<span class="sd"> :return: float</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">_ls</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">densities</span><span class="p">,</span> <span class="n">ProbabilityDistribution</span><span class="o">.</span><span class="n">ProbabilityDistribution</span><span class="p">):</span>
<span class="n">densities</span> <span class="o">=</span> <span class="p">[</span><span class="n">densities</span><span class="p">]</span>
<span class="n">targets</span> <span class="o">=</span> <span class="p">[</span><span class="n">targets</span><span class="p">]</span>
<span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">densities</span><span class="p">)</span>
<span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">df</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">densities</span><span class="p">):</span>
<span class="n">_ls</span> <span class="o">+=</span> <span class="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">df</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">targets</span><span class="p">[</span><span class="n">ct</span><span class="p">]))</span>
<span class="k">return</span> <span class="n">_ls</span> <span class="o">/</span> <span class="n">n</span></div>
<div class="viewcode-block" id="crps"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.crps">[docs]</a><span class="k">def</span> <span class="nf">crps</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="n">densities</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Continuous Ranked Probability Score</span>
<span class="sd"> :param targets: a list with the target values</span>
<span class="sd"> :param densities: a list with pyFTS.probabil objectsistic.ProbabilityDistribution</span>
<span class="sd"> :return: float</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">_crps</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">densities</span><span class="p">,</span> <span class="n">ProbabilityDistribution</span><span class="o">.</span><span class="n">ProbabilityDistribution</span><span class="p">):</span>
<span class="n">densities</span> <span class="o">=</span> <span class="p">[</span><span class="n">densities</span><span class="p">]</span>
<span class="n">targets</span> <span class="o">=</span> <span class="p">[</span><span class="n">targets</span><span class="p">]</span>
<span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">densities</span><span class="p">)</span>
<span class="k">if</span> <span class="n">n</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>
<span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">df</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">densities</span><span class="p">):</span>
<span class="n">_crps</span> <span class="o">+=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">([(</span><span class="n">df</span><span class="o">.</span><span class="n">cumulative</span><span class="p">(</span><span class="nb">bin</span><span class="p">)</span> <span class="o">-</span> <span class="p">(</span><span class="mi">1</span> <span class="k">if</span> <span class="nb">bin</span> <span class="o">&gt;=</span> <span class="n">targets</span><span class="p">[</span><span class="n">ct</span><span class="p">]</span> <span class="k">else</span> <span class="mi">0</span><span class="p">))</span> <span class="o">**</span> <span class="mi">2</span> <span class="k">for</span> <span class="nb">bin</span> <span class="ow">in</span> <span class="n">df</span><span class="o">.</span><span class="n">bins</span><span class="p">])</span>
<span class="k">return</span> <span class="n">_crps</span> <span class="o">/</span> <span class="n">n</span></div>
<div class="viewcode-block" id="get_point_statistics"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.get_point_statistics">[docs]</a><span class="k">def</span> <span class="nf">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="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Condensate all measures for point forecasters</span>
<span class="sd"> :param data: test data</span>
<span class="sd"> :param model: FTS model with point forecasting capability</span>
<span class="sd"> :param kwargs:</span>
<span class="sd"> :return: a list with the RMSE, SMAPE and U Statistic</span>
<span class="sd"> &quot;&quot;&quot;</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">kwargs</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;point&#39;</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="k">if</span> <span class="n">indexer</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">ndata</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="n">indexer</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">data</span><span class="p">))</span>
<span class="k">elif</span> <span class="n">model</span><span class="o">.</span><span class="n">is_multivariate</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">):</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Multivariate data must be a Pandas DataFrame!&quot;</span><span class="p">)</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="n">data</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ndata</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="n">data</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
<span class="k">if</span> <span class="n">steps_ahead</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">forecasts</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">ndata</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">model</span><span class="o">.</span><span class="n">is_multivariate</span> <span class="ow">and</span> <span class="n">model</span><span class="o">.</span><span class="n">has_seasonality</span><span class="p">:</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">indexer</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">ndata</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">model</span><span class="o">.</span><span class="n">is_multivariate</span><span class="p">:</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="n">ndata</span><span class="p">[</span><span class="n">model</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span><span class="o">.</span><span class="n">values</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">forecasts</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</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="p">[</span><span class="n">forecasts</span><span class="p">]</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">ndata</span><span class="p">)</span> <span class="o">-</span> <span class="n">model</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span>
<span class="n">forecasts</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="n">forecasts</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">forecasts</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="n">forecasts</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">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">rmse</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">model</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="n">forecasts</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="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">mape</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">model</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="n">forecasts</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="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">UStatistic</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">model</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="n">forecasts</span><span class="p">),</span> <span class="mi">2</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">steps_ahead_sampler</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_sampler&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">nforecasts</span> <span class="o">=</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="n">model</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">ndata</span><span class="p">)</span> <span class="o">-</span> <span class="n">steps_ahead</span><span class="p">,</span> <span class="n">steps_ahead_sampler</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">ndata</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="n">model</span><span class="o">.</span><span class="n">order</span><span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">nforecasts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="n">start</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">+</span> <span class="n">steps_ahead</span> <span class="o">-</span> <span class="mi">1</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">rmse</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">:</span><span class="n">steps_ahead_sampler</span><span class="p">],</span> <span class="n">nforecasts</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="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">mape</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">:</span><span class="n">steps_ahead_sampler</span><span class="p">],</span> <span class="n">nforecasts</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="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">UStatistic</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">:</span><span class="n">steps_ahead_sampler</span><span class="p">],</span> <span class="n">nforecasts</span><span class="p">),</span> <span class="mi">2</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="get_point_ahead_statistics"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.get_point_ahead_statistics">[docs]</a><span class="k">def</span> <span class="nf">get_point_ahead_statistics</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">forecasts</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"> Condensate all measures for point forecasters</span>
<span class="sd"> :param data: test data</span>
<span class="sd"> :param model: FTS model with point forecasting capability</span>
<span class="sd"> :param kwargs:</span>
<span class="sd"> :return: a list with the RMSE, SMAPE and U Statistic</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">l</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span>
<span class="k">if</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="n">l</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;Data and intervals have different lenghts!&quot;</span><span class="p">)</span>
<span class="n">lags</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">lag</span> <span class="ow">in</span> <span class="nb">range</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="p">{}</span>
<span class="n">datum</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">lag</span><span class="p">]</span>
<span class="n">forecast</span> <span class="o">=</span> <span class="n">forecasts</span><span class="p">[</span><span class="n">lag</span><span class="p">]</span>
<span class="n">ret</span><span class="p">[</span><span class="s1">&#39;steps&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">lag</span>
<span class="n">ret</span><span class="p">[</span><span class="s1">&#39;method&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
<span class="n">ret</span><span class="p">[</span><span class="s1">&#39;rmse&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">rmse</span><span class="p">(</span><span class="n">datum</span><span class="p">,</span> <span class="n">forecast</span><span class="p">)</span>
<span class="n">ret</span><span class="p">[</span><span class="s1">&#39;mape&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">mape</span><span class="p">(</span><span class="n">datum</span><span class="p">,</span> <span class="n">forecast</span><span class="p">)</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">lag</span><span class="o">-</span><span class="mi">1</span><span class="p">:</span><span class="n">lag</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="k">if</span> <span class="n">lag</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="p">[</span><span class="n">datum</span><span class="p">,</span> <span class="n">datum</span><span class="p">]</span>
<span class="n">ret</span><span class="p">[</span><span class="s1">&#39;u&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">UStatistic</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">forecast</span><span class="p">)</span>
<span class="n">lags</span><span class="p">[</span><span class="n">lag</span><span class="p">]</span> <span class="o">=</span> <span class="n">ret</span>
<span class="k">return</span> <span class="n">lags</span></div>
<div class="viewcode-block" id="get_interval_statistics"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.get_interval_statistics">[docs]</a><span class="k">def</span> <span class="nf">get_interval_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="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Condensate all measures for point interval forecasters</span>
<span class="sd"> :param data: test data</span>
<span class="sd"> :param model: FTS model with interval forecasting capability</span>
<span class="sd"> :param kwargs:</span>
<span class="sd"> :return: a list with the sharpness, resolution, coverage, .05 pinball mean,</span>
<span class="sd"> .25 pinball mean, .75 pinball mean and .95 pinball mean.</span>
<span class="sd"> &quot;&quot;&quot;</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">kwargs</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;interval&#39;</span>
<span class="n">ret</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
<span class="k">if</span> <span class="n">steps_ahead</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">forecasts</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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="nb">round</span><span class="p">(</span><span class="n">sharpness</span><span class="p">(</span><span class="n">forecasts</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="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">resolution</span><span class="p">(</span><span class="n">forecasts</span><span class="p">),</span> <span class="mi">2</span><span class="p">))</span>
<span class="k">if</span> <span class="n">model</span><span class="o">.</span><span class="n">is_multivariate</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">model</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span><span class="o">.</span><span class="n">values</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">coverage</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">model</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="n">forecasts</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="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">pinball_mean</span><span class="p">(</span><span class="mf">0.05</span><span class="p">,</span> <span class="n">data</span><span class="p">[</span><span class="n">model</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="n">forecasts</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="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">pinball_mean</span><span class="p">(</span><span class="mf">0.25</span><span class="p">,</span> <span class="n">data</span><span class="p">[</span><span class="n">model</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="n">forecasts</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="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">pinball_mean</span><span class="p">(</span><span class="mf">0.75</span><span class="p">,</span> <span class="n">data</span><span class="p">[</span><span class="n">model</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="n">forecasts</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="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">pinball_mean</span><span class="p">(</span><span class="mf">0.95</span><span class="p">,</span> <span class="n">data</span><span class="p">[</span><span class="n">model</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="n">forecasts</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="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">winkler_mean</span><span class="p">(</span><span class="mf">0.05</span><span class="p">,</span> <span class="n">data</span><span class="p">[</span><span class="n">model</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="n">forecasts</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="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">winkler_mean</span><span class="p">(</span><span class="mf">0.25</span><span class="p">,</span> <span class="n">data</span><span class="p">[</span><span class="n">model</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="n">forecasts</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="k">else</span><span class="p">:</span>
<span class="n">forecasts</span> <span class="o">=</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="n">model</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">data</span><span class="p">)</span> <span class="o">-</span> <span class="n">steps_ahead</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="n">model</span><span class="o">.</span><span class="n">order</span><span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">forecasts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="n">start</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">+</span> <span class="n">steps_ahead</span> <span class="o">-</span> <span class="mi">1</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">sharpness</span><span class="p">(</span><span class="n">forecasts</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="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">resolution</span><span class="p">(</span><span class="n">forecasts</span><span class="p">),</span> <span class="mi">2</span><span class="p">))</span>
<span class="k">if</span> <span class="n">model</span><span class="o">.</span><span class="n">is_multivariate</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">model</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span><span class="o">.</span><span class="n">values</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">coverage</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">model</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="n">forecasts</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="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">pinball_mean</span><span class="p">(</span><span class="mf">0.05</span><span class="p">,</span> <span class="n">data</span><span class="p">[</span><span class="n">start</span><span class="p">:],</span> <span class="n">forecasts</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="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">pinball_mean</span><span class="p">(</span><span class="mf">0.25</span><span class="p">,</span> <span class="n">data</span><span class="p">[</span><span class="n">start</span><span class="p">:],</span> <span class="n">forecasts</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="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">pinball_mean</span><span class="p">(</span><span class="mf">0.75</span><span class="p">,</span> <span class="n">data</span><span class="p">[</span><span class="n">start</span><span class="p">:],</span> <span class="n">forecasts</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="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">pinball_mean</span><span class="p">(</span><span class="mf">0.95</span><span class="p">,</span> <span class="n">data</span><span class="p">[</span><span class="n">start</span><span class="p">:],</span> <span class="n">forecasts</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="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">winkler_mean</span><span class="p">(</span><span class="mf">0.05</span><span class="p">,</span> <span class="n">data</span><span class="p">[</span><span class="n">start</span><span class="p">:],</span> <span class="n">forecasts</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="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">winkler_mean</span><span class="p">(</span><span class="mf">0.25</span><span class="p">,</span> <span class="n">data</span><span class="p">[</span><span class="n">start</span><span class="p">:],</span> <span class="n">forecasts</span><span class="p">),</span> <span class="mi">2</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="get_interval_ahead_statistics"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.get_interval_ahead_statistics">[docs]</a><span class="k">def</span> <span class="nf">get_interval_ahead_statistics</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">intervals</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"> Condensate all measures for point interval forecasters</span>
<span class="sd"> :param data: test data</span>
<span class="sd"> :param intervals: predicted intervals for each datapoint</span>
<span class="sd"> :param kwargs:</span>
<span class="sd"> :return: a list with the sharpness, resolution, coverage, .05 pinball mean,</span>
<span class="sd"> .25 pinball mean, .75 pinball mean and .95 pinball mean.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">l</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">intervals</span><span class="p">)</span>
<span class="k">if</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="n">l</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;Data and intervals have different lenghts!&quot;</span><span class="p">)</span>
<span class="n">lags</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">lag</span> <span class="ow">in</span> <span class="nb">range</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="p">{}</span>
<span class="n">datum</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">lag</span><span class="p">]</span>
<span class="n">interval</span> <span class="o">=</span> <span class="n">intervals</span><span class="p">[</span><span class="n">lag</span><span class="p">]</span>
<span class="n">ret</span><span class="p">[</span><span class="s1">&#39;steps&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">lag</span>
<span class="n">ret</span><span class="p">[</span><span class="s1">&#39;method&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
<span class="n">ret</span><span class="p">[</span><span class="s1">&#39;sharpness&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">interval</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">interval</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mi">2</span><span class="p">)</span>
<span class="n">ret</span><span class="p">[</span><span class="s1">&#39;coverage&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">if</span> <span class="n">interval</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">datum</span> <span class="o">&lt;=</span> <span class="n">interval</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">else</span> <span class="mi">0</span>
<span class="n">ret</span><span class="p">[</span><span class="s1">&#39;pinball05&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">pinball</span><span class="p">(</span><span class="mf">0.05</span><span class="p">,</span> <span class="n">datum</span><span class="p">,</span> <span class="n">interval</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="mi">2</span><span class="p">)</span>
<span class="n">ret</span><span class="p">[</span><span class="s1">&#39;pinball25&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">pinball</span><span class="p">(</span><span class="mf">0.25</span><span class="p">,</span> <span class="n">datum</span><span class="p">,</span> <span class="n">interval</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="mi">2</span><span class="p">)</span>
<span class="n">ret</span><span class="p">[</span><span class="s1">&#39;pinball75&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">pinball</span><span class="p">(</span><span class="mf">0.75</span><span class="p">,</span> <span class="n">datum</span><span class="p">,</span> <span class="n">interval</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="n">ret</span><span class="p">[</span><span class="s1">&#39;pinball95&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">pinball</span><span class="p">(</span><span class="mf">0.95</span><span class="p">,</span> <span class="n">datum</span><span class="p">,</span> <span class="n">interval</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="n">ret</span><span class="p">[</span><span class="s1">&#39;winkler05&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">winkler_score</span><span class="p">(</span><span class="mf">0.05</span><span class="p">,</span> <span class="n">datum</span><span class="p">,</span> <span class="n">interval</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span>
<span class="n">ret</span><span class="p">[</span><span class="s1">&#39;winkler25&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">winkler_score</span><span class="p">(</span><span class="mf">0.25</span><span class="p">,</span> <span class="n">datum</span><span class="p">,</span> <span class="n">interval</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span>
<span class="n">lags</span><span class="p">[</span><span class="n">lag</span><span class="p">]</span> <span class="o">=</span> <span class="n">ret</span>
<span class="k">return</span> <span class="n">lags</span></div>
<div class="viewcode-block" id="get_distribution_statistics"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.get_distribution_statistics">[docs]</a><span class="k">def</span> <span class="nf">get_distribution_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="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Get CRPS statistic and time for a forecasting model</span>
<span class="sd"> :param data: test data</span>
<span class="sd"> :param model: FTS model with probabilistic forecasting capability</span>
<span class="sd"> :param kwargs:</span>
<span class="sd"> :return: a list with the CRPS and execution time</span>
<span class="sd"> &quot;&quot;&quot;</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">kwargs</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;distribution&#39;</span>
<span class="n">ret</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
<span class="k">if</span> <span class="n">steps_ahead</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">_s1</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">forecasts</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">_e1</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="k">if</span> <span class="n">model</span><span class="o">.</span><span class="n">is_multivariate</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">model</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span><span class="o">.</span><span class="n">values</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">crps</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">model</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="n">forecasts</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]),</span> <span class="mi">3</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="nb">round</span><span class="p">(</span><span class="n">_e1</span> <span class="o">-</span> <span class="n">_s1</span><span class="p">,</span> <span class="mi">3</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="nb">round</span><span class="p">(</span><span class="n">brier_score</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">model</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="n">forecasts</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]),</span> <span class="mi">3</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">skip</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_sampler&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">forecasts</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">_s1</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="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="n">model</span><span class="o">.</span><span class="n">max_lag</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="o">-</span> <span class="n">steps_ahead</span><span class="p">,</span> <span class="n">skip</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="n">model</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">forecasts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="n">_e1</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">start</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">+</span> <span class="n">steps_ahead</span>
<span class="k">if</span> <span class="n">model</span><span class="o">.</span><span class="n">is_multivariate</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">model</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span><span class="o">.</span><span class="n">values</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">crps</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">:</span><span class="n">skip</span><span class="p">],</span> <span class="n">forecasts</span><span class="p">),</span> <span class="mi">3</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="nb">round</span><span class="p">(</span><span class="n">_e1</span> <span class="o">-</span> <span class="n">_s1</span><span class="p">,</span> <span class="mi">3</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="nb">round</span><span class="p">(</span><span class="n">brier_score</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">:</span><span class="n">skip</span><span class="p">],</span> <span class="n">forecasts</span><span class="p">),</span> <span class="mi">3</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="get_distribution_ahead_statistics"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.get_distribution_ahead_statistics">[docs]</a><span class="k">def</span> <span class="nf">get_distribution_ahead_statistics</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">distributions</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Get CRPS statistic and time for a forecasting model</span>
<span class="sd"> :param data: test data</span>
<span class="sd"> :param model: FTS model with probabilistic forecasting capability</span>
<span class="sd"> :param kwargs:</span>
<span class="sd"> :return: a list with the CRPS and execution time</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">l</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">distributions</span><span class="p">)</span>
<span class="k">if</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="n">l</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;Data and distributions have different lenghts!&quot;</span><span class="p">)</span>
<span class="n">lags</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">lag</span> <span class="ow">in</span> <span class="nb">range</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="p">{}</span>
<span class="n">datum</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">lag</span><span class="p">]</span>
<span class="n">dist</span> <span class="o">=</span> <span class="n">distributions</span><span class="p">[</span><span class="n">lag</span><span class="p">]</span>
<span class="n">ret</span><span class="p">[</span><span class="s1">&#39;steps&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">lag</span>
<span class="n">ret</span><span class="p">[</span><span class="s1">&#39;method&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
<span class="n">ret</span><span class="p">[</span><span class="s1">&#39;crps&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">crps</span><span class="p">(</span><span class="n">datum</span><span class="p">,</span> <span class="n">dist</span><span class="p">),</span> <span class="mi">3</span><span class="p">)</span>
<span class="n">ret</span><span class="p">[</span><span class="s1">&#39;brier&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">brier_score</span><span class="p">(</span><span class="n">datum</span><span class="p">,</span> <span class="n">dist</span><span class="p">),</span> <span class="mi">3</span><span class="p">)</span>
<span class="n">ret</span><span class="p">[</span><span class="s1">&#39;log&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">logarithm_score</span><span class="p">(</span><span class="n">datum</span><span class="p">,</span> <span class="n">dist</span><span class="p">),</span> <span class="mi">3</span><span class="p">)</span>
<span class="n">lags</span><span class="p">[</span><span class="n">lag</span><span class="p">]</span> <span class="o">=</span> <span class="n">ret</span>
<span class="k">return</span> <span class="n">lags</span></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.benchmarks.Measures</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,221 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.benchmarks.ResidualAnalysis &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.benchmarks.ResidualAnalysis</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.benchmarks.ResidualAnalysis</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;Residual Analysis methods&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</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.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">Transformations</span><span class="p">,</span><span class="n">Util</span>
<span class="kn">from</span> <span class="nn">pyFTS.benchmarks</span> <span class="kn">import</span> <span class="n">Measures</span>
<span class="kn">from</span> <span class="nn">scipy</span> <span class="kn">import</span> <span class="n">stats</span>
<div class="viewcode-block" id="residuals"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.ResidualAnalysis.residuals">[docs]</a><span class="k">def</span> <span class="nf">residuals</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="n">forecasts</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="sd">&quot;&quot;&quot;First order residuals&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">targets</span><span class="p">[</span><span class="n">order</span><span class="p">:])</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="n">forecasts</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span></div>
<div class="viewcode-block" id="ljung_box_test"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.ResidualAnalysis.ljung_box_test">[docs]</a><span class="k">def</span> <span class="nf">ljung_box_test</span><span class="p">(</span><span class="n">residuals</span><span class="p">,</span> <span class="n">lags</span><span class="o">=</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">alpha</span><span class="o">=</span><span class="mf">0.5</span><span class="p">):</span>
<span class="kn">from</span> <span class="nn">statsmodels.stats.diagnostic</span> <span class="kn">import</span> <span class="n">acorr_ljungbox</span>
<span class="kn">from</span> <span class="nn">scipy.stats</span> <span class="kn">import</span> <span class="n">chi2</span>
<span class="n">stat</span><span class="p">,</span> <span class="n">pval</span> <span class="o">=</span> <span class="n">acorr_ljungbox</span><span class="p">(</span><span class="n">residuals</span><span class="p">,</span> <span class="n">lags</span><span class="o">=</span><span class="n">lags</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">ct</span><span class="p">,</span> <span class="n">Q</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">stat</span><span class="p">):</span>
<span class="n">lag</span> <span class="o">=</span> <span class="n">ct</span><span class="o">+</span><span class="mi">1</span>
<span class="n">p_value</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">-</span> <span class="n">chi2</span><span class="o">.</span><span class="n">cdf</span><span class="p">(</span><span class="n">Q</span><span class="p">,</span> <span class="n">df</span><span class="o">=</span><span class="n">lag</span><span class="p">)</span>
<span class="n">critical_value</span> <span class="o">=</span> <span class="n">chi2</span><span class="o">.</span><span class="n">ppf</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">alpha</span><span class="p">,</span> <span class="n">df</span><span class="o">=</span><span class="n">lag</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">lag</span><span class="p">,</span> <span class="n">Q</span><span class="p">,</span> <span class="n">p_value</span><span class="p">,</span> <span class="n">critical_value</span><span class="p">,</span> <span class="s1">&#39;H0 accepted&#39;</span> <span class="k">if</span> <span class="n">Q</span> <span class="o">&gt;</span> <span class="n">critical_value</span> <span class="k">else</span> <span class="s1">&#39;H0 rejected&#39;</span><span class="p">])</span>
<span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">rows</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;Lag&#39;</span><span class="p">,</span><span class="s1">&#39;Statistic&#39;</span><span class="p">,</span><span class="s1">&#39;p-Value&#39;</span><span class="p">,</span><span class="s1">&#39;Critical Value&#39;</span><span class="p">,</span> <span class="s1">&#39;Result&#39;</span><span class="p">])</span></div>
<div class="viewcode-block" id="compare_residuals"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.ResidualAnalysis.compare_residuals">[docs]</a><span class="k">def</span> <span class="nf">compare_residuals</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">alpha</span><span class="o">=.</span><span class="mi">05</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Compare residual&#39;s statistics of several models</span>
<span class="sd"> :param data: test data</span>
<span class="sd"> :param models: </span>
<span class="sd"> :return: a Pandas dataframe with the Box-Ljung statistic for each model</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">statsmodels.stats.diagnostic</span> <span class="kn">import</span> <span class="n">acorr_ljungbox</span>
<span class="n">rows</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;Model&quot;</span><span class="p">,</span><span class="s2">&quot;Order&quot;</span><span class="p">,</span><span class="s2">&quot;AVG&quot;</span><span class="p">,</span><span class="s2">&quot;STD&quot;</span><span class="p">,</span><span class="s2">&quot;Box-Ljung&quot;</span><span class="p">,</span><span class="s2">&quot;p-value&quot;</span><span class="p">,</span><span class="s2">&quot;Result&quot;</span><span class="p">]</span>
<span class="k">for</span> <span class="n">mfts</span> <span class="ow">in</span> <span class="n">models</span><span class="p">:</span>
<span class="n">forecasts</span> <span class="o">=</span> <span class="n">mfts</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">res</span> <span class="o">=</span> <span class="n">residuals</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">forecasts</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="p">)</span>
<span class="n">mu</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
<span class="n">sig</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">std</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
<span class="n">row</span> <span class="o">=</span> <span class="p">[</span><span class="n">mfts</span><span class="o">.</span><span class="n">shortname</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="n">mu</span><span class="p">,</span> <span class="n">sig</span><span class="p">]</span>
<span class="n">stat</span><span class="p">,</span> <span class="n">pval</span> <span class="o">=</span> <span class="n">acorr_ljungbox</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
<span class="n">test</span> <span class="o">=</span> <span class="s1">&#39;H0 Accepted&#39;</span> <span class="k">if</span> <span class="n">pval</span> <span class="o">&gt;</span> <span class="n">alpha</span> <span class="k">else</span> <span class="s1">&#39;H0 Rejected&#39;</span>
<span class="n">row</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="n">stat</span><span class="p">,</span> <span class="n">pval</span><span class="p">,</span> <span class="n">test</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">row</span><span class="p">)</span>
<span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">rows</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="n">columns</span><span class="p">)</span></div>
<div class="viewcode-block" id="plot_residuals_by_model"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.ResidualAnalysis.plot_residuals_by_model">[docs]</a><span class="k">def</span> <span class="nf">plot_residuals_by_model</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="n">models</span><span class="p">,</span> <span class="n">tam</span><span class="o">=</span><span class="p">[</span><span class="mi">8</span><span class="p">,</span> <span class="mi">8</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="kn">import</span> <span class="nn">scipy</span> <span class="k">as</span> <span class="nn">sp</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="nb">len</span><span class="p">(</span><span class="n">models</span><span class="p">),</span> <span class="n">ncols</span><span class="o">=</span><span class="mi">4</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="k">for</span> <span class="n">c</span><span class="p">,</span> <span class="n">mfts</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="nb">len</span><span class="p">(</span><span class="n">models</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">ax</span> <span class="o">=</span> <span class="n">axes</span><span class="p">[</span><span class="n">c</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ax</span> <span class="o">=</span> <span class="n">axes</span>
<span class="n">forecasts</span> <span class="o">=</span> <span class="n">mfts</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">targets</span><span class="p">)</span>
<span class="n">res</span> <span class="o">=</span> <span class="n">residuals</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="n">forecasts</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="n">mu</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
<span class="n">sig</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">std</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
<span class="k">if</span> <span class="n">c</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> <span class="n">ax</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="s2">&quot;Residuals&quot;</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="s1">&#39;large&#39;</span><span class="p">)</span>
<span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="n">mfts</span><span class="o">.</span><span class="n">shortname</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="s1">&#39;large&#39;</span><span class="p">)</span>
<span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">)</span>
<span class="n">ax</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">res</span><span class="p">)</span>
<span class="k">if</span> <span class="n">c</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> <span class="n">ax</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="s2">&quot;Autocorrelation&quot;</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="s1">&#39;large&#39;</span><span class="p">)</span>
<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;ACS&#39;</span><span class="p">)</span>
<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;Lag&#39;</span><span class="p">)</span>
<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">acorr</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
<span class="k">if</span> <span class="n">c</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> <span class="n">ax</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="s2">&quot;Histogram&quot;</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="s1">&#39;large&#39;</span><span class="p">)</span>
<span class="n">ax</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Freq&#39;</span><span class="p">)</span>
<span class="n">ax</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;Bins&#39;</span><span class="p">)</span>
<span class="n">ax</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">hist</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
<span class="k">if</span> <span class="n">c</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> <span class="n">ax</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="s2">&quot;QQ Plot&quot;</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="s1">&#39;large&#39;</span><span class="p">)</span>
<span class="n">_</span><span class="p">,</span> <span class="p">(</span><span class="n">__</span><span class="p">,</span> <span class="n">___</span><span class="p">,</span> <span class="n">r</span><span class="p">)</span> <span class="o">=</span> <span class="n">sp</span><span class="o">.</span><span class="n">stats</span><span class="o">.</span><span class="n">probplot</span><span class="p">(</span><span class="n">res</span><span class="p">,</span> <span class="n">plot</span><span class="o">=</span><span class="n">ax</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="n">fit</span><span class="o">=</span><span class="kc">True</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">Util</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>
<div class="viewcode-block" id="single_plot_residuals"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.ResidualAnalysis.single_plot_residuals">[docs]</a><span class="k">def</span> <span class="nf">single_plot_residuals</span><span class="p">(</span><span class="n">res</span><span class="p">,</span> <span class="n">order</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">7</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="kn">import</span> <span class="nn">scipy</span> <span class="k">as</span> <span class="nn">sp</span>
<span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="n">nrows</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">ncols</span><span class="o">=</span><span class="mi">2</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="p">[</span><span class="mi">0</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="s2">&quot;Residuals&quot;</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="s1">&#39;large&#39;</span><span class="p">)</span>
<span class="n">ax</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="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
<span class="n">ax</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="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s2">&quot;Autocorrelation&quot;</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="s1">&#39;large&#39;</span><span class="p">)</span>
<span class="n">ax</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="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;ACF&#39;</span><span class="p">)</span>
<span class="n">ax</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="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;Lag&#39;</span><span class="p">)</span>
<span class="n">ax</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="o">.</span><span class="n">acorr</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
<span class="n">ax</span><span class="p">[</span><span class="mi">1</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="s2">&quot;Histogram&quot;</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="s1">&#39;large&#39;</span><span class="p">)</span>
<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Freq&#39;</span><span class="p">)</span>
<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;Bins&#39;</span><span class="p">)</span>
<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">hist</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
<span class="n">_</span><span class="p">,</span> <span class="p">(</span><span class="n">__</span><span class="p">,</span> <span class="n">___</span><span class="p">,</span> <span class="n">r</span><span class="p">)</span> <span class="o">=</span> <span class="n">sp</span><span class="o">.</span><span class="n">stats</span><span class="o">.</span><span class="n">probplot</span><span class="p">(</span><span class="n">res</span><span class="p">,</span> <span class="n">plot</span><span class="o">=</span><span class="n">ax</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">fit</span><span class="o">=</span><span class="kc">True</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">Util</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 class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.benchmarks.ResidualAnalysis</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,266 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.benchmarks.Tests &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.benchmarks.Tests</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.benchmarks.Tests</h1><div class="highlight"><pre>
<span></span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">from</span> <span class="nn">pyFTS.benchmarks.Measures</span> <span class="kn">import</span> <span class="n">acf</span>
<div class="viewcode-block" id="BoxPierceStatistic"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Tests.BoxPierceStatistic">[docs]</a><span class="k">def</span> <span class="nf">BoxPierceStatistic</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">h</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Q Statistic for Box-Pierce test</span>
<span class="sd"> :param data:</span>
<span class="sd"> :param h:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">n</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="n">s</span> <span class="o">=</span> <span class="mi">0</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">1</span><span class="p">,</span> <span class="n">h</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">acf</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span>
<span class="n">s</span> <span class="o">+=</span> <span class="n">r</span> <span class="o">**</span> <span class="mi">2</span>
<span class="k">return</span> <span class="n">n</span> <span class="o">*</span> <span class="n">s</span></div>
<div class="viewcode-block" id="BoxLjungStatistic"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Tests.BoxLjungStatistic">[docs]</a><span class="k">def</span> <span class="nf">BoxLjungStatistic</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">h</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Q Statistic for LjungBox test</span>
<span class="sd"> :param data:</span>
<span class="sd"> :param h:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">n</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="n">s</span> <span class="o">=</span> <span class="mi">0</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">1</span><span class="p">,</span> <span class="n">h</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">acf</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span>
<span class="n">s</span> <span class="o">+=</span> <span class="n">r</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">/</span> <span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="n">k</span><span class="p">)</span>
<span class="k">return</span> <span class="n">n</span> <span class="o">*</span> <span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span> <span class="o">*</span> <span class="n">s</span></div>
<div class="viewcode-block" id="format_experiment_table"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Tests.format_experiment_table">[docs]</a><span class="k">def</span> <span class="nf">format_experiment_table</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">exclude</span><span class="o">=</span><span class="p">[],</span> <span class="n">replace</span><span class="o">=</span><span class="p">{},</span> <span class="n">csv</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">std</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="n">rows</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">columns</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">datasets</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">Dataset</span><span class="o">.</span><span class="n">unique</span><span class="p">()</span>
<span class="n">models</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">Model</span><span class="o">.</span><span class="n">unique</span><span class="p">()</span>
<span class="k">for</span> <span class="n">model</span> <span class="ow">in</span> <span class="n">models</span><span class="p">:</span>
<span class="n">test</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">any</span><span class="p">([</span><span class="n">model</span><span class="o">.</span><span class="n">rfind</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">exclude</span><span class="p">])</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">exclude</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="kc">False</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">test</span><span class="p">:</span>
<span class="n">columns</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="k">for</span> <span class="n">dataset</span> <span class="ow">in</span> <span class="n">datasets</span><span class="p">:</span>
<span class="n">row</span> <span class="o">=</span> <span class="p">[</span><span class="n">dataset</span><span class="p">]</span>
<span class="k">if</span> <span class="n">std</span><span class="p">:</span>
<span class="n">row_std</span> <span class="o">=</span> <span class="p">[</span><span class="n">dataset</span><span class="p">]</span>
<span class="k">for</span> <span class="n">model</span> <span class="ow">in</span> <span class="n">columns</span><span class="p">:</span>
<span class="n">avg</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmin</span><span class="p">(</span><span class="n">df</span><span class="p">[(</span><span class="n">df</span><span class="o">.</span><span class="n">Dataset</span> <span class="o">==</span> <span class="n">dataset</span><span class="p">)</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">df</span><span class="o">.</span><span class="n">Model</span> <span class="o">==</span> <span class="n">model</span><span class="p">)][</span><span class="s2">&quot;AVG&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="n">row</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">avg</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
<span class="k">if</span> <span class="n">std</span><span class="p">:</span>
<span class="n">_std</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmin</span><span class="p">(</span><span class="n">df</span><span class="p">[(</span><span class="n">df</span><span class="o">.</span><span class="n">Dataset</span> <span class="o">==</span> <span class="n">dataset</span><span class="p">)</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">df</span><span class="o">.</span><span class="n">Model</span> <span class="o">==</span> <span class="n">model</span><span class="p">)][</span><span class="s2">&quot;STD&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="n">row_std</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;(&quot;</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">_std</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span> <span class="o">+</span> <span class="s2">&quot;)&quot;</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">row</span><span class="p">)</span>
<span class="k">if</span> <span class="n">std</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">row_std</span><span class="p">)</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">columns</span><span class="p">)):</span>
<span class="k">if</span> <span class="n">columns</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="ow">in</span> <span class="n">replace</span><span class="p">:</span>
<span class="n">columns</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">replace</span><span class="p">[</span><span class="n">columns</span><span class="p">[</span><span class="n">k</span><span class="p">]]</span>
<span class="n">columns</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="s2">&quot;dataset&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">csv</span><span class="p">:</span>
<span class="n">header</span> <span class="o">=</span> <span class="s2">&quot;&quot;</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">columns</span><span class="p">)):</span>
<span class="k">if</span> <span class="n">k</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="s2">&quot;,&quot;</span>
<span class="n">header</span> <span class="o">+=</span> <span class="n">columns</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>
<span class="n">body</span> <span class="o">=</span> <span class="s2">&quot;&quot;</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">rows</span><span class="p">)):</span>
<span class="n">row</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="k">for</span> <span class="n">w</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">rows</span><span class="p">[</span><span class="n">k</span><span class="p">])):</span>
<span class="k">if</span> <span class="n">w</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">row</span> <span class="o">+=</span> <span class="s2">&quot;,&quot;</span>
<span class="n">row</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">rows</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">w</span><span class="p">])</span>
<span class="n">body</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">row</span><span class="p">)</span>
<span class="k">return</span> <span class="n">header</span> <span class="o">+</span> <span class="n">body</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">rows</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="n">columns</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="test_mean_equality"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Tests.test_mean_equality">[docs]</a><span class="k">def</span> <span class="nf">test_mean_equality</span><span class="p">(</span><span class="n">tests</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=.</span><span class="mi">05</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;friedman&#39;</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Test for the equality of the means, with alpha confidence level.</span>
<span class="sd"> H_0: There&#39;s no significant difference between the means</span>
<span class="sd"> H_1: There is at least one significant difference between the means</span>
<span class="sd"> :param tests:</span>
<span class="sd"> :param alpha:</span>
<span class="sd"> :param method:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">stac.stac</span> <span class="kn">import</span> <span class="n">nonparametric_tests</span> <span class="k">as</span> <span class="n">npt</span>
<span class="n">methods</span> <span class="o">=</span> <span class="n">tests</span><span class="o">.</span><span class="n">columns</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
<span class="n">values</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">methods</span><span class="p">:</span>
<span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tests</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="k">if</span> <span class="n">method</span><span class="o">==</span><span class="s1">&#39;quade&#39;</span><span class="p">:</span>
<span class="n">f_value</span><span class="p">,</span> <span class="n">p_value</span><span class="p">,</span> <span class="n">rankings</span><span class="p">,</span> <span class="n">pivots</span> <span class="o">=</span> <span class="n">npt</span><span class="o">.</span><span class="n">quade_test</span><span class="p">(</span><span class="o">*</span><span class="n">values</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">method</span><span class="o">==</span><span class="s1">&#39;friedman&#39;</span><span class="p">:</span>
<span class="n">f_value</span><span class="p">,</span> <span class="n">p_value</span><span class="p">,</span> <span class="n">rankings</span><span class="p">,</span> <span class="n">pivots</span> <span class="o">=</span> <span class="n">npt</span><span class="o">.</span><span class="n">friedman_aligned_ranks_test</span><span class="p">(</span><span class="o">*</span><span class="n">values</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s1">&#39;Unknown test method!&#39;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;F-Value: </span><span class="si">{}</span><span class="s2"> </span><span class="se">\t</span><span class="s2">p-Value: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">f_value</span><span class="p">,</span> <span class="n">p_value</span><span class="p">))</span>
<span class="k">if</span> <span class="n">p_value</span> <span class="o">&lt;</span> <span class="n">alpha</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">H0 is rejected!</span><span class="se">\n</span><span class="s2">&quot;</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;</span><span class="se">\n</span><span class="s2">H0 is accepted!</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">post_hoc</span> <span class="o">=</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">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="nb">len</span><span class="p">(</span><span class="n">methods</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">methods</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">rankings</span><span class="p">[</span><span class="n">k</span><span class="p">]])</span>
<span class="n">post_hoc</span><span class="p">[</span><span class="n">methods</span><span class="p">[</span><span class="n">k</span><span class="p">]]</span> <span class="o">=</span> <span class="n">pivots</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>
<span class="k">return</span> <span class="p">[</span><span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">rows</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;METHOD&#39;</span><span class="p">,</span> <span class="s1">&#39;RANK&#39;</span><span class="p">])</span><span class="o">.</span><span class="n">sort_values</span><span class="p">([</span><span class="s1">&#39;RANK&#39;</span><span class="p">]),</span> <span class="n">post_hoc</span><span class="p">]</span></div>
<div class="viewcode-block" id="post_hoc_tests"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Tests.post_hoc_tests">[docs]</a><span class="k">def</span> <span class="nf">post_hoc_tests</span><span class="p">(</span><span class="n">post_hoc</span><span class="p">,</span> <span class="n">control_method</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=.</span><span class="mi">05</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;finner&#39;</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;</span>
<span class="sd"> Finner paired post-hoc test with NSFTS as control method.</span>
<span class="sd"> $H_0$: There is no significant difference between the means</span>
<span class="sd"> $H_1$: There is a significant difference between the means</span>
<span class="sd"> :param post_hoc:</span>
<span class="sd"> :param control_method:</span>
<span class="sd"> :param alpha:</span>
<span class="sd"> :param method:</span>
<span class="sd"> :return:</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="kn">from</span> <span class="nn">stac.stac</span> <span class="kn">import</span> <span class="n">nonparametric_tests</span> <span class="k">as</span> <span class="n">npt</span>
<span class="k">if</span> <span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;bonferroni_dunn&#39;</span><span class="p">:</span>
<span class="n">comparisons</span><span class="p">,</span> <span class="n">z_values</span><span class="p">,</span> <span class="n">p_values</span><span class="p">,</span> <span class="n">adj_p_values</span> <span class="o">=</span> <span class="n">npt</span><span class="o">.</span><span class="n">bonferroni_dunn_test</span><span class="p">(</span><span class="n">post_hoc</span><span class="p">,</span><span class="n">control_method</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;holm&#39;</span><span class="p">:</span>
<span class="n">comparisons</span><span class="p">,</span> <span class="n">z_values</span><span class="p">,</span> <span class="n">p_values</span><span class="p">,</span> <span class="n">adj_p_values</span> <span class="o">=</span> <span class="n">npt</span><span class="o">.</span><span class="n">holm_test</span><span class="p">(</span><span class="n">post_hoc</span><span class="p">,</span><span class="n">control_method</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;finner&#39;</span><span class="p">:</span>
<span class="n">comparisons</span><span class="p">,</span> <span class="n">z_values</span><span class="p">,</span> <span class="n">p_values</span><span class="p">,</span> <span class="n">adj_p_values</span> <span class="o">=</span> <span class="n">npt</span><span class="o">.</span><span class="n">finner_test</span><span class="p">(</span><span class="n">post_hoc</span><span class="p">,</span> <span class="n">control_method</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s1">&#39;Unknown test method!&#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">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="nb">len</span><span class="p">(</span><span class="n">comparisons</span><span class="p">)):</span>
<span class="n">test</span> <span class="o">=</span> <span class="s1">&#39;H0 Accepted&#39;</span> <span class="k">if</span> <span class="n">adj_p_values</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">alpha</span> <span class="k">else</span> <span class="s1">&#39;H0 Rejected&#39;</span>
<span class="n">rows</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">comparisons</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">z_values</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">p_values</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">adj_p_values</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">test</span><span class="p">])</span>
<span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">rows</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;COMPARISON&#39;</span><span class="p">,</span> <span class="s1">&#39;Z-VALUE&#39;</span><span class="p">,</span> <span class="s1">&#39;P-VALUE&#39;</span><span class="p">,</span> <span class="s1">&#39;ADJUSTED P-VALUE&#39;</span><span class="p">,</span> <span class="s1">&#39;Result&#39;</span><span class="p">])</span></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.benchmarks.Tests</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,320 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.benchmarks.arima &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.benchmarks.arima</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.benchmarks.arima</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/python</span>
<span class="c1"># -*- coding: utf8 -*-</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">from</span> <span class="nn">statsmodels.tsa.arima_model</span> <span class="kn">import</span> <span class="n">ARIMA</span> <span class="k">as</span> <span class="n">stats_arima</span>
<span class="kn">import</span> <span class="nn">scipy.stats</span> <span class="k">as</span> <span class="nn">st</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">SortedCollection</span><span class="p">,</span> <span class="n">fts</span>
<span class="kn">from</span> <span class="nn">pyFTS.probabilistic</span> <span class="kn">import</span> <span class="n">ProbabilityDistribution</span>
<div class="viewcode-block" id="ARIMA"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.arima.ARIMA">[docs]</a><span class="k">class</span> <span class="nc">ARIMA</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Façade for statsmodels.tsa.arima_model</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">ARIMA</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;ARIMA&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;Auto Regressive Integrated Moving Average&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_point_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_interval_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_probability_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">uod_clip</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model_fit</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">trained_data</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">p</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">d</span> <span class="o">=</span> <span class="mi">0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">q</span> <span class="o">=</span> <span class="mi">0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">benchmark_only</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_order</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">alpha</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;alpha&quot;</span><span class="p">,</span> <span class="mf">0.05</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</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;order&quot;</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</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="bp">self</span><span class="o">.</span><span class="n">_decompose_order</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">_decompose_order</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">order</span><span class="p">):</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">order</span><span class="p">,</span> <span class="p">(</span><span class="nb">tuple</span><span class="p">,</span> <span class="nb">set</span><span class="p">,</span> <span class="nb">list</span><span class="p">)):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">p</span> <span class="o">=</span> <span class="n">order</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">d</span> <span class="o">=</span> <span class="n">order</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">q</span> <span class="o">=</span> <span class="n">order</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">q</span> <span class="o">+</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">q</span> <span class="o">-</span> <span class="mi">1</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">q</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span>
<span class="bp">self</span><span class="o">.</span><span class="n">d</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transformations</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;ARIMA(</span><span class="si">{}</span><span class="s2">,</span><span class="si">{}</span><span class="s2">,</span><span class="si">{}</span><span class="s2">)-</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">d</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">q</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">alpha</span><span class="p">)</span>
<div class="viewcode-block" id="ARIMA.train"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.arima.ARIMA.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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="s1">&#39;order&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="n">order</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;order&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_decompose_order</span><span class="p">(</span><span class="n">order</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">indexer</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">indexer</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="n">stats_arima</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">order</span><span class="o">=</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">d</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">q</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model_fit</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">disp</span><span class="o">=</span><span class="mi">0</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="n">ex</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model_fit</span> <span class="o">=</span> <span class="kc">None</span></div>
<div class="viewcode-block" id="ARIMA.ar"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.arima.ARIMA.ar">[docs]</a> <span class="k">def</span> <span class="nf">ar</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="k">return</span> <span class="n">data</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model_fit</span><span class="o">.</span><span class="n">arparams</span><span class="p">)</span></div>
<div class="viewcode-block" id="ARIMA.ma"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.arima.ARIMA.ma">[docs]</a> <span class="k">def</span> <span class="nf">ma</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="k">return</span> <span class="n">data</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model_fit</span><span class="o">.</span><span class="n">maparams</span><span class="p">)</span></div>
<div class="viewcode-block" id="ARIMA.forecast"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.arima.ARIMA.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</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="bp">self</span><span class="o">.</span><span class="n">model_fit</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>
<span class="n">ndata</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="n">ndata</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">ndata</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">ar</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="bp">self</span><span class="o">.</span><span class="n">ar</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">:</span> <span class="n">k</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="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">,</span> <span class="n">l</span><span class="o">+</span><span class="mi">1</span><span class="p">)])</span> <span class="c1">#+1 to forecast one step ahead given all available lags</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">q</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">residuals</span> <span class="o">=</span> <span class="n">ndata</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="o">-</span><span class="mi">1</span><span class="p">:]</span> <span class="o">-</span> <span class="n">ar</span>
<span class="n">ma</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="bp">self</span><span class="o">.</span><span class="n">ma</span><span class="p">(</span><span class="n">residuals</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">q</span><span class="p">:</span> <span class="n">k</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="bp">self</span><span class="o">.</span><span class="n">q</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">residuals</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)])</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">ar</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">q</span> <span class="o">-</span> <span class="mi">1</span><span class="p">:]</span> <span class="o">+</span> <span class="n">ma</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">ret</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">q</span><span class="p">:]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">ar</span>
<span class="c1">#ret = self.apply_inverse_transformations(ret, params=[data[self.order - 1:]]) nforecasts = np.array(forecasts)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="ARIMA.forecast_interval"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.arima.ARIMA.forecast_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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="bp">self</span><span class="o">.</span><span class="n">model_fit</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>
<span class="k">if</span> <span class="s1">&#39;alpha&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="n">alpha</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;alpha&#39;</span><span class="p">,</span><span class="mf">0.05</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">alpha</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">alpha</span>
<span class="n">sigma</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model_fit</span><span class="o">.</span><span class="n">sigma2</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">data</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">l</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">sample</span> <span class="o">=</span> <span class="p">[</span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</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="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">k</span><span class="p">)]</span>
<span class="n">mean</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">mean</span><span class="p">,(</span><span class="nb">list</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">mean</span> <span class="o">=</span> <span class="n">mean</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mean</span> <span class="o">+</span> <span class="n">st</span><span class="o">.</span><span class="n">norm</span><span class="o">.</span><span class="n">ppf</span><span class="p">(</span><span class="n">alpha</span><span class="p">)</span> <span class="o">*</span> <span class="n">sigma</span><span class="p">)</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mean</span> <span class="o">+</span> <span class="n">st</span><span class="o">.</span><span class="n">norm</span><span class="o">.</span><span class="n">ppf</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">alpha</span><span class="p">)</span> <span class="o">*</span> <span class="n">sigma</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">tmp</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="ARIMA.forecast_ahead_interval"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.arima.ARIMA.forecast_ahead_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="n">steps</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="bp">self</span><span class="o">.</span><span class="n">model_fit</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>
<span class="k">if</span> <span class="s1">&#39;alpha&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="n">alpha</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;alpha&#39;</span><span class="p">,</span><span class="mf">0.05</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">alpha</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">alpha</span>
<span class="n">smoothing</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;smoothing&quot;</span><span class="p">,</span><span class="mf">0.5</span><span class="p">)</span>
<span class="n">sigma</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model_fit</span><span class="o">.</span><span class="n">sigma2</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">ndata</span><span class="p">)</span>
<span class="n">nmeans</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_ahead</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</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">steps</span><span class="p">):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">hsigma</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">k</span><span class="o">*</span><span class="n">smoothing</span><span class="p">)</span><span class="o">*</span><span class="n">sigma</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">nmeans</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">+</span> <span class="n">st</span><span class="o">.</span><span class="n">norm</span><span class="o">.</span><span class="n">ppf</span><span class="p">(</span><span class="n">alpha</span><span class="p">)</span> <span class="o">*</span> <span class="n">hsigma</span><span class="p">)</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">nmeans</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">+</span> <span class="n">st</span><span class="o">.</span><span class="n">norm</span><span class="o">.</span><span class="n">ppf</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">alpha</span><span class="p">)</span> <span class="o">*</span> <span class="n">hsigma</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">tmp</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span><span class="p">[</span><span class="o">-</span><span class="n">steps</span><span class="p">:]</span></div>
<div class="viewcode-block" id="ARIMA.forecast_distribution"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.arima.ARIMA.forecast_distribution">[docs]</a> <span class="k">def</span> <span class="nf">forecast_distribution</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">sigma</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model_fit</span><span class="o">.</span><span class="n">sigma2</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">data</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">l</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="p">[</span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</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="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">k</span><span class="p">)]</span>
<span class="n">mean</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">mean</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</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">mean</span> <span class="o">=</span> <span class="n">mean</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">dist</span> <span class="o">=</span> <span class="n">ProbabilityDistribution</span><span class="o">.</span><span class="n">ProbabilityDistribution</span><span class="p">(</span><span class="nb">type</span><span class="o">=</span><span class="s2">&quot;histogram&quot;</span><span class="p">,</span> <span class="n">uod</span><span class="o">=</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">original_min</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_max</span><span class="p">])</span>
<span class="n">intervals</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">alpha</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="mf">0.05</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.05</span><span class="p">):</span>
<span class="n">qt1</span> <span class="o">=</span> <span class="n">mean</span> <span class="o">+</span> <span class="n">st</span><span class="o">.</span><span class="n">norm</span><span class="o">.</span><span class="n">ppf</span><span class="p">(</span><span class="n">alpha</span><span class="p">)</span> <span class="o">*</span> <span class="n">sigma</span>
<span class="n">qt2</span> <span class="o">=</span> <span class="n">mean</span> <span class="o">+</span> <span class="n">st</span><span class="o">.</span><span class="n">norm</span><span class="o">.</span><span class="n">ppf</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">alpha</span><span class="p">)</span> <span class="o">*</span> <span class="n">sigma</span>
<span class="n">intervals</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">qt1</span><span class="p">,</span> <span class="n">qt2</span><span class="p">])</span>
<span class="n">dist</span><span class="o">.</span><span class="n">append_interval</span><span class="p">(</span><span class="n">intervals</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">dist</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="ARIMA.forecast_ahead_distribution"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.arima.ARIMA.forecast_ahead_distribution">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_distribution</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">smoothing</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;smoothing&quot;</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">)</span>
<span class="n">sigma</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model_fit</span><span class="o">.</span><span class="n">sigma2</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">data</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">nmeans</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_ahead</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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">steps</span><span class="p">):</span>
<span class="n">dist</span> <span class="o">=</span> <span class="n">ProbabilityDistribution</span><span class="o">.</span><span class="n">ProbabilityDistribution</span><span class="p">(</span><span class="nb">type</span><span class="o">=</span><span class="s2">&quot;histogram&quot;</span><span class="p">,</span>
<span class="n">uod</span><span class="o">=</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">original_min</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_max</span><span class="p">])</span>
<span class="n">intervals</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">alpha</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="mf">0.05</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.05</span><span class="p">):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">hsigma</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">k</span> <span class="o">*</span> <span class="n">smoothing</span><span class="p">)</span> <span class="o">*</span> <span class="n">sigma</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">nmeans</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">+</span> <span class="n">st</span><span class="o">.</span><span class="n">norm</span><span class="o">.</span><span class="n">ppf</span><span class="p">(</span><span class="n">alpha</span><span class="p">)</span> <span class="o">*</span> <span class="n">hsigma</span><span class="p">)</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">nmeans</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">+</span> <span class="n">st</span><span class="o">.</span><span class="n">norm</span><span class="o">.</span><span class="n">ppf</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">alpha</span><span class="p">)</span> <span class="o">*</span> <span class="n">hsigma</span><span class="p">)</span>
<span class="n">intervals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>
<span class="n">dist</span><span class="o">.</span><span class="n">append_interval</span><span class="p">(</span><span class="n">intervals</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">dist</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span><span class="p">[</span><span class="o">-</span><span class="n">steps</span><span class="p">:]</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.benchmarks.arima</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,274 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.benchmarks.knn &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.benchmarks.knn</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.benchmarks.knn</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/python</span>
<span class="c1"># -*- coding: utf8 -*-</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">statsmodels.tsa.tsatools</span> <span class="kn">import</span> <span class="n">lagmat</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">fts</span>
<span class="kn">from</span> <span class="nn">pyFTS.probabilistic</span> <span class="kn">import</span> <span class="n">ProbabilityDistribution</span>
<span class="kn">from</span> <span class="nn">sklearn.neighbors</span> <span class="kn">import</span> <span class="n">KDTree</span>
<span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">product</span>
<span class="kn">from</span> <span class="nn">pyFTS.models.ensemble.ensemble</span> <span class="kn">import</span> <span class="n">sampler</span>
<div class="viewcode-block" id="KNearestNeighbors"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.knn.KNearestNeighbors">[docs]</a><span class="k">class</span> <span class="nc">KNearestNeighbors</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> A façade for sklearn.neighbors</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">KNearestNeighbors</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;kNN&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;kNN&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;K-Nearest Neighbors&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">uod_clip</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_point_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_interval_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_probability_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">benchmark_only</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_order</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">alpha</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;alpha&quot;</span><span class="p">,</span> <span class="mf">0.05</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span>
<span class="bp">self</span><span class="o">.</span><span class="n">lag</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">k</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;k&quot;</span><span class="p">,</span> <span class="mi">30</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">uod</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">kdtree</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">values</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">def</span> <span class="nf">_prepare_x</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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">data</span><span class="p">)</span>
<span class="n">X</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="n">l</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:</span>
<span class="n">l</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="k">for</span> <span class="n">t</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>
<span class="n">X</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">data</span><span class="p">[</span><span class="n">t</span> <span class="o">-</span> <span class="n">k</span> <span class="o">-</span> <span class="mi">1</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">)])</span>
<span class="k">return</span> <span class="n">X</span>
<span class="k">def</span> <span class="nf">_prepare_xy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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">data</span><span class="p">)</span>
<span class="n">X</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">Y</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">t</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>
<span class="n">X</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">data</span><span class="p">[</span><span class="n">t</span> <span class="o">-</span> <span class="n">k</span> <span class="o">-</span> <span class="mi">1</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">)])</span>
<span class="n">Y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">t</span><span class="p">])</span>
<span class="k">return</span> <span class="p">(</span><span class="n">X</span><span class="p">,</span><span class="n">Y</span><span class="p">)</span>
<div class="viewcode-block" id="KNearestNeighbors.train"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.knn.KNearestNeighbors.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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="bp">self</span><span class="o">.</span><span class="n">_prepare_xy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">kdtree</span> <span class="o">=</span> <span class="n">KDTree</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">X</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">values</span> <span class="o">=</span> <span class="n">Y</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;kNN(</span><span class="si">{}</span><span class="s2">)-</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">alpha</span><span class="p">)</span></div>
<div class="viewcode-block" id="KNearestNeighbors.knn"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.knn.KNearestNeighbors.knn">[docs]</a> <span class="k">def</span> <span class="nf">knn</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sample</span><span class="p">):</span>
<span class="n">X</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_prepare_x</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="n">_</span><span class="p">,</span> <span class="n">ix</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">kdtree</span><span class="o">.</span><span class="n">query</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">X</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">k</span><span class="p">)</span>
<span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">values</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">ix</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span> <span class="p">]</span></div>
<div class="viewcode-block" id="KNearestNeighbors.forecast"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.knn.KNearestNeighbors.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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">data</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">l</span><span class="o">+</span><span class="p">(</span><span class="mi">1</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="o">==</span> <span class="n">l</span> <span class="k">else</span> <span class="mi">0</span><span class="p">)):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">forecasts</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">knn</span><span class="p">(</span><span class="n">sample</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">np</span><span class="o">.</span><span class="n">nanmean</span><span class="p">(</span><span class="n">forecasts</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="KNearestNeighbors.forecast_interval"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.knn.KNearestNeighbors.forecast_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">alpha</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;alpha&#39;</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">alpha</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</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="bp">self</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">data</span><span class="p">)):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">forecasts</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">knn</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="n">i</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">percentile</span><span class="p">(</span><span class="n">forecasts</span><span class="p">,</span> <span class="p">[</span><span class="n">alpha</span><span class="o">*</span><span class="mi">100</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</span><span class="o">-</span><span class="n">alpha</span><span class="p">)</span><span class="o">*</span><span class="mi">100</span><span class="p">])</span><span class="o">.</span><span class="n">tolist</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">i</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="KNearestNeighbors.forecast_ahead_interval"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.knn.KNearestNeighbors.forecast_ahead_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">alpha</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;alpha&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">alpha</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">start</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;start&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">)</span>
<span class="n">sample</span> <span class="o">=</span> <span class="p">[[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="n">start</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:</span> <span class="n">start</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">steps</span> <span class="o">+</span> <span class="bp">self</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="p">[]</span>
<span class="n">lags</span> <span class="o">=</span> <span class="p">[</span><span class="n">sample</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">)]</span>
<span class="c1"># Trace the possible paths</span>
<span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">lags</span><span class="p">):</span>
<span class="n">forecasts</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">knn</span><span class="p">(</span><span class="n">path</span><span class="p">))</span>
<span class="n">sample</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sampler</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">arange</span><span class="p">(</span><span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">),</span> <span class="n">bounds</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
<span class="n">interval</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">percentile</span><span class="p">(</span><span class="n">forecasts</span><span class="p">,</span> <span class="p">[</span><span class="n">alpha</span><span class="o">*</span><span class="mi">100</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</span><span class="o">-</span><span class="n">alpha</span><span class="p">)</span><span class="o">*</span><span class="mi">100</span><span class="p">])</span><span class="o">.</span><span class="n">tolist</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">interval</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="KNearestNeighbors.forecast_distribution"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.knn.KNearestNeighbors.forecast_distribution">[docs]</a> <span class="k">def</span> <span class="nf">forecast_distribution</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">smooth</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;smooth&quot;</span><span class="p">,</span> <span class="s2">&quot;histogram&quot;</span><span class="p">)</span>
<span class="n">uod</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_UoD</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="bp">self</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">data</span><span class="p">)):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">forecasts</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">knn</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="n">dist</span> <span class="o">=</span> <span class="n">ProbabilityDistribution</span><span class="o">.</span><span class="n">ProbabilityDistribution</span><span class="p">(</span><span class="n">smooth</span><span class="p">,</span> <span class="n">uod</span><span class="o">=</span><span class="n">uod</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">forecasts</span><span class="p">,</span>
<span class="n">name</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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">dist</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="KNearestNeighbors.forecast_ahead_distribution"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.knn.KNearestNeighbors.forecast_ahead_distribution">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_distribution</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">smooth</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;smooth&quot;</span><span class="p">,</span> <span class="s2">&quot;histogram&quot;</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">start</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;start&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">)</span>
<span class="n">uod</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_UoD</span><span class="p">()</span>
<span class="n">sample</span> <span class="o">=</span> <span class="p">[[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="n">start</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:</span> <span class="n">start</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">steps</span> <span class="o">+</span> <span class="bp">self</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="p">[]</span>
<span class="n">lags</span> <span class="o">=</span> <span class="p">[</span><span class="n">sample</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">)]</span>
<span class="c1"># Trace the possible paths</span>
<span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">lags</span><span class="p">):</span>
<span class="n">forecasts</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">knn</span><span class="p">(</span><span class="n">path</span><span class="p">))</span>
<span class="n">dist</span> <span class="o">=</span> <span class="n">ProbabilityDistribution</span><span class="o">.</span><span class="n">ProbabilityDistribution</span><span class="p">(</span><span class="n">smooth</span><span class="p">,</span> <span class="n">uod</span><span class="o">=</span><span class="n">uod</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">forecasts</span><span class="p">,</span>
<span class="n">name</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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">dist</span><span class="p">)</span>
<span class="n">sample</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sampler</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">arange</span><span class="p">(</span><span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">),</span> <span class="n">bounds</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ret</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.benchmarks.knn</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,118 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.benchmarks.naive &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.benchmarks.naive</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.benchmarks.naive</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/python</span>
<span class="c1"># -*- coding: utf8 -*-</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">fts</span>
<div class="viewcode-block" id="Naive"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.naive.Naive">[docs]</a><span class="k">class</span> <span class="nc">Naive</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Naïve Forecasting method&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">Naive</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</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">name</span><span class="o">=</span><span class="s2">&quot;Naive&quot;</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Naïve Model&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;Naïve Model&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">benchmark_only</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">uod_clip</span> <span class="o">=</span> <span class="kc">False</span>
<div class="viewcode-block" id="Naive.forecast"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.naive.Naive.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">return</span> <span class="n">data</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.benchmarks.naive</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,267 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.benchmarks.quantreg &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.benchmarks.quantreg</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.benchmarks.quantreg</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/python</span>
<span class="c1"># -*- coding: utf8 -*-</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">from</span> <span class="nn">statsmodels.regression.quantile_regression</span> <span class="kn">import</span> <span class="n">QuantReg</span>
<span class="kn">from</span> <span class="nn">statsmodels.tsa.tsatools</span> <span class="kn">import</span> <span class="n">lagmat</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">SortedCollection</span><span class="p">,</span> <span class="n">fts</span>
<span class="kn">from</span> <span class="nn">pyFTS.probabilistic</span> <span class="kn">import</span> <span class="n">ProbabilityDistribution</span>
<div class="viewcode-block" id="QuantileRegression"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.quantreg.QuantileRegression">[docs]</a><span class="k">class</span> <span class="nc">QuantileRegression</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Façade for statsmodels.regression.quantile_regression&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">QuantileRegression</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;QAR&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;Quantile Regression&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_point_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_interval_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_probability_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">uod_clip</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">benchmark_only</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_order</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">alpha</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;alpha&quot;</span><span class="p">,</span> <span class="mf">0.05</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">dist</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;dist&quot;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">upper_qt</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mean_qt</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">lower_qt</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">dist_qt</span> <span class="o">=</span> <span class="kc">None</span>
<div class="viewcode-block" id="QuantileRegression.train"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.quantreg.QuantileRegression.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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="bp">self</span><span class="o">.</span><span class="n">indexer</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">):</span>
<span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">indexer</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">lagdata</span><span class="p">,</span> <span class="n">ndata</span> <span class="o">=</span> <span class="n">lagmat</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">maxlag</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">trim</span><span class="o">=</span><span class="s2">&quot;both&quot;</span><span class="p">,</span> <span class="n">original</span><span class="o">=</span><span class="s1">&#39;sep&#39;</span><span class="p">)</span>
<span class="n">mqt</span> <span class="o">=</span> <span class="n">QuantReg</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">lagdata</span><span class="p">)</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="mf">0.5</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">alpha</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">uqt</span> <span class="o">=</span> <span class="n">QuantReg</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">lagdata</span><span class="p">)</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">alpha</span><span class="p">)</span>
<span class="n">lqt</span> <span class="o">=</span> <span class="n">QuantReg</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">lagdata</span><span class="p">)</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">alpha</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mean_qt</span> <span class="o">=</span> <span class="p">[</span><span class="n">k</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">mqt</span><span class="o">.</span><span class="n">params</span><span class="p">]</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">alpha</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">upper_qt</span> <span class="o">=</span> <span class="p">[</span><span class="n">k</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">uqt</span><span class="o">.</span><span class="n">params</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">lower_qt</span> <span class="o">=</span> <span class="p">[</span><span class="n">k</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">lqt</span><span class="o">.</span><span class="n">params</span><span class="p">]</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dist</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">dist_qt</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">alpha</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="mf">0.05</span><span class="p">,</span><span class="mf">0.5</span><span class="p">,</span><span class="mf">0.05</span><span class="p">):</span>
<span class="n">lqt</span> <span class="o">=</span> <span class="n">QuantReg</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">lagdata</span><span class="p">)</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">alpha</span><span class="p">)</span>
<span class="n">uqt</span> <span class="o">=</span> <span class="n">QuantReg</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">lagdata</span><span class="p">)</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">alpha</span><span class="p">)</span>
<span class="n">lo_qt</span> <span class="o">=</span> <span class="p">[</span><span class="n">k</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">lqt</span><span class="o">.</span><span class="n">params</span><span class="p">]</span>
<span class="n">up_qt</span> <span class="o">=</span> <span class="p">[</span><span class="n">k</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">uqt</span><span class="o">.</span><span class="n">params</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">dist_qt</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">lo_qt</span><span class="p">,</span> <span class="n">up_qt</span><span class="p">])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;QAR(</span><span class="si">{}</span><span class="s2">)-</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">alpha</span><span class="p">)</span></div>
<div class="viewcode-block" id="QuantileRegression.linearmodel"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.quantreg.QuantileRegression.linearmodel">[docs]</a> <span class="k">def</span> <span class="nf">linearmodel</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">data</span><span class="p">,</span><span class="n">params</span><span class="p">):</span>
<span class="c1">#return params[0] + sum([ data[k] * params[k+1] for k in np.arange(0, self.order) ])</span>
<span class="k">return</span> <span class="nb">sum</span><span class="p">([</span><span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">*</span> <span class="n">params</span><span class="p">[</span><span class="n">k</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">)])</span></div>
<div class="viewcode-block" id="QuantileRegression.point_to_interval"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.quantreg.QuantileRegression.point_to_interval">[docs]</a> <span class="k">def</span> <span class="nf">point_to_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">lo_params</span><span class="p">,</span> <span class="n">up_params</span><span class="p">):</span>
<span class="n">lo</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">linearmodel</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">lo_params</span><span class="p">)</span>
<span class="n">up</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">linearmodel</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">up_params</span><span class="p">)</span>
<span class="k">return</span> <span class="p">[</span><span class="n">lo</span><span class="p">,</span> <span class="n">up</span><span class="p">]</span></div>
<div class="viewcode-block" id="QuantileRegression.interval_to_interval"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.quantreg.QuantileRegression.interval_to_interval">[docs]</a> <span class="k">def</span> <span class="nf">interval_to_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">lo_params</span><span class="p">,</span> <span class="n">up_params</span><span class="p">):</span>
<span class="n">lo</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">linearmodel</span><span class="p">([</span><span class="n">k</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">data</span><span class="p">],</span> <span class="n">lo_params</span><span class="p">)</span>
<span class="n">up</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">linearmodel</span><span class="p">([</span><span class="n">k</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">data</span><span class="p">],</span> <span class="n">up_params</span><span class="p">)</span>
<span class="k">return</span> <span class="p">[</span><span class="n">lo</span><span class="p">,</span> <span class="n">up</span><span class="p">]</span></div>
<div class="viewcode-block" id="QuantileRegression.forecast"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.quantreg.QuantileRegression.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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">ndata</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">l</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span> <span class="c1">#+1 to forecast one step ahead given all available lags</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">ndata</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="p">:</span> <span class="n">k</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="bp">self</span><span class="o">.</span><span class="n">linearmodel</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mean_qt</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="QuantileRegression.forecast_interval"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.quantreg.QuantileRegression.forecast_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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">ndata</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</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="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="p">,</span> <span class="n">l</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">ndata</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:</span> <span class="n">k</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="bp">self</span><span class="o">.</span><span class="n">point_to_interval</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">lower_qt</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">upper_qt</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="QuantileRegression.forecast_ahead_interval"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.quantreg.QuantileRegression.forecast_ahead_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">smoothing</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;smoothing&quot;</span><span class="p">,</span> <span class="mf">0.01</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">ndata</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">nmeans</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_ahead</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">):</span>
<span class="n">nmeans</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="n">k</span><span class="p">,</span><span class="n">ndata</span><span class="p">[</span><span class="n">k</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">steps</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">):</span>
<span class="n">intl</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">point_to_interval</span><span class="p">(</span><span class="n">nmeans</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:</span> <span class="n">k</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">lower_qt</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">upper_qt</span><span class="p">)</span>
<span class="n">tmpk</span> <span class="o">=</span> <span class="n">k</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">intl</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="p">(</span><span class="n">tmpk</span><span class="o">*</span><span class="n">smoothing</span><span class="p">)),</span> <span class="n">intl</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="p">(</span><span class="n">tmpk</span><span class="o">*</span><span class="n">smoothing</span><span class="p">))])</span>
<span class="k">return</span> <span class="n">ret</span><span class="p">[</span><span class="o">-</span><span class="n">steps</span><span class="p">:]</span></div>
<div class="viewcode-block" id="QuantileRegression.forecast_distribution"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.quantreg.QuantileRegression.forecast_distribution">[docs]</a> <span class="k">def</span> <span class="nf">forecast_distribution</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</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">ndata</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">l</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
<span class="n">dist</span> <span class="o">=</span> <span class="n">ProbabilityDistribution</span><span class="o">.</span><span class="n">ProbabilityDistribution</span><span class="p">(</span><span class="nb">type</span><span class="o">=</span><span class="s2">&quot;histogram&quot;</span><span class="p">,</span>
<span class="n">uod</span><span class="o">=</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">original_min</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_max</span><span class="p">])</span>
<span class="n">intervals</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">qt</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dist_qt</span><span class="p">:</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">ndata</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">intl</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">point_to_interval</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">qt</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">qt</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="n">intervals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">intl</span><span class="p">)</span>
<span class="n">dist</span><span class="o">.</span><span class="n">append_interval</span><span class="p">(</span><span class="n">intervals</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">dist</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="QuantileRegression.forecast_ahead_distribution"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.quantreg.QuantileRegression.forecast_ahead_distribution">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_distribution</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">smoothing</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;smoothing&quot;</span><span class="p">,</span> <span class="mf">0.01</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">ndata</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">nmeans</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_ahead</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">):</span>
<span class="n">nmeans</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">ndata</span><span class="p">[</span><span class="n">k</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">steps</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">):</span>
<span class="n">dist</span> <span class="o">=</span> <span class="n">ProbabilityDistribution</span><span class="o">.</span><span class="n">ProbabilityDistribution</span><span class="p">(</span><span class="nb">type</span><span class="o">=</span><span class="s2">&quot;histogram&quot;</span><span class="p">,</span>
<span class="n">uod</span><span class="o">=</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">original_min</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_max</span><span class="p">])</span>
<span class="n">intervals</span> <span class="o">=</span> <span class="p">[[</span><span class="n">nmeans</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">],</span> <span class="n">nmeans</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">]]]</span>
<span class="k">for</span> <span class="n">qt</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dist_qt</span><span class="p">:</span>
<span class="n">intl1</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">point_to_interval</span><span class="p">(</span><span class="n">nmeans</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:</span> <span class="n">k</span><span class="p">],</span> <span class="n">qt</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">qt</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="n">tmpk</span> <span class="o">=</span> <span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span>
<span class="n">intl2</span> <span class="o">=</span> <span class="p">[</span><span class="n">intl1</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="p">(</span><span class="n">tmpk</span> <span class="o">*</span> <span class="n">smoothing</span><span class="p">)),</span> <span class="n">intl1</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="p">(</span><span class="n">tmpk</span> <span class="o">*</span> <span class="n">smoothing</span><span class="p">))]</span>
<span class="n">intervals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">intl2</span><span class="p">)</span>
<span class="n">dist</span><span class="o">.</span><span class="n">append_interval</span><span class="p">(</span><span class="n">intervals</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">dist</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.benchmarks.quantreg</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,652 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.common.Util &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.common.Util</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.common.Util</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Common facilities for pyFTS</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">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">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</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">from</span> <span class="nn">pyFTS.probabilistic</span> <span class="kn">import</span> <span class="n">ProbabilityDistribution</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">Transformations</span>
<div class="viewcode-block" id="plot_compared_intervals_ahead"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Util.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">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.common.html#pyFTS.common.Util.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="kn">import</span> <span class="n">Rectangle</span>
<span class="kn">from</span> <span class="nn">matplotlib.collections</span> <span class="kn">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_probability_distributions"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Util.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="plot_distribution"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Util.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="sd">&quot;&quot;&quot;</span>
<span class="sd"> Plot forecasted ProbabilityDistribution objects on a matplotlib axis</span>
<span class="sd"> :param ax: matplotlib axis</span>
<span class="sd"> :param cmap: matplotlib colormap name</span>
<span class="sd"> :param probabilitydist: list of ProbabilityDistribution objects</span>
<span class="sd"> :param fig: matplotlib figure</span>
<span class="sd"> :param time_from: starting time (on x axis) to begin the plots</span>
<span class="sd"> :param reference_data:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">matplotlib.patches</span> <span class="kn">import</span> <span class="n">Rectangle</span>
<span class="kn">from</span> <span class="nn">matplotlib.collections</span> <span class="kn">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_distribution2"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Util.plot_distribution2">[docs]</a><span class="k">def</span> <span class="nf">plot_distribution2</span><span class="p">(</span><span class="n">probabilitydist</span><span class="p">,</span> <span class="n">data</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"> Plot distributions in y-axis over the time (x-axis)</span>
<span class="sd"> :param probabilitydist: the forecasted probability distributions to plot</span>
<span class="sd"> :param data: the original test sample</span>
<span class="sd"> :keyword start_at: the time index (inside of data) to start to plot the probability distributions</span>
<span class="sd"> :keyword ax: a matplotlib axis. If no value was provided a new axis is created.</span>
<span class="sd"> :keyword cmap: a matplotlib colormap name, the default value is &#39;Blues&#39;</span>
<span class="sd"> :keyword quantiles: the list of quantiles intervals to plot, e. g. [.05, .25, .75, .95]</span>
<span class="sd"> :keyword median: a boolean value indicating if the median value will be plot.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">matplotlib.colorbar</span> <span class="k">as</span> <span class="nn">cbar</span>
<span class="kn">import</span> <span class="nn">matplotlib.cm</span> <span class="k">as</span> <span class="nn">cm</span>
<span class="n">ax</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;ax&#39;</span><span class="p">,</span><span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="n">ax</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="n">nrows</span><span class="o">=</span><span class="mi">1</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">15</span><span class="p">,</span> <span class="mi">5</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">probabilitydist</span><span class="p">)</span>
<span class="n">cmap</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;cmap&#39;</span><span class="p">,</span><span class="s1">&#39;Blues&#39;</span><span class="p">)</span>
<span class="n">cmap</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">start_at</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;start_at&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
<span class="n">x</span> <span class="o">=</span> <span class="p">[</span><span class="n">k</span> <span class="o">+</span> <span class="n">start_at</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="n">l</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)]</span>
<span class="n">qt</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;quantiles&#39;</span><span class="p">,</span><span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="n">qt</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">qt</span> <span class="o">=</span> <span class="p">[</span><span class="nb">round</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">2</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="o">.</span><span class="mi">05</span><span class="p">,</span> <span class="mf">1.</span><span class="p">,</span> <span class="o">.</span><span class="mi">05</span><span class="p">)]</span>
<span class="n">qt</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="o">.</span><span class="mi">01</span><span class="p">)</span>
<span class="n">qt</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="o">.</span><span class="mi">99</span><span class="p">)</span>
<span class="n">lq</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">qt</span><span class="p">)</span>
<span class="n">normal</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">Normalize</span><span class="p">(</span><span class="nb">min</span><span class="p">(</span><span class="n">qt</span><span class="p">),</span> <span class="nb">max</span><span class="p">(</span><span class="n">qt</span><span class="p">))</span>
<span class="n">scalarMap</span> <span class="o">=</span> <span class="n">cm</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">normal</span><span class="p">,</span> <span class="n">cmap</span><span class="o">=</span><span class="n">cmap</span><span class="p">)</span>
<span class="k">for</span> <span class="n">ct</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="nb">int</span><span class="p">(</span><span class="n">lq</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">y</span> <span class="o">=</span> <span class="p">[[</span><span class="n">data</span><span class="p">[</span><span class="n">start_at</span><span class="p">],</span> <span class="n">data</span><span class="p">[</span><span class="n">start_at</span><span class="p">]]]</span>
<span class="k">for</span> <span class="n">pd</span> <span class="ow">in</span> <span class="n">probabilitydist</span><span class="p">:</span>
<span class="n">qts</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">quantile</span><span class="p">([</span><span class="n">qt</span><span class="p">[</span><span class="n">ct</span> <span class="o">-</span> <span class="mi">1</span><span class="p">],</span> <span class="n">qt</span><span class="p">[</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">append</span><span class="p">(</span><span class="n">qts</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">fill_between</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="p">[</span><span class="n">k</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">y</span><span class="p">],</span> <span class="p">[</span><span class="n">k</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">y</span><span class="p">],</span>
<span class="n">facecolor</span><span class="o">=</span><span class="n">scalarMap</span><span class="o">.</span><span class="n">to_rgba</span><span class="p">(</span><span class="n">ct</span> <span class="o">/</span> <span class="n">lq</span><span class="p">))</span>
<span class="k">except</span><span class="p">:</span>
<span class="k">pass</span>
<span class="k">if</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;median&#39;</span><span class="p">,</span><span class="kc">True</span><span class="p">):</span>
<span class="n">y</span> <span class="o">=</span> <span class="p">[</span><span class="n">data</span><span class="p">[</span><span class="n">start_at</span><span class="p">]]</span>
<span class="k">for</span> <span class="n">pd</span> <span class="ow">in</span> <span class="n">probabilitydist</span><span class="p">:</span>
<span class="n">qts</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">quantile</span><span class="p">([</span><span class="o">.</span><span class="mi">5</span><span class="p">])</span>
<span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">qts</span><span class="p">[</span><span class="mi">0</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">x</span><span class="p">,</span> <span class="n">y</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">label</span><span class="o">=</span><span class="s1">&#39;Median&#39;</span><span class="p">)</span>
<span class="n">cax</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">cbar</span><span class="o">.</span><span class="n">make_axes</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
<span class="n">cb</span> <span class="o">=</span> <span class="n">cbar</span><span class="o">.</span><span class="n">ColorbarBase</span><span class="p">(</span><span class="n">cax</span><span class="p">,</span> <span class="n">cmap</span><span class="o">=</span><span class="n">cmap</span><span class="p">,</span> <span class="n">norm</span><span class="o">=</span><span class="n">normal</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_tiled"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Util.plot_distribution_tiled">[docs]</a><span class="k">def</span> <span class="nf">plot_distribution_tiled</span><span class="p">(</span><span class="n">distributions</span><span class="p">,</span><span class="n">data</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span><span class="n">rows</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span><span class="n">cols</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span><span class="n">index</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span><span class="n">size</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mi">20</span><span class="p">]):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Plot one distribution individually in each axis, with probability in y-axis and UoD on x-axis</span>
<span class="sd"> :param distributions:</span>
<span class="sd"> :param data:</span>
<span class="sd"> :param rows:</span>
<span class="sd"> :param cols:</span>
<span class="sd"> :param index:</span>
<span class="sd"> :param axis:</span>
<span class="sd"> :param size:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">axis</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">fig</span><span class="p">,</span> <span class="n">axis</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="n">rows</span><span class="p">,</span> <span class="n">ncols</span><span class="o">=</span><span class="n">cols</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="n">size</span><span class="p">)</span>
<span class="k">for</span> <span class="n">ct</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">rows</span><span class="o">*</span><span class="n">cols</span><span class="p">):</span>
<span class="n">col</span> <span class="o">=</span> <span class="n">ct</span> <span class="o">%</span> <span class="n">cols</span>
<span class="n">row</span> <span class="o">=</span> <span class="n">ct</span> <span class="o">//</span> <span class="n">cols</span>
<span class="k">if</span> <span class="n">index</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">ix</span> <span class="o">=</span> <span class="n">ct</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ix</span> <span class="o">=</span><span class="n">index</span><span class="p">[</span><span class="n">ct</span><span class="p">]</span>
<span class="n">forecast</span> <span class="o">=</span> <span class="n">distributions</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span>
<span class="n">forecast</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="n">axis</span><span class="p">[</span><span class="n">row</span><span class="p">][</span><span class="n">col</span><span class="p">])</span>
<span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">axis</span><span class="p">[</span><span class="n">row</span><span class="p">][</span><span class="n">col</span><span class="p">]</span><span class="o">.</span><span class="n">axvline</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">ix</span><span class="p">])</span>
<span class="n">axis</span><span class="p">[</span><span class="n">row</span><span class="p">][</span><span class="n">col</span><span class="p">]</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">&#39;t+</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ix</span><span class="p">))</span>
<span class="n">axis</span><span class="p">[</span><span class="n">row</span><span class="p">][</span><span class="n">col</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span></div>
<div class="viewcode-block" id="plot_interval"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Util.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="sd">&quot;&quot;&quot;</span>
<span class="sd"> Plot forecasted intervals on matplotlib</span>
<span class="sd"> :param axis: matplotlib axis</span>
<span class="sd"> :param intervals: list of forecasted intervals</span>
<span class="sd"> :param order: order of the model that create the forecasts</span>
<span class="sd"> :param label: figure label</span>
<span class="sd"> :param color: matplotlib color name</span>
<span class="sd"> :param typeonlegend:</span>
<span class="sd"> :param ls: matplotlib line style</span>
<span class="sd"> :param linewidth: matplotlib width</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</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="o">+</span><span class="mi">1</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_interval2"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Util.plot_interval2">[docs]</a><span class="k">def</span> <span class="nf">plot_interval2</span><span class="p">(</span><span class="n">intervals</span><span class="p">,</span> <span class="n">data</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"> Plot forecasted intervals on matplotlib</span>
<span class="sd"> :param intervals: list of forecasted intervals</span>
<span class="sd"> :param data: the original test sample</span>
<span class="sd"> :keyword start_at: the time index (inside of data) to start to plot the intervals</span>
<span class="sd"> :keyword label: figure label</span>
<span class="sd"> :keyword color: matplotlib color name</span>
<span class="sd"> :keyword typeonlegend:</span>
<span class="sd"> :keyword ls: matplotlib line style</span>
<span class="sd"> :keyword linewidth: matplotlib width</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">l</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">intervals</span><span class="p">)</span>
<span class="n">nintervals</span> <span class="o">=</span> <span class="n">intervals</span>
<span class="n">start_at</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;start_at&#39;</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">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;ax&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="n">ax</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="n">nrows</span><span class="o">=</span><span class="mi">1</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">15</span><span class="p">,</span> <span class="mi">5</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">start_at</span><span class="p">):</span>
<span class="n">nintervals</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="p">[</span><span class="kc">None</span><span class="p">,</span><span class="kc">None</span><span class="p">])</span>
<span class="n">nintervals</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="n">start_at</span><span class="p">,</span> <span class="p">[</span><span class="n">data</span><span class="p">[</span><span class="n">start_at</span><span class="p">],</span> <span class="n">data</span><span class="p">[</span><span class="n">start_at</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">nintervals</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">nintervals</span><span class="p">]</span>
<span class="n">typeonlegend</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;typeonlegend&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="n">color</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;color&#39;</span><span class="p">,</span> <span class="s1">&#39;red&#39;</span><span class="p">)</span>
<span class="n">label</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;label&#39;</span><span class="p">,</span><span class="s1">&#39;&#39;</span><span class="p">)</span>
<span class="n">linewidth</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;linewidth&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">ls</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;ls&#39;</span><span class="p">,</span><span class="s1">&#39;-&#39;</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">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">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">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">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></div>
<div class="viewcode-block" id="plot_rules"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Util.plot_rules">[docs]</a><span class="k">def</span> <span class="nf">plot_rules</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">[</span><span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">rules_by_axis</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Plot the FLRG rules of a FTS model on a matplotlib axis</span>
<span class="sd"> :param model: FTS model</span>
<span class="sd"> :param size: figure size</span>
<span class="sd"> :param axis: matplotlib axis</span>
<span class="sd"> :param rules_by_axis: number of rules plotted by column</span>
<span class="sd"> :param columns: number of columns</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">axis</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">rules_by_axis</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">rows</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">elif</span> <span class="n">axis</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">rules_by_axis</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">rows</span> <span class="o">=</span> <span class="p">(((</span><span class="nb">len</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">flrgs</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span><span class="o">//</span><span class="n">rules_by_axis</span><span class="p">))</span> <span class="o">//</span> <span class="n">columns</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span>
<span class="n">fig</span><span class="p">,</span> <span class="n">axis</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="n">rows</span><span class="p">,</span> <span class="n">ncols</span><span class="o">=</span><span class="n">columns</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="n">size</span><span class="p">)</span>
<span class="k">if</span> <span class="n">rules_by_axis</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">draw_sets_on_axis</span><span class="p">(</span><span class="n">axis</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">size</span><span class="p">)</span>
<span class="n">_lhs</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">model</span><span class="o">.</span><span class="n">is_high_order</span> <span class="k">else</span> <span class="n">model</span><span class="o">.</span><span class="n">flrgs</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
<span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">_lhs</span><span class="p">):</span>
<span class="n">xticks</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">xtickslabels</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="n">rules_by_axis</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">ax</span> <span class="o">=</span> <span class="n">axis</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">colcount</span> <span class="o">=</span> <span class="p">(</span><span class="n">ct</span> <span class="o">//</span> <span class="n">rules_by_axis</span><span class="p">)</span> <span class="o">%</span> <span class="n">columns</span>
<span class="n">rowcount</span> <span class="o">=</span> <span class="p">(</span><span class="n">ct</span> <span class="o">//</span> <span class="n">rules_by_axis</span><span class="p">)</span> <span class="o">//</span> <span class="n">columns</span>
<span class="k">if</span> <span class="n">rows</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">columns</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">ax</span> <span class="o">=</span> <span class="n">axis</span><span class="p">[</span><span class="n">rowcount</span><span class="p">,</span> <span class="n">colcount</span><span class="p">]</span>
<span class="k">elif</span> <span class="n">columns</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">ax</span> <span class="o">=</span> <span class="n">axis</span><span class="p">[</span><span class="n">rowcount</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ax</span> <span class="o">=</span> <span class="n">axis</span>
<span class="k">if</span> <span class="n">ct</span> <span class="o">%</span> <span class="n">rules_by_axis</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">draw_sets_on_axis</span><span class="p">(</span><span class="n">ax</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">size</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">model</span><span class="o">.</span><span class="n">is_high_order</span><span class="p">:</span>
<span class="k">if</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">model</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">x</span> <span class="o">=</span> <span class="p">(</span><span class="n">ct</span> <span class="o">%</span> <span class="n">rules_by_axis</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span>
<span class="n">ax</span><span class="o">.</span><span class="n">plot</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="s1">&#39;o&#39;</span><span class="p">)</span>
<span class="n">xticks</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="n">xtickslabels</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
<span class="k">for</span> <span class="n">rhs</span> <span class="ow">in</span> <span class="n">flrg</span><span class="o">.</span><span class="n">RHS</span><span class="p">:</span>
<span class="n">dest</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">rhs</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span>
<span class="n">ax</span><span class="o">.</span><span class="n">arrow</span><span class="p">(</span><span class="n">x</span><span class="o">+.</span><span class="mi">1</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="n">dest</span> <span class="o">-</span> <span class="n">y</span><span class="p">,</span> <span class="c1">#length_includes_head=True,</span>
<span class="n">head_width</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span> <span class="n">head_length</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="s1">&#39;full&#39;</span><span class="p">,</span> <span class="n">overhang</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
<span class="n">fc</span><span class="o">=</span><span class="s1">&#39;k&#39;</span><span class="p">,</span> <span class="n">ec</span><span class="o">=</span><span class="s1">&#39;k&#39;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
<span class="n">x</span> <span class="o">=</span> <span class="p">(</span><span class="n">ct</span><span class="o">%</span><span class="n">rules_by_axis</span><span class="p">)</span><span class="o">*</span><span class="n">model</span><span class="o">.</span><span class="n">order</span> <span class="o">+</span> <span class="mi">1</span>
<span class="k">for</span> <span class="n">ct2</span><span class="p">,</span> <span class="n">lhs</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">):</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">lhs</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span>
<span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">([</span><span class="n">x</span><span class="o">+</span><span class="n">ct2</span><span class="p">],</span> <span class="p">[</span><span class="n">y</span><span class="p">],</span> <span class="s1">&#39;o&#39;</span><span class="p">)</span>
<span class="n">xticks</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="n">ct2</span><span class="p">)</span>
<span class="n">xtickslabels</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">lhs</span><span class="p">)</span>
<span class="k">for</span> <span class="n">ct2</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</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">fs1</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="n">ct2</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="n">fs2</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="n">ct2</span><span class="p">]</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">fs1</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span>
<span class="n">dest</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">fs2</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span>
<span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">([</span><span class="n">x</span><span class="o">+</span><span class="n">ct2</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="n">x</span><span class="o">+</span><span class="n">ct2</span><span class="p">],</span> <span class="p">[</span><span class="n">y</span><span class="p">,</span><span class="n">dest</span><span class="p">],</span><span class="s1">&#39;-&#39;</span><span class="p">)</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span><span class="o">.</span><span class="n">centroid</span>
<span class="k">for</span> <span class="n">rhs</span> <span class="ow">in</span> <span class="n">flrg</span><span class="o">.</span><span class="n">RHS</span><span class="p">:</span>
<span class="n">dest</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">rhs</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span>
<span class="n">ax</span><span class="o">.</span><span class="n">arrow</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">model</span><span class="o">.</span><span class="n">order</span> <span class="o">-</span><span class="mi">1</span> <span class="o">+</span> <span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="n">dest</span> <span class="o">-</span> <span class="n">y</span><span class="p">,</span> <span class="c1"># length_includes_head=True,</span>
<span class="n">head_width</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span> <span class="n">head_length</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="s1">&#39;full&#39;</span><span class="p">,</span> <span class="n">overhang</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
<span class="n">fc</span><span class="o">=</span><span class="s1">&#39;k&#39;</span><span class="p">,</span> <span class="n">ec</span><span class="o">=</span><span class="s1">&#39;k&#39;</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_xticks</span><span class="p">(</span><span class="n">xticks</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_xticklabels</span><span class="p">(</span><span class="n">xtickslabels</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="n">rules_by_axis</span><span class="o">*</span><span class="n">model</span><span class="o">.</span><span class="n">order</span><span class="o">+</span><span class="mi">1</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">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span></div>
<div class="viewcode-block" id="draw_sets_on_axis"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Util.draw_sets_on_axis">[docs]</a><span class="k">def</span> <span class="nf">draw_sets_on_axis</span><span class="p">(</span><span class="n">axis</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">size</span><span class="p">):</span>
<span class="k">if</span> <span class="n">axis</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">fig</span><span class="p">,</span> <span class="n">axis</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">1</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="n">size</span><span class="p">)</span>
<span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">):</span>
<span class="n">fs</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">key</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="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="n">fs</span><span class="o">.</span><span class="n">parameters</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">fs</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="n">axis</span><span class="o">.</span><span class="n">axhline</span><span class="p">(</span><span class="n">fs</span><span class="o">.</span><span class="n">centroid</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="s2">&quot;lightgray&quot;</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.5</span><span class="p">)</span>
<span class="n">axis</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">model</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">)])</span>
<span class="n">axis</span><span class="o">.</span><span class="n">set_xticks</span><span class="p">(</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">model</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">)))</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;&#39;</span><span class="p">]</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">)</span>
<span class="n">axis</span><span class="o">.</span><span class="n">set_xticklabels</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>
<span class="n">axis</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">([</span><span class="n">model</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">min</span><span class="p">,</span> <span class="n">model</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">max</span><span class="p">])</span>
<span class="n">axis</span><span class="o">.</span><span class="n">set_yticks</span><span class="p">([</span><span class="n">model</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">model</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">])</span>
<span class="n">axis</span><span class="o">.</span><span class="n">set_yticklabels</span><span class="p">([</span><span class="nb">str</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span> <span class="o">+</span> <span class="s2">&quot; - &quot;</span> <span class="o">+</span> <span class="n">k</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">model</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">])</span></div>
<span class="n">current_milli_time</span> <span class="o">=</span> <span class="k">lambda</span><span class="p">:</span> <span class="nb">int</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">*</span> <span class="mi">1000</span><span class="p">))</span>
<div class="viewcode-block" id="uniquefilename"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Util.uniquefilename">[docs]</a><span class="k">def</span> <span class="nf">uniquefilename</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
<span class="k">if</span> <span class="s1">&#39;.&#39;</span> <span class="ow">in</span> <span class="n">name</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">name</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="k">return</span> <span class="n">tmp</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">current_milli_time</span><span class="p">())</span> <span class="o">+</span> <span class="s1">&#39;.&#39;</span> <span class="o">+</span> <span class="n">tmp</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="n">name</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">current_milli_time</span><span class="p">())</span></div>
<div class="viewcode-block" id="show_and_save_image"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Util.show_and_save_image">[docs]</a><span class="k">def</span> <span class="nf">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">flag</span><span class="p">,</span> <span class="n">lgd</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Show and image and save on file</span>
<span class="sd"> :param fig: Matplotlib Figure object</span>
<span class="sd"> :param file: filename to save the picture</span>
<span class="sd"> :param flag: if True the image will be saved</span>
<span class="sd"> :param lgd: legend</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
<span class="k">if</span> <span class="n">flag</span><span class="p">:</span>
<span class="k">if</span> <span class="n">lgd</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">fig</span><span class="o">.</span><span class="n">savefig</span><span class="p">(</span><span class="n">file</span><span class="p">,</span> <span class="n">additional_artists</span><span class="o">=</span><span class="n">lgd</span><span class="p">,</span><span class="n">bbox_inches</span><span class="o">=</span><span class="s1">&#39;tight&#39;</span><span class="p">)</span> <span class="c1">#bbox_extra_artists=(lgd,), )</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">fig</span><span class="o">.</span><span class="n">savefig</span><span class="p">(</span><span class="n">file</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="n">fig</span><span class="p">)</span></div>
<div class="viewcode-block" id="enumerate2"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Util.enumerate2">[docs]</a><span class="k">def</span> <span class="nf">enumerate2</span><span class="p">(</span><span class="n">xs</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">step</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
<span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">xs</span><span class="p">:</span>
<span class="k">yield</span> <span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="n">start</span> <span class="o">+=</span> <span class="n">step</span></div>
<div class="viewcode-block" id="sliding_window"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Util.sliding_window">[docs]</a><span class="k">def</span> <span class="nf">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="o">=</span><span class="mf">0.8</span><span class="p">,</span> <span class="n">inc</span><span class="o">=</span><span class="mf">0.1</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 method of cross validation for time series</span>
<span class="sd"> :param data: the entire dataset</span>
<span class="sd"> :param windowsize: window size</span>
<span class="sd"> :param train: percentual of the window size will be used for training the models</span>
<span class="sd"> :param inc: percentual of data used for slide the window</span>
<span class="sd"> :return: window count, training set, test set</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">multivariate</span> <span class="o">=</span> <span class="kc">True</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">)</span> <span class="k">else</span> <span class="kc">False</span>
<span class="n">l</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="k">if</span> <span class="ow">not</span> <span class="n">multivariate</span> <span class="k">else</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">index</span><span class="p">)</span>
<span class="n">ttrain</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">windowsize</span> <span class="o">*</span> <span class="n">train</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
<span class="n">ic</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">round</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="mi">0</span><span class="p">))</span>
<span class="n">progressbar</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="n">rng</span> <span class="o">=</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="o">-</span><span class="n">windowsize</span><span class="o">+</span><span class="n">ic</span><span class="p">,</span><span class="n">ic</span><span class="p">)</span>
<span class="k">if</span> <span class="n">progressbar</span><span class="p">:</span>
<span class="kn">from</span> <span class="nn">tqdm</span> <span class="kn">import</span> <span class="n">tqdm</span>
<span class="n">rng</span> <span class="o">=</span> <span class="n">tqdm</span><span class="p">(</span><span class="n">rng</span><span class="p">)</span>
<span class="k">for</span> <span class="n">count</span> <span class="ow">in</span> <span class="n">rng</span><span class="p">:</span>
<span class="k">if</span> <span class="n">count</span> <span class="o">+</span> <span class="n">windowsize</span> <span class="o">&gt;</span> <span class="n">l</span><span class="p">:</span>
<span class="n">_end</span> <span class="o">=</span> <span class="n">l</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">_end</span> <span class="o">=</span> <span class="n">count</span> <span class="o">+</span> <span class="n">windowsize</span>
<span class="k">if</span> <span class="n">multivariate</span><span class="p">:</span>
<span class="k">yield</span> <span class="p">(</span><span class="n">count</span><span class="p">,</span> <span class="n">data</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="n">count</span><span class="p">:</span> <span class="n">count</span> <span class="o">+</span> <span class="n">ttrain</span><span class="p">],</span> <span class="n">data</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="n">count</span> <span class="o">+</span> <span class="n">ttrain</span><span class="p">:</span> <span class="n">_end</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">yield</span> <span class="p">(</span><span class="n">count</span><span class="p">,</span> <span class="n">data</span><span class="p">[</span><span class="n">count</span> <span class="p">:</span> <span class="n">count</span> <span class="o">+</span> <span class="n">ttrain</span><span class="p">],</span> <span class="n">data</span><span class="p">[</span><span class="n">count</span> <span class="o">+</span> <span class="n">ttrain</span> <span class="p">:</span> <span class="n">_end</span><span class="p">]</span> <span class="p">)</span></div>
<div class="viewcode-block" id="persist_obj"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Util.persist_obj">[docs]</a><span class="k">def</span> <span class="nf">persist_obj</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">file</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Persist an object on filesystem. This function depends on Dill package</span>
<span class="sd"> :param obj: object on memory</span>
<span class="sd"> :param file: file name to store the object</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">dill</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">file</span><span class="p">,</span> <span class="s1">&#39;wb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">_file</span><span class="p">:</span>
<span class="n">dill</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">_file</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="s2">&quot;File </span><span class="si">{}</span><span class="s2"> could not be saved due exception </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">file</span><span class="p">,</span> <span class="n">ex</span><span class="p">))</span></div>
<div class="viewcode-block" id="load_obj"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Util.load_obj">[docs]</a><span class="k">def</span> <span class="nf">load_obj</span><span class="p">(</span><span class="n">file</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Load to memory an object stored filesystem. This function depends on Dill package</span>
<span class="sd"> :param file: file name where the object is stored</span>
<span class="sd"> :return: object</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">dill</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">file</span><span class="p">,</span> <span class="s1">&#39;rb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">_file</span><span class="p">:</span>
<span class="n">obj</span> <span class="o">=</span> <span class="n">dill</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">_file</span><span class="p">)</span>
<span class="k">return</span> <span class="n">obj</span></div>
<div class="viewcode-block" id="persist_env"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Util.persist_env">[docs]</a><span class="k">def</span> <span class="nf">persist_env</span><span class="p">(</span><span class="n">file</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Persist an entire environment on file. This function depends on Dill package</span>
<span class="sd"> :param file: file name to store the environment</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">dill</span>
<span class="n">dill</span><span class="o">.</span><span class="n">dump_session</span><span class="p">(</span><span class="n">file</span><span class="p">)</span></div>
<div class="viewcode-block" id="load_env"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Util.load_env">[docs]</a><span class="k">def</span> <span class="nf">load_env</span><span class="p">(</span><span class="n">file</span><span class="p">):</span>
<span class="kn">import</span> <span class="nn">dill</span>
<span class="n">dill</span><span class="o">.</span><span class="n">load_session</span><span class="p">(</span><span class="n">file</span><span class="p">)</span></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.common.Util</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,750 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.common.fts &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.common.fts</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.common.fts</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">SortedCollection</span><span class="p">,</span> <span class="n">tree</span><span class="p">,</span> <span class="n">Util</span>
<div class="viewcode-block" id="FTS"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS">[docs]</a><span class="k">class</span> <span class="nc">FTS</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Fuzzy Time Series object model</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</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"> Create a Fuzzy Time Series model</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span> <span class="o">=</span> <span class="p">{}</span>
<span class="sd">&quot;&quot;&quot;The list of Fuzzy Logical Relationship Groups - FLRG&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</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;order&#39;</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;A integer with the model order (number of past lags are used on forecasting)&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</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;name&#39;</span><span class="p">,</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;A string with a short name or alias for the model&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</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;name&#39;</span><span class="p">,</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;A string with the model name&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</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;name&#39;</span><span class="p">,</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;A string with the model detailed information&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_wrapper</span> <span class="o">=</span> <span class="kc">False</span>
<span class="sd">&quot;&quot;&quot;Indicates that this model is a wrapper for other(s) method(s)&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">False</span>
<span class="sd">&quot;&quot;&quot;A boolean value indicating if the model support orders greater than 1, default: False&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_order</span> <span class="o">=</span> <span class="mi">1</span>
<span class="sd">&quot;&quot;&quot;In high order models, this integer value indicates the minimal order supported for the model, default: 1&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_seasonality</span> <span class="o">=</span> <span class="kc">False</span>
<span class="sd">&quot;&quot;&quot;A boolean value indicating if the model supports seasonal indexers, default: False&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_point_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="sd">&quot;&quot;&quot;A boolean value indicating if the model supports point forecasting, default: True&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_interval_forecasting</span> <span class="o">=</span> <span class="kc">False</span>
<span class="sd">&quot;&quot;&quot;A boolean value indicating if the model supports interval forecasting, default: False&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_probability_forecasting</span> <span class="o">=</span> <span class="kc">False</span>
<span class="sd">&quot;&quot;&quot;A boolean value indicating if the model support probabilistic forecasting, default: False&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_multivariate</span> <span class="o">=</span> <span class="kc">False</span>
<span class="sd">&quot;&quot;&quot;A boolean value indicating if the model support multivariate time series (Pandas DataFrame), default: False&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_clustered</span> <span class="o">=</span> <span class="kc">False</span>
<span class="sd">&quot;&quot;&quot;A boolean value indicating if the model support multivariate time series (Pandas DataFrame), but works like </span>
<span class="sd"> a monovariate method, default: False&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">dump</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transformations</span> <span class="o">=</span> <span class="p">[]</span>
<span class="sd">&quot;&quot;&quot;A list with the data transformations (common.Transformations) applied on model pre and post processing, default: []&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transformations_param</span> <span class="o">=</span> <span class="p">[]</span>
<span class="sd">&quot;&quot;&quot;A list with the specific parameters for each data transformation&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">original_max</span> <span class="o">=</span> <span class="mi">0</span>
<span class="sd">&quot;&quot;&quot;A float with the upper limit of the Universe of Discourse, the maximal value found on training data&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">original_min</span> <span class="o">=</span> <span class="mi">0</span>
<span class="sd">&quot;&quot;&quot;A float with the lower limit of the Universe of Discourse, the minimal value found on training data&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner</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;partitioner&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;A pyFTS.partitioners.Partitioner object with the Universe of Discourse partitioner used on the model. This is a mandatory dependecy. &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span> <span class="o">!=</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">sets</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span>
<span class="bp">self</span><span class="o">.</span><span class="n">auto_update</span> <span class="o">=</span> <span class="kc">False</span>
<span class="sd">&quot;&quot;&quot;A boolean value indicating that model is incremental&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">benchmark_only</span> <span class="o">=</span> <span class="kc">False</span>
<span class="sd">&quot;&quot;&quot;A boolean value indicating a façade for external (non-FTS) model used on benchmarks or ensembles.&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</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="s2">&quot;indexer&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;An pyFTS.models.seasonal.Indexer object for indexing the time series data&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">uod_clip</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;uod_clip&quot;</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;Flag indicating if the test data will be clipped inside the training Universe of Discourse&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">alpha_cut</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;alpha_cut&quot;</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;A float with the minimal membership to be considered on fuzzyfication process&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">lags</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;lags&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;The list of lag indexes for high order models&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span>
<span class="sd">&quot;&quot;&quot;A integer indicating the largest lag used by the model. This value also indicates the minimum number of past lags </span>
<span class="sd"> needed to forecast a single step ahead&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">log</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">([],</span><span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;Datetime&quot;</span><span class="p">,</span><span class="s2">&quot;Operation&quot;</span><span class="p">,</span><span class="s2">&quot;Value&quot;</span><span class="p">])</span>
<span class="sd">&quot;&quot;&quot;&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_time_variant</span> <span class="o">=</span> <span class="kc">False</span>
<span class="sd">&quot;&quot;&quot;A boolean value indicating if this model is time variant&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">standard_horizon</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;standard_horizon&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;Standard forecasting horizon (Default: 1)&quot;&quot;&quot;</span>
<div class="viewcode-block" id="FTS.fuzzy"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.fuzzy">[docs]</a> <span class="k">def</span> <span class="nf">fuzzy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Fuzzify a data point</span>
<span class="sd"> :param data: data point</span>
<span class="sd"> :return: maximum membership fuzzy set</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">best</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;fuzzyset&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="s2">&quot;membership&quot;</span><span class="p">:</span> <span class="mf">0.0</span><span class="p">}</span>
<span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">:</span>
<span class="n">fset</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">f</span><span class="p">]</span>
<span class="k">if</span> <span class="n">best</span><span class="p">[</span><span class="s2">&quot;membership&quot;</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">fset</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">data</span><span class="p">):</span>
<span class="n">best</span><span class="p">[</span><span class="s2">&quot;fuzzyset&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">fset</span><span class="o">.</span><span class="n">name</span>
<span class="n">best</span><span class="p">[</span><span class="s2">&quot;membership&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">fset</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="k">return</span> <span class="n">best</span></div>
<div class="viewcode-block" id="FTS.clip_uod"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.clip_uod">[docs]</a> <span class="k">def</span> <span class="nf">clip_uod</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">uod_clip</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">clip</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">min</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">max</span><span class="p">)</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">uod_clip</span><span class="p">:</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">clip</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_min</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_max</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ndata</span></div>
<div class="viewcode-block" id="FTS.predict"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.predict">[docs]</a> <span class="k">def</span> <span class="nf">predict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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"> Forecast using trained model</span>
<span class="sd"> :param data: time series with minimal length to the order of the model</span>
<span class="sd"> :keyword type: the forecasting type, one of these values: point(default), interval, distribution or multivariate.</span>
<span class="sd"> :keyword steps_ahead: The forecasting path H, i. e., tell the model to forecast from t+1 to t+H.</span>
<span class="sd"> :keyword step_to: The forecasting step H, i. e., tell the model to forecast to t+H for each input sample </span>
<span class="sd"> :keyword start_at: in the multi step forecasting, the index of the data where to start forecasting (default value: 0)</span>
<span class="sd"> :keyword distributed: boolean, indicate if the forecasting procedure will be distributed in a dispy cluster (default value: False)</span>
<span class="sd"> :keyword nodes: a list with the dispy cluster nodes addresses</span>
<span class="sd"> :keyword explain: try to explain, step by step, the one-step-ahead point forecasting result given the input data. (default value: False)</span>
<span class="sd"> :keyword generators: for multivariate methods on multi step ahead forecasting, generators is a dict where the keys</span>
<span class="sd"> are the dataframe columun names (except the target_variable) and the values are lambda functions that</span>
<span class="sd"> accept one value (the actual value of the variable) and return the next value or trained FTS</span>
<span class="sd"> models that accept the actual values and forecast new ones.</span>
<span class="sd"> :return: a numpy array with the forecasted data</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">copy</span>
<span class="n">kw</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">kwargs</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_multivariate</span><span class="p">:</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="n">data</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">apply_transformations</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">clip_uod</span><span class="p">(</span><span class="n">ndata</span><span class="p">)</span>
<span class="k">if</span> <span class="s1">&#39;distributed&#39;</span> <span class="ow">in</span> <span class="n">kw</span><span class="p">:</span>
<span class="n">distributed</span> <span class="o">=</span> <span class="n">kw</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="k">else</span><span class="p">:</span>
<span class="n">distributed</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">if</span> <span class="s1">&#39;type&#39;</span> <span class="ow">in</span> <span class="n">kw</span><span class="p">:</span>
<span class="nb">type</span> <span class="o">=</span> <span class="n">kw</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;type&quot;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="nb">type</span> <span class="o">=</span> <span class="s1">&#39;point&#39;</span>
<span class="k">if</span> <span class="n">distributed</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="n">distributed</span> <span class="o">==</span> <span class="kc">False</span><span class="p">:</span>
<span class="n">steps_ahead</span> <span class="o">=</span> <span class="n">kw</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;steps_ahead&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="n">step_to</span> <span class="o">=</span> <span class="n">kw</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;step_to&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">steps_ahead</span> <span class="o">==</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">step_to</span> <span class="o">==</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">steps_ahead</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">or</span> <span class="n">step_to</span> <span class="o">==</span><span class="mi">1</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">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</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">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_interval</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</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">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_distribution</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">)</span>
<span class="k">elif</span> <span class="nb">type</span> <span class="o">==</span> <span class="s1">&#39;multivariate&#39;</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_multivariate</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">step_to</span> <span class="o">==</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">steps_ahead</span> <span class="o">&gt;</span> <span class="mi">1</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">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_ahead</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">steps_ahead</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</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">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_ahead_interval</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">steps_ahead</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</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">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_ahead_distribution</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">steps_ahead</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">)</span>
<span class="k">elif</span> <span class="nb">type</span> <span class="o">==</span> <span class="s1">&#39;multivariate&#39;</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_ahead_multivariate</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">steps_ahead</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">step_to</span> <span class="o">&gt;</span> <span class="mi">1</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">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_step</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">step_to</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">&#39;This model only perform point step ahead forecasts!&#39;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="p">[</span><span class="s1">&#39;point&#39;</span><span class="p">,</span> <span class="s1">&#39;interval&#39;</span><span class="p">,</span> <span class="s1">&#39;distribution&#39;</span><span class="p">,</span> <span class="s1">&#39;multivariate&#39;</span><span class="p">]</span><span class="o">.</span><span class="fm">__contains__</span><span class="p">(</span><span class="nb">type</span><span class="p">):</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;The argument </span><span class="se">\&#39;</span><span class="s1">type</span><span class="se">\&#39;</span><span class="s1"> has an unknown value.&#39;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="n">distributed</span> <span class="o">==</span> <span class="s1">&#39;dispy&#39;</span><span class="p">:</span>
<span class="kn">from</span> <span class="nn">pyFTS.distributed</span> <span class="kn">import</span> <span class="n">dispy</span>
<span class="n">nodes</span> <span class="o">=</span> <span class="n">kw</span><span class="o">.</span><span class="n">pop</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">num_batches</span> <span class="o">=</span> <span class="n">kw</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;num_batches&#39;</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">dispy</span><span class="o">.</span><span class="n">distributed_predict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kw</span><span class="p">,</span> <span class="n">nodes</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="n">num_batches</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">distributed</span> <span class="o">==</span> <span class="s1">&#39;spark&#39;</span><span class="p">:</span>
<span class="kn">from</span> <span class="nn">pyFTS.distributed</span> <span class="kn">import</span> <span class="n">spark</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">spark</span><span class="o">.</span><span class="n">distributed_predict</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">ndata</span><span class="p">,</span> <span class="n">model</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_multivariate</span><span class="p">:</span>
<span class="n">kw</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">type</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">apply_inverse_transformations</span><span class="p">(</span><span class="n">ret</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="p">[</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">-</span> <span class="mi">1</span><span class="p">:]],</span> <span class="o">**</span><span class="n">kw</span><span class="p">)</span>
<span class="k">if</span> <span class="s1">&#39;statistics&#39;</span> <span class="ow">in</span> <span class="n">kw</span><span class="p">:</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;statistics&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">kw</span><span class="p">[</span><span class="s1">&#39;statistics&#39;</span><span class="p">]</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="FTS.forecast"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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"> Point forecast one step ahead</span>
<span class="sd"> :param data: time series data with the minimal length equal to the max_lag of the model</span>
<span class="sd"> :param kwargs: model specific parameters</span>
<span class="sd"> :return: a list with the forecasted values</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">&#39;This model do not perform one step ahead point forecasts!&#39;</span><span class="p">)</span></div>
<div class="viewcode-block" id="FTS.forecast_interval"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.forecast_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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"> Interval forecast one step ahead</span>
<span class="sd"> :param data: time series data with the minimal length equal to the max_lag of the model</span>
<span class="sd"> :param kwargs: model specific parameters</span>
<span class="sd"> :return: a list with the prediction intervals</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">&#39;This model do not perform one step ahead interval forecasts!&#39;</span><span class="p">)</span></div>
<div class="viewcode-block" id="FTS.forecast_distribution"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.forecast_distribution">[docs]</a> <span class="k">def</span> <span class="nf">forecast_distribution</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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"> Probabilistic forecast one step ahead</span>
<span class="sd"> :param data: time series data with the minimal length equal to the max_lag of the model</span>
<span class="sd"> :param kwargs: model specific parameters</span>
<span class="sd"> :return: a list with probabilistic.ProbabilityDistribution objects representing the forecasted Probability Distributions</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">&#39;This model do not perform one step ahead distribution forecasts!&#39;</span><span class="p">)</span></div>
<div class="viewcode-block" id="FTS.forecast_multivariate"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.forecast_multivariate">[docs]</a> <span class="k">def</span> <span class="nf">forecast_multivariate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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"> Multivariate forecast one step ahead</span>
<span class="sd"> :param data: Pandas dataframe with one column for each variable and with the minimal length equal to the max_lag of the model</span>
<span class="sd"> :param kwargs: model specific parameters</span>
<span class="sd"> :return: a Pandas Dataframe object representing the forecasted values for each variable</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">&#39;This model do not perform one step ahead multivariate forecasts!&#39;</span><span class="p">)</span></div>
<div class="viewcode-block" id="FTS.forecast_ahead"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.forecast_ahead">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</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"> Point forecast from 1 to H steps ahead, where H is given by the steps parameter</span>
<span class="sd"> :param data: time series data with the minimal length equal to the max_lag of the model</span>
<span class="sd"> :param steps: the number of steps ahead to forecast (default: 1)</span>
<span class="sd"> :keyword start_at: in the multi step forecasting, the index of the data where to start forecasting (default: 0)</span>
<span class="sd"> :return: a list with the forecasted values</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span>
<span class="k">return</span> <span class="n">data</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</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">data</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
<span class="n">start</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;start_at&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">data</span><span class="p">[:</span><span class="n">start</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">max_lag</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="n">start</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="n">steps</span><span class="o">+</span><span class="n">start</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">ret</span><span class="p">[</span><span class="n">k</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span><span class="n">k</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="nb">isinstance</span><span class="p">(</span><span class="n">tmp</span><span class="p">,(</span><span class="nb">list</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">tmp</span> <span class="o">=</span> <span class="n">tmp</span><span class="p">[</span><span class="o">-</span><span class="mi">1</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">tmp</span><span class="p">)</span>
<span class="n">data</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span><span class="p">[</span><span class="o">-</span><span class="n">steps</span><span class="p">:]</span></div>
<div class="viewcode-block" id="FTS.forecast_ahead_interval"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.forecast_ahead_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</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"> Interval forecast from 1 to H steps ahead, where H is given by the steps parameter</span>
<span class="sd"> :param data: time series data with the minimal length equal to the max_lag of the model</span>
<span class="sd"> :param steps: the number of steps ahead to forecast</span>
<span class="sd"> :keyword start_at: in the multi step forecasting, the index of the data where to start forecasting (default: 0)</span>
<span class="sd"> :return: a list with the forecasted intervals</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">&#39;This model do not perform multi step ahead interval forecasts!&#39;</span><span class="p">)</span></div>
<div class="viewcode-block" id="FTS.forecast_ahead_distribution"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.forecast_ahead_distribution">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_distribution</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</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"> Probabilistic forecast from 1 to H steps ahead, where H is given by the steps parameter</span>
<span class="sd"> :param data: time series data with the minimal length equal to the max_lag of the model</span>
<span class="sd"> :param steps: the number of steps ahead to forecast</span>
<span class="sd"> :keyword start_at: in the multi step forecasting, the index of the data where to start forecasting (default: 0)</span>
<span class="sd"> :return: a list with the forecasted Probability Distributions</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">&#39;This model do not perform multi step ahead distribution forecasts!&#39;</span><span class="p">)</span></div>
<div class="viewcode-block" id="FTS.forecast_ahead_multivariate"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.forecast_ahead_multivariate">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_multivariate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</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"> Multivariate forecast n step ahead</span>
<span class="sd"> :param data: Pandas dataframe with one column for each variable and with the minimal length equal to the max_lag of the model</span>
<span class="sd"> :param steps: the number of steps ahead to forecast</span>
<span class="sd"> :keyword start_at: in the multi step forecasting, the index of the data where to start forecasting (default: 0)</span>
<span class="sd"> :return: a Pandas Dataframe object representing the forecasted values for each variable</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">&#39;This model do not perform one step ahead multivariate forecasts!&#39;</span><span class="p">)</span></div>
<div class="viewcode-block" id="FTS.forecast_step"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.forecast_step">[docs]</a> <span class="k">def</span> <span class="nf">forecast_step</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">step</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"> Point forecast for H steps ahead, where H is given by the step parameter</span>
<span class="sd"> :param data: time series data with the minimal length equal to the max_lag of the model</span>
<span class="sd"> :param step: the forecasting horizon (default: 1)</span>
<span class="sd"> :keyword start_at: in the multi step forecasting, the index of the data where to start forecasting (default: 0)</span>
<span class="sd"> :return: a list with the forecasted values</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">l</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="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="n">l</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span>
<span class="k">return</span> <span class="n">data</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</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">data</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
<span class="n">start</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;start_at&#39;</span><span class="p">,</span><span class="mi">0</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="n">start</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span><span class="n">k</span><span class="p">]</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_ahead</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">step</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="nb">isinstance</span><span class="p">(</span><span class="n">tmp</span><span class="p">,(</span><span class="nb">list</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">tmp</span> <span class="o">=</span> <span class="n">tmp</span><span class="p">[</span><span class="o">-</span><span class="mi">1</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">tmp</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="FTS.train"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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"> Method specific parameter fitting</span>
<span class="sd"> :param data: training time series data</span>
<span class="sd"> :param kwargs: Method specific parameters</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">pass</span></div>
<div class="viewcode-block" id="FTS.fit"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.fit">[docs]</a> <span class="k">def</span> <span class="nf">fit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</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"> Fit the model&#39;s parameters based on the training data.</span>
<span class="sd"> :param ndata: training time series data</span>
<span class="sd"> :param kwargs:</span>
<span class="sd"> :keyword num_batches: split the training data in num_batches to save memory during the training process</span>
<span class="sd"> :keyword save_model: save final model on disk</span>
<span class="sd"> :keyword batch_save: save the model between each batch</span>
<span class="sd"> :keyword file_path: path to save the model</span>
<span class="sd"> :keyword distributed: boolean, indicate if the training procedure will be distributed in a dispy cluster</span>
<span class="sd"> :keyword nodes: a list with the dispy cluster nodes addresses</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">datetime</span><span class="o">,</span> <span class="nn">copy</span>
<span class="n">kw</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">kwargs</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_multivariate</span><span class="p">:</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">ndata</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">apply_transformations</span><span class="p">(</span><span class="n">ndata</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">original_min</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmin</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">original_max</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmax</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="k">if</span> <span class="s1">&#39;partitioner&#39;</span> <span class="ow">in</span> <span class="n">kw</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span> <span class="o">=</span> <span class="n">kw</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;partitioner&#39;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_multivariate</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_wrapper</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">benchmark_only</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;Fuzzy sets were not provided for the model. Use &#39;partitioner&#39; parameter. &quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="s1">&#39;order&#39;</span> <span class="ow">in</span> <span class="n">kw</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="o">=</span> <span class="n">kw</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;order&#39;</span><span class="p">)</span>
<span class="n">dump</span> <span class="o">=</span> <span class="n">kw</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;dump&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="n">num_batches</span> <span class="o">=</span> <span class="n">kw</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;num_batches&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="n">save</span> <span class="o">=</span> <span class="n">kw</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;save_model&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span> <span class="c1"># save model on disk</span>
<span class="n">batch_save</span> <span class="o">=</span> <span class="n">kw</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;batch_save&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span> <span class="c1">#save model between batches</span>
<span class="n">file_path</span> <span class="o">=</span> <span class="n">kw</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;file_path&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="n">distributed</span> <span class="o">=</span> <span class="n">kw</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="k">if</span> <span class="n">distributed</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">distributed</span><span class="p">:</span>
<span class="k">if</span> <span class="n">num_batches</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">num_batches</span> <span class="o">=</span> <span class="mi">10</span>
<span class="k">if</span> <span class="n">distributed</span> <span class="o">==</span> <span class="s1">&#39;dispy&#39;</span><span class="p">:</span>
<span class="kn">from</span> <span class="nn">pyFTS.distributed</span> <span class="kn">import</span> <span class="n">dispy</span>
<span class="n">nodes</span> <span class="o">=</span> <span class="n">kw</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;nodes&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="n">train_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;train_method&#39;</span><span class="p">,</span> <span class="n">dispy</span><span class="o">.</span><span class="n">simple_model_train</span><span class="p">)</span>
<span class="n">dispy</span><span class="o">.</span><span class="n">distributed_train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">train_method</span><span class="p">,</span> <span class="n">nodes</span><span class="p">,</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">),</span> <span class="n">data</span><span class="p">,</span> <span class="n">num_batches</span><span class="p">,</span> <span class="p">{},</span>
<span class="o">**</span><span class="n">kw</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">distributed</span> <span class="o">==</span> <span class="s1">&#39;spark&#39;</span><span class="p">:</span>
<span class="kn">from</span> <span class="nn">pyFTS.distributed</span> <span class="kn">import</span> <span class="n">spark</span>
<span class="n">url</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;url&#39;</span><span class="p">,</span> <span class="s1">&#39;spark://127.0.0.1:7077&#39;</span><span class="p">)</span>
<span class="n">app</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;app&#39;</span><span class="p">,</span> <span class="s1">&#39;pyFTS&#39;</span><span class="p">)</span>
<span class="n">spark</span><span class="o">.</span><span class="n">distributed_train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">url</span><span class="o">=</span><span class="n">url</span><span class="p">,</span> <span class="n">app</span><span class="o">=</span><span class="n">app</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="n">dump</span> <span class="o">==</span> <span class="s1">&#39;time&#39;</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;[{0: %H:%M:%S}] Start training&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()))</span>
<span class="k">if</span> <span class="n">num_batches</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_wrapper</span><span class="p">:</span>
<span class="n">n</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="n">batch_size</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">n</span> <span class="o">/</span> <span class="n">num_batches</span><span class="p">)</span>
<span class="n">bcount</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">rng</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">batch_size</span><span class="p">)</span>
<span class="k">if</span> <span class="n">dump</span> <span class="o">==</span> <span class="s1">&#39;tqdm&#39;</span><span class="p">:</span>
<span class="kn">from</span> <span class="nn">tqdm</span> <span class="kn">import</span> <span class="n">tqdm</span>
<span class="n">rng</span> <span class="o">=</span> <span class="n">tqdm</span><span class="p">(</span><span class="n">rng</span><span class="p">)</span>
<span class="k">for</span> <span class="n">ct</span> <span class="ow">in</span> <span class="n">rng</span><span class="p">:</span>
<span class="k">if</span> <span class="n">dump</span> <span class="o">==</span> <span class="s1">&#39;time&#39;</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;[{0: %H:%M:%S}] Starting batch &quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">())</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">bcount</span><span class="p">))</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_multivariate</span><span class="p">:</span>
<span class="n">mdata</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="n">ct</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:</span><span class="n">ct</span> <span class="o">+</span> <span class="n">batch_size</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">mdata</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">ct</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="p">:</span> <span class="n">ct</span> <span class="o">+</span> <span class="n">batch_size</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">train</span><span class="p">(</span><span class="n">mdata</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">)</span>
<span class="k">if</span> <span class="n">batch_save</span><span class="p">:</span>
<span class="n">Util</span><span class="o">.</span><span class="n">persist_obj</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">file_path</span><span class="p">)</span>
<span class="k">if</span> <span class="n">dump</span> <span class="o">==</span> <span class="s1">&#39;time&#39;</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;[{0: %H:%M:%S}] Finish batch &quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">())</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">bcount</span><span class="p">))</span>
<span class="n">bcount</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</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="o">**</span><span class="n">kw</span><span class="p">)</span>
<span class="k">if</span> <span class="n">dump</span> <span class="o">==</span> <span class="s1">&#39;time&#39;</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;[{0: %H:%M:%S}] Finish training&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()))</span>
<span class="k">if</span> <span class="n">save</span><span class="p">:</span>
<span class="n">Util</span><span class="o">.</span><span class="n">persist_obj</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">file_path</span><span class="p">)</span></div>
<div class="viewcode-block" id="FTS.clone_parameters"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.clone_parameters">[docs]</a> <span class="k">def</span> <span class="nf">clone_parameters</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Import the parameters values from other model</span>
<span class="sd"> :param model: a model to clone the parameters</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">order</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">partitioner</span>
<span class="bp">self</span><span class="o">.</span><span class="n">lags</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">lags</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">shortname</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">name</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">detail</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">is_high_order</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_order</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">min_order</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_seasonality</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">has_seasonality</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_point_forecasting</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">has_point_forecasting</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_interval_forecasting</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">has_interval_forecasting</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_probability_forecasting</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">has_probability_forecasting</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_multivariate</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">is_multivariate</span>
<span class="bp">self</span><span class="o">.</span><span class="n">dump</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">dump</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transformations</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">transformations</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transformations_param</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">transformations_param</span>
<span class="bp">self</span><span class="o">.</span><span class="n">original_max</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">original_max</span>
<span class="bp">self</span><span class="o">.</span><span class="n">original_min</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">original_min</span>
<span class="bp">self</span><span class="o">.</span><span class="n">auto_update</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">auto_update</span>
<span class="bp">self</span><span class="o">.</span><span class="n">benchmark_only</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">benchmark_only</span>
<span class="bp">self</span><span class="o">.</span><span class="n">indexer</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">indexer</span></div>
<div class="viewcode-block" id="FTS.append_rule"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.append_rule">[docs]</a> <span class="k">def</span> <span class="nf">append_rule</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrg</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Append FLRG rule to the model</span>
<span class="sd"> :param flrg: rule</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span> <span class="o">=</span> <span class="n">flrg</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">RHS</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">set</span><span class="p">)):</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">flrg</span><span class="o">.</span><span class="n">RHS</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
<span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">RHS</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
<span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">flrg</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="n">value</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div>
<div class="viewcode-block" id="FTS.merge"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.merge">[docs]</a> <span class="k">def</span> <span class="nf">merge</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Merge the FLRG rules from other model</span>
<span class="sd"> :param model: source model</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">flrg</span> <span class="ow">in</span> <span class="n">model</span><span class="o">.</span><span class="n">flrgs</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="bp">self</span><span class="o">.</span><span class="n">append_rule</span><span class="p">(</span><span class="n">flrg</span><span class="p">)</span></div>
<div class="viewcode-block" id="FTS.append_transformation"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.append_transformation">[docs]</a> <span class="k">def</span> <span class="nf">append_transformation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">transformation</span><span class="p">):</span>
<span class="k">if</span> <span class="n">transformation</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transformations</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">transformation</span><span class="p">)</span></div>
<div class="viewcode-block" id="FTS.apply_transformations"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.apply_transformations">[docs]</a> <span class="k">def</span> <span class="nf">apply_transformations</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">updateUoD</span><span class="o">=</span><span class="kc">False</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"> Apply the data transformations for data preprocessing</span>
<span class="sd"> :param data: input data</span>
<span class="sd"> :param params: transformation parameters</span>
<span class="sd"> :param updateUoD:</span>
<span class="sd"> :param kwargs:</span>
<span class="sd"> :return: preprocessed data</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="n">data</span>
<span class="k">if</span> <span class="n">updateUoD</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">min</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">original_min</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">*</span> <span class="mf">1.1</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">original_min</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.9</span>
<span class="k">if</span> <span class="nb">max</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">original_max</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">*</span> <span class="mf">1.1</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">original_max</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.9</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transformations</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">if</span> <span class="n">params</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">params</span> <span class="o">=</span> <span class="p">[</span> <span class="kc">None</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">transformations</span><span class="p">]</span>
<span class="k">for</span> <span class="n">c</span><span class="p">,</span> <span class="n">t</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transformations</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">ndata</span> <span class="o">=</span> <span class="n">t</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">params</span><span class="p">[</span><span class="n">c</span><span class="p">],</span> <span class="p">)</span>
<span class="k">return</span> <span class="n">ndata</span></div>
<div class="viewcode-block" id="FTS.apply_inverse_transformations"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.apply_inverse_transformations">[docs]</a> <span class="k">def</span> <span class="nf">apply_inverse_transformations</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">params</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"> Apply the data transformations for data postprocessing</span>
<span class="sd"> :param data: input data</span>
<span class="sd"> :param params: transformation parameters</span>
<span class="sd"> :param updateUoD:</span>
<span class="sd"> :param kwargs:</span>
<span class="sd"> :return: postprocessed data</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transformations</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">if</span> <span class="n">params</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">params</span> <span class="o">=</span> <span class="p">[</span><span class="kc">None</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">transformations</span><span class="p">]</span>
<span class="k">for</span> <span class="n">c</span><span class="p">,</span> <span class="n">t</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transformations</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">ndata</span> <span class="o">=</span> <span class="n">t</span><span class="o">.</span><span class="n">inverse</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">params</span><span class="p">[</span><span class="n">c</span><span class="p">],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ndata</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="n">data</span></div>
<div class="viewcode-block" id="FTS.get_UoD"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.get_UoD">[docs]</a> <span class="k">def</span> <span class="nf">get_UoD</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Returns the interval of the known bounds of the universe of discourse (UoD), i. e.,</span>
<span class="sd"> the known minimum and maximum values of the time series.</span>
<span class="sd"> :return: A set with the lower and the upper bounds of the UoD</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">return</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">min</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">max</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">original_min</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_max</span><span class="p">)</span></div>
<div class="viewcode-block" id="FTS.offset"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.offset">[docs]</a> <span class="k">def</span> <span class="nf">offset</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Returns the number of lags to skip in the input test data in order to synchronize it with</span>
<span class="sd"> the forecasted values given by the predict function. This is necessary due to the order of the</span>
<span class="sd"> model, among other parameters.</span>
<span class="sd"> :return: An integer with the number of lags to skip</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="mi">1</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> String representation of the model</span>
<span class="sd"> :return: a string containing the name of the model and the learned rules</span>
<span class="sd"> (if the model was already trained)</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">+</span> <span class="s2">&quot;:</span><span class="se">\n</span><span class="s2">&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s1">&#39;common&#39;</span><span class="p">:</span>
<span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">key</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{0}{1}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">r</span><span class="p">]))</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{0}{1}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">r</span><span class="p">]))</span>
<span class="k">return</span> <span class="n">tmp</span>
<span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> The length (number of rules) of the model</span>
<span class="sd"> :return: number of rules</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">)</span>
<div class="viewcode-block" id="FTS.len_total"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.len_total">[docs]</a> <span class="k">def</span> <span class="nf">len_total</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Total length of the model, adding the number of terms in all rules</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="nb">sum</span><span class="p">([</span><span class="nb">len</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">])</span></div>
<div class="viewcode-block" id="FTS.reset_calculated_values"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.reset_calculated_values">[docs]</a> <span class="k">def</span> <span class="nf">reset_calculated_values</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Reset all pre-calculated values on the FLRG&#39;s</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">for</span> <span class="n">flrg</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="p">]</span><span class="o">.</span><span class="n">reset_calculated_values</span><span class="p">()</span></div>
<div class="viewcode-block" id="FTS.append_log"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.append_log">[docs]</a> <span class="k">def</span> <span class="nf">append_log</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">operation</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="k">pass</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.common.fts</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,271 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.distributed.dispy &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.distributed.dispy</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.distributed.dispy</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">dispy</span> <span class="k">as</span> <span class="nn">dispy</span><span class="o">,</span> <span class="nn">dispy.httpd</span><span class="o">,</span> <span class="nn">logging</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">Util</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<div class="viewcode-block" id="start_dispy_cluster"><a class="viewcode-back" href="../../../pyFTS.distributed.html#pyFTS.distributed.dispy.start_dispy_cluster">[docs]</a><span class="k">def</span> <span class="nf">start_dispy_cluster</span><span class="p">(</span><span class="n">method</span><span class="p">,</span> <span class="n">nodes</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Start a new Dispy cluster on &#39;nodes&#39; to execute the method &#39;method&#39;</span>
<span class="sd"> :param method: function to be executed on each cluster node</span>
<span class="sd"> :param nodes: list of node names or IP&#39;s.</span>
<span class="sd"> :return: the dispy cluster instance and the http_server for monitoring</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">cluster</span> <span class="o">=</span> <span class="n">dispy</span><span class="o">.</span><span class="n">JobCluster</span><span class="p">(</span><span class="n">method</span><span class="p">,</span> <span class="n">nodes</span><span class="o">=</span><span class="n">nodes</span><span class="p">,</span> <span class="n">loglevel</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">,</span> <span class="n">ping_interval</span><span class="o">=</span><span class="mi">1000</span><span class="p">)</span>
<span class="n">http_server</span> <span class="o">=</span> <span class="n">dispy</span><span class="o">.</span><span class="n">httpd</span><span class="o">.</span><span class="n">DispyHTTPServer</span><span class="p">(</span><span class="n">cluster</span><span class="p">)</span>
<span class="k">return</span> <span class="n">cluster</span><span class="p">,</span> <span class="n">http_server</span></div>
<div class="viewcode-block" id="stop_dispy_cluster"><a class="viewcode-back" href="../../../pyFTS.distributed.html#pyFTS.distributed.dispy.stop_dispy_cluster">[docs]</a><span class="k">def</span> <span class="nf">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="sd">&quot;&quot;&quot;</span>
<span class="sd"> Stop a dispy cluster and http_server</span>
<span class="sd"> :param cluster:</span>
<span class="sd"> :param http_server:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1">#cluster.wait() # wait for all jobs to finish</span>
<span class="n">cluster</span><span class="o">.</span><span class="n">print_status</span><span class="p">()</span>
<span class="n">http_server</span><span class="o">.</span><span class="n">shutdown</span><span class="p">()</span> <span class="c1"># this waits until browser gets all updates</span>
<span class="n">cluster</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div>
<div class="viewcode-block" id="get_number_of_cpus"><a class="viewcode-back" href="../../../pyFTS.distributed.html#pyFTS.distributed.dispy.get_number_of_cpus">[docs]</a><span class="k">def</span> <span class="nf">get_number_of_cpus</span><span class="p">(</span><span class="n">cluster</span><span class="p">):</span>
<span class="n">cpus</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">dispy_node</span> <span class="ow">in</span> <span class="n">cluster</span><span class="o">.</span><span class="n">status</span><span class="p">()</span><span class="o">.</span><span class="n">nodes</span><span class="p">:</span>
<span class="n">cpus</span> <span class="o">+=</span> <span class="n">dispy_node</span><span class="o">.</span><span class="n">cpus</span>
<span class="k">return</span> <span class="n">cpus</span></div>
<div class="viewcode-block" id="simple_model_train"><a class="viewcode-back" href="../../../pyFTS.distributed.html#pyFTS.distributed.dispy.simple_model_train">[docs]</a><span class="k">def</span> <span class="nf">simple_model_train</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">parameters</span><span class="p">):</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Cluster function that receives a FTS instance &#39;model&#39; and train using the &#39;data&#39; and &#39;parameters&#39;</span>
<span class="sd"> :param model: a FTS instance</span>
<span class="sd"> :param data: training dataset</span>
<span class="sd"> :param parameters: parameters for the training process</span>
<span class="sd"> :return: the trained model</span>
<span class="sd"> &quot;&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">model</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="o">**</span><span class="n">parameters</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">model</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="s1">&#39;training_time&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">_end</span> <span class="o">-</span> <span class="n">_start</span>
<span class="k">return</span> <span class="n">model</span></div>
<div class="viewcode-block" id="distributed_train"><a class="viewcode-back" href="../../../pyFTS.distributed.html#pyFTS.distributed.dispy.distributed_train">[docs]</a><span class="k">def</span> <span class="nf">distributed_train</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">train_method</span><span class="p">,</span> <span class="n">nodes</span><span class="p">,</span> <span class="n">fts_method</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">num_batches</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span>
<span class="n">train_parameters</span><span class="o">=</span><span class="p">{},</span> <span class="o">**</span><span class="n">kwargs</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="o">,</span> <span class="nn">datetime</span>
<span class="n">batch_save</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;batch_save&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span> <span class="c1"># save model between batches</span>
<span class="n">batch_save_interval</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;batch_save_interval&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">file_path</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_path&#39;</span><span class="p">,</span> <span class="kc">None</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">start_dispy_cluster</span><span class="p">(</span><span class="n">train_method</span><span class="p">,</span> <span class="n">nodes</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;[{0: %H:%M:%S}] Distrituted Train Started with </span><span class="si">{1}</span><span class="s2"> CPU&#39;s&quot;</span>
<span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">(),</span> <span class="n">get_number_of_cpus</span><span class="p">(</span><span class="n">cluster</span><span class="p">)))</span>
<span class="n">jobs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">n</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="n">batch_size</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">n</span> <span class="o">/</span> <span class="n">num_batches</span><span class="p">)</span>
<span class="n">bcount</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">for</span> <span class="n">ct</span> <span class="ow">in</span> <span class="nb">range</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">n</span><span class="p">,</span> <span class="n">batch_size</span><span class="p">):</span>
<span class="k">if</span> <span class="n">model</span><span class="o">.</span><span class="n">is_multivariate</span><span class="p">:</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="n">ct</span> <span class="o">-</span> <span class="n">model</span><span class="o">.</span><span class="n">order</span><span class="p">:</span><span class="n">ct</span> <span class="o">+</span> <span class="n">batch_size</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">ct</span> <span class="o">-</span> <span class="n">model</span><span class="o">.</span><span class="n">order</span><span class="p">:</span> <span class="n">ct</span> <span class="o">+</span> <span class="n">batch_size</span><span class="p">]</span>
<span class="n">tmp_model</span> <span class="o">=</span> <span class="n">fts_method</span><span class="p">()</span>
<span class="n">tmp_model</span><span class="o">.</span><span class="n">clone_parameters</span><span class="p">(</span><span class="n">model</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">tmp_model</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="n">train_parameters</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="n">bcount</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="n">bcount</span> <span class="o">+=</span> <span class="mi">1</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="nb">print</span><span class="p">(</span><span class="s2">&quot;[{0: %H:%M:%S}] Processing batch &quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">())</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">job</span><span class="o">.</span><span class="n">id</span><span class="p">))</span>
<span class="n">tmp</span> <span class="o">=</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">tmp</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">model</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>
<span class="k">if</span> <span class="s1">&#39;training_time&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">model</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">:</span>
<span class="n">model</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="s1">&#39;training_time&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">model</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="s1">&#39;training_time&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="s1">&#39;training_time&#39;</span><span class="p">])</span>
<span class="k">if</span> <span class="n">batch_save</span> <span class="ow">and</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="n">batch_save_interval</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">Util</span><span class="o">.</span><span class="n">persist_obj</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">file_path</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="n">job</span><span class="o">.</span><span class="n">exception</span><span class="p">)</span>
<span class="nb">print</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;[{0: %H:%M:%S}] Finished batch &quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">())</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">job</span><span class="o">.</span><span class="n">id</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;[{0: %H:%M:%S}] Distrituted Train Finished&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()))</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="k">return</span> <span class="n">model</span></div>
<div class="viewcode-block" id="simple_model_predict"><a class="viewcode-back" href="../../../pyFTS.distributed.html#pyFTS.distributed.dispy.simple_model_predict">[docs]</a><span class="k">def</span> <span class="nf">simple_model_predict</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">parameters</span><span class="p">):</span>
<span class="kn">import</span> <span class="nn">time</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">forecasts</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">parameters</span><span class="p">)</span>
<span class="n">_stop</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="k">return</span> <span class="n">forecasts</span><span class="p">,</span> <span class="n">_stop</span> <span class="o">-</span> <span class="n">_start</span></div>
<div class="viewcode-block" id="distributed_predict"><a class="viewcode-back" href="../../../pyFTS.distributed.html#pyFTS.distributed.dispy.distributed_predict">[docs]</a><span class="k">def</span> <span class="nf">distributed_predict</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">parameters</span><span class="p">,</span> <span class="n">nodes</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">num_batches</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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">cluster</span><span class="p">,</span> <span class="n">http_server</span> <span class="o">=</span> <span class="n">start_dispy_cluster</span><span class="p">(</span><span class="n">simple_model_predict</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">n</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="n">batch_size</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">n</span> <span class="o">/</span> <span class="n">num_batches</span><span class="p">)</span>
<span class="n">bcount</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">for</span> <span class="n">ct</span> <span class="ow">in</span> <span class="nb">range</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">n</span><span class="p">,</span> <span class="n">batch_size</span><span class="p">):</span>
<span class="k">if</span> <span class="n">model</span><span class="o">.</span><span class="n">is_multivariate</span><span class="p">:</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="n">ct</span> <span class="o">-</span> <span class="n">model</span><span class="o">.</span><span class="n">order</span><span class="p">:</span><span class="n">ct</span> <span class="o">+</span> <span class="n">batch_size</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">ct</span> <span class="o">-</span> <span class="n">model</span><span class="o">.</span><span class="n">order</span><span class="p">:</span> <span class="n">ct</span> <span class="o">+</span> <span class="n">batch_size</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">model</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="n">parameters</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="n">bcount</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="n">bcount</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="n">ret</span> <span class="o">=</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="n">tmp</span> <span class="o">=</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">tmp</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">if</span> <span class="n">job</span><span class="o">.</span><span class="n">id</span> <span class="o">&lt;</span> <span class="n">batch_size</span><span class="p">:</span>
<span class="n">ret</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="mi">0</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">ret</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="k">if</span> <span class="s1">&#39;forecasting_time&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">model</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">:</span>
<span class="n">model</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="s1">&#39;forecasting_time&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">model</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="s1">&#39;forecasting_time&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="mi">1</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="n">job</span><span class="o">.</span><span class="n">exception</span><span class="p">)</span>
<span class="nb">print</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="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="k">return</span> <span class="n">ret</span></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.distributed.dispy</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,725 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.hyperparam.Evolutionary &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.hyperparam.Evolutionary</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.hyperparam.Evolutionary</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Distributed Evolutionary Hyperparameter Optimization (DEHO) for MVFTS</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">import</span> <span class="nn">math</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">reduce</span>
<span class="kn">from</span> <span class="nn">operator</span> <span class="kn">import</span> <span class="n">itemgetter</span>
<span class="kn">import</span> <span class="nn">random</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">Util</span>
<span class="kn">from</span> <span class="nn">pyFTS.benchmarks</span> <span class="kn">import</span> <span class="n">Measures</span>
<span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="kn">import</span> <span class="n">Grid</span><span class="p">,</span> <span class="n">Entropy</span> <span class="c1"># , Huarng</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">Membership</span>
<span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="kn">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.hyperparam</span> <span class="kn">import</span> <span class="n">Util</span> <span class="k">as</span> <span class="n">hUtil</span>
<span class="n">__measures</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;f1&#39;</span><span class="p">,</span> <span class="s1">&#39;f2&#39;</span><span class="p">,</span> <span class="s1">&#39;rmse&#39;</span><span class="p">,</span> <span class="s1">&#39;size&#39;</span><span class="p">]</span>
<div class="viewcode-block" id="genotype"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Evolutionary.genotype">[docs]</a><span class="k">def</span> <span class="nf">genotype</span><span class="p">(</span><span class="n">mf</span><span class="p">,</span> <span class="n">npart</span><span class="p">,</span> <span class="n">partitioner</span><span class="p">,</span> <span class="n">order</span><span class="p">,</span> <span class="n">alpha</span><span class="p">,</span> <span class="n">lags</span><span class="p">,</span> <span class="n">f1</span><span class="p">,</span> <span class="n">f2</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Create the individual genotype</span>
<span class="sd"> :param mf: membership function</span>
<span class="sd"> :param npart: number of partitions</span>
<span class="sd"> :param partitioner: partitioner method</span>
<span class="sd"> :param order: model order</span>
<span class="sd"> :param alpha: alpha-cut</span>
<span class="sd"> :param lags: array with lag indexes</span>
<span class="sd"> :param f1: accuracy fitness value</span>
<span class="sd"> :param f2: parsimony fitness value</span>
<span class="sd"> :return: the genotype, a dictionary with all hyperparameters</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">ind</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">mf</span><span class="o">=</span><span class="n">mf</span><span class="p">,</span> <span class="n">npart</span><span class="o">=</span><span class="n">npart</span><span class="p">,</span> <span class="n">partitioner</span><span class="o">=</span><span class="n">partitioner</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">alpha</span><span class="o">=</span><span class="n">alpha</span><span class="p">,</span> <span class="n">lags</span><span class="o">=</span><span class="n">lags</span><span class="p">,</span> <span class="n">f1</span><span class="o">=</span><span class="n">f1</span><span class="p">,</span> <span class="n">f2</span><span class="o">=</span><span class="n">f2</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ind</span></div>
<div class="viewcode-block" id="random_genotype"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Evolutionary.random_genotype">[docs]</a><span class="k">def</span> <span class="nf">random_genotype</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"> Create random genotype</span>
<span class="sd"> :return: the genotype, a dictionary with all hyperparameters</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">order</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="n">lags</span> <span class="o">=</span> <span class="p">[</span><span class="n">k</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">1</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="k">return</span> <span class="n">genotype</span><span class="p">(</span>
<span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">),</span>
<span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">100</span><span class="p">),</span>
<span class="n">random</span><span class="o">.</span><span class="n">randint</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="n">order</span><span class="p">,</span>
<span class="n">random</span><span class="o">.</span><span class="n">uniform</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="o">.</span><span class="mi">5</span><span class="p">),</span>
<span class="n">lags</span><span class="p">,</span>
<span class="kc">None</span><span class="p">,</span>
<span class="kc">None</span>
<span class="p">)</span></div>
<span class="c1">#</span>
<div class="viewcode-block" id="initial_population"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Evolutionary.initial_population">[docs]</a><span class="k">def</span> <span class="nf">initial_population</span><span class="p">(</span><span class="n">n</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"> Create a random population of size n</span>
<span class="sd"> :param n: the size of the population</span>
<span class="sd"> :return: a list with n random individuals</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">create_random_individual</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;random_individual&#39;</span><span class="p">,</span> <span class="n">random_genotype</span><span class="p">)</span>
<span class="n">pop</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n</span><span class="p">):</span>
<span class="n">pop</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">create_random_individual</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">))</span>
<span class="k">return</span> <span class="n">pop</span></div>
<div class="viewcode-block" id="phenotype"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Evolutionary.phenotype">[docs]</a><span class="k">def</span> <span class="nf">phenotype</span><span class="p">(</span><span class="n">individual</span><span class="p">,</span> <span class="n">train</span><span class="p">,</span> <span class="n">fts_method</span><span class="p">,</span> <span class="n">parameters</span><span class="o">=</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"> Instantiate the genotype, creating a fitted model with the genotype hyperparameters</span>
<span class="sd"> :param individual: a genotype</span>
<span class="sd"> :param train: the training dataset</span>
<span class="sd"> :param fts_method: the FTS method </span>
<span class="sd"> :param parameters: dict with model specific arguments for fit method.</span>
<span class="sd"> :return: a fitted FTS model</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="kn">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="k">if</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;mf&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">mf</span> <span class="o">=</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trimf</span>
<span class="k">elif</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;mf&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
<span class="n">mf</span> <span class="o">=</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trapmf</span>
<span class="k">elif</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;mf&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">3</span> <span class="ow">and</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;partitioner&#39;</span><span class="p">]</span> <span class="o">!=</span> <span class="mi">2</span><span class="p">:</span>
<span class="n">mf</span> <span class="o">=</span> <span class="n">Membership</span><span class="o">.</span><span class="n">gaussmf</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">mf</span> <span class="o">=</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trimf</span>
<span class="k">if</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;partitioner&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</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">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">individual</span><span class="p">[</span><span class="s1">&#39;npart&#39;</span><span class="p">],</span> <span class="n">func</span><span class="o">=</span><span class="n">mf</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;partitioner&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
<span class="n">partitioner</span> <span class="o">=</span> <span class="n">Entropy</span><span class="o">.</span><span class="n">EntropyPartitioner</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">individual</span><span class="p">[</span><span class="s1">&#39;npart&#39;</span><span class="p">],</span> <span class="n">func</span><span class="o">=</span><span class="n">mf</span><span class="p">)</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">fts_method</span><span class="p">(</span><span class="n">partitioner</span><span class="o">=</span><span class="n">partitioner</span><span class="p">,</span>
<span class="n">lags</span><span class="o">=</span><span class="n">individual</span><span class="p">[</span><span class="s1">&#39;lags&#39;</span><span class="p">],</span>
<span class="n">alpha_cut</span><span class="o">=</span><span class="n">individual</span><span class="p">[</span><span class="s1">&#39;alpha&#39;</span><span class="p">],</span>
<span class="n">order</span><span class="o">=</span><span class="n">individual</span><span class="p">[</span><span class="s1">&#39;order&#39;</span><span class="p">])</span>
<span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">train</span><span class="p">,</span> <span class="o">**</span><span class="n">parameters</span><span class="p">)</span>
<span class="k">return</span> <span class="n">model</span></div>
<div class="viewcode-block" id="evaluate"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Evolutionary.evaluate">[docs]</a><span class="k">def</span> <span class="nf">evaluate</span><span class="p">(</span><span class="n">dataset</span><span class="p">,</span> <span class="n">individual</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"> Evaluate an individual using a sliding window cross validation over the dataset.</span>
<span class="sd"> :param dataset: Evaluation dataset</span>
<span class="sd"> :param individual: genotype to be tested</span>
<span class="sd"> :param window_size: The length of scrolling window for train/test on dataset</span>
<span class="sd"> :param train_rate: The train/test split ([0,1])</span>
<span class="sd"> :param increment_rate: The increment of the scrolling window, relative to the window_size ([0,1])</span>
<span class="sd"> :param parameters: dict with model specific arguments for fit method.</span>
<span class="sd"> :return: a tuple (len_lags, rmse) with the parsimony fitness value and the accuracy fitness value</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="kn">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.common</span> <span class="kn">import</span> <span class="n">Util</span>
<span class="kn">from</span> <span class="nn">pyFTS.benchmarks</span> <span class="kn">import</span> <span class="n">Measures</span>
<span class="kn">from</span> <span class="nn">pyFTS.hyperparam.Evolutionary</span> <span class="kn">import</span> <span class="n">phenotype</span><span class="p">,</span> <span class="n">__measures</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="n">window_size</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;window_size&#39;</span><span class="p">,</span> <span class="mi">800</span><span class="p">)</span>
<span class="n">train_rate</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;train_rate&#39;</span><span class="p">,</span> <span class="o">.</span><span class="mi">8</span><span class="p">)</span>
<span class="n">increment_rate</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;increment_rate&#39;</span><span class="p">,</span> <span class="o">.</span><span class="mi">2</span><span class="p">)</span>
<span class="n">fts_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;fts_method&#39;</span><span class="p">,</span> <span class="n">hofts</span><span class="o">.</span><span class="n">WeightedHighOrderFTS</span><span class="p">)</span>
<span class="n">parameters</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;parameters&#39;</span><span class="p">,{})</span>
<span class="k">if</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;f1&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;f2&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">return</span> <span class="p">{</span> <span class="n">key</span><span class="p">:</span> <span class="n">individual</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">__measures</span> <span class="p">}</span>
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">lengths</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">train</span><span class="p">,</span> <span class="n">test</span> <span class="ow">in</span> <span class="n">Util</span><span class="o">.</span><span class="n">sliding_window</span><span class="p">(</span><span class="n">dataset</span><span class="p">,</span> <span class="n">window_size</span><span class="p">,</span> <span class="n">train</span><span class="o">=</span><span class="n">train_rate</span><span class="p">,</span> <span class="n">inc</span><span class="o">=</span><span class="n">increment_rate</span><span class="p">):</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">phenotype</span><span class="p">(</span><span class="n">individual</span><span class="p">,</span> <span class="n">train</span><span class="p">,</span> <span class="n">fts_method</span><span class="o">=</span><span class="n">fts_method</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="n">forecasts</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">test</span><span class="p">)</span>
<span class="n">rmse</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">test</span><span class="p">[</span><span class="n">model</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="n">forecasts</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="n">lengths</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">model</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">rmse</span><span class="p">)</span>
<span class="k">except</span><span class="p">:</span>
<span class="n">lengths</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">nan</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">np</span><span class="o">.</span><span class="n">nan</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">_lags</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">lags</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span>
<span class="n">_rmse</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmean</span><span class="p">(</span><span class="n">errors</span><span class="p">)</span>
<span class="n">_len</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmean</span><span class="p">(</span><span class="n">lengths</span><span class="p">)</span>
<span class="n">f1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">([</span><span class="o">.</span><span class="mi">6</span> <span class="o">*</span> <span class="n">_rmse</span><span class="p">,</span> <span class="o">.</span><span class="mi">4</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">nanstd</span><span class="p">(</span><span class="n">errors</span><span class="p">)])</span>
<span class="n">f2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">([</span><span class="o">.</span><span class="mi">4</span> <span class="o">*</span> <span class="n">_len</span><span class="p">,</span> <span class="o">.</span><span class="mi">6</span> <span class="o">*</span> <span class="n">_lags</span><span class="p">])</span>
<span class="k">return</span> <span class="p">{</span><span class="s1">&#39;f1&#39;</span><span class="p">:</span> <span class="n">f1</span><span class="p">,</span> <span class="s1">&#39;f2&#39;</span><span class="p">:</span> <span class="n">f2</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;size&#39;</span><span class="p">:</span> <span class="n">_len</span> <span class="p">}</span>
<span class="k">except</span><span class="p">:</span>
<span class="k">return</span> <span class="p">{</span><span class="s1">&#39;f1&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">inf</span><span class="p">,</span> <span class="s1">&#39;f2&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">inf</span><span class="p">,</span> <span class="s1">&#39;rmse&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">inf</span><span class="p">,</span> <span class="s1">&#39;size&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">inf</span><span class="p">}</span></div>
<div class="viewcode-block" id="tournament"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Evolutionary.tournament">[docs]</a><span class="k">def</span> <span class="nf">tournament</span><span class="p">(</span><span class="n">population</span><span class="p">,</span> <span class="n">objective</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"> Simple tournament selection strategy.</span>
<span class="sd"> :param population: the population</span>
<span class="sd"> :param objective: the objective to be considered on tournament</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">population</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span>
<span class="n">r1</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span> <span class="k">if</span> <span class="n">n</span> <span class="o">&gt;</span> <span class="mi">2</span> <span class="k">else</span> <span class="mi">0</span>
<span class="n">r2</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span> <span class="k">if</span> <span class="n">n</span> <span class="o">&gt;</span> <span class="mi">2</span> <span class="k">else</span> <span class="mi">1</span>
<span class="n">ix</span> <span class="o">=</span> <span class="n">r1</span> <span class="k">if</span> <span class="n">population</span><span class="p">[</span><span class="n">r1</span><span class="p">][</span><span class="n">objective</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">population</span><span class="p">[</span><span class="n">r2</span><span class="p">][</span><span class="n">objective</span><span class="p">]</span> <span class="k">else</span> <span class="n">r2</span>
<span class="k">return</span> <span class="n">population</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span></div>
<div class="viewcode-block" id="double_tournament"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Evolutionary.double_tournament">[docs]</a><span class="k">def</span> <span class="nf">double_tournament</span><span class="p">(</span><span class="n">population</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"> Double tournament selection strategy.</span>
<span class="sd"> :param population:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">ancestor1</span> <span class="o">=</span> <span class="n">tournament</span><span class="p">(</span><span class="n">population</span><span class="p">,</span> <span class="s1">&#39;f1&#39;</span><span class="p">)</span>
<span class="n">ancestor2</span> <span class="o">=</span> <span class="n">tournament</span><span class="p">(</span><span class="n">population</span><span class="p">,</span> <span class="s1">&#39;f1&#39;</span><span class="p">)</span>
<span class="n">selected</span> <span class="o">=</span> <span class="n">tournament</span><span class="p">([</span><span class="n">ancestor1</span><span class="p">,</span> <span class="n">ancestor2</span><span class="p">],</span> <span class="s1">&#39;f2&#39;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">selected</span></div>
<div class="viewcode-block" id="lag_crossover2"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Evolutionary.lag_crossover2">[docs]</a><span class="k">def</span> <span class="nf">lag_crossover2</span><span class="p">(</span><span class="n">best</span><span class="p">,</span> <span class="n">worst</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Cross over two lag genes</span>
<span class="sd"> :param best: best genotype</span>
<span class="sd"> :param worst: worst genotype</span>
<span class="sd"> :return: a tuple (order, lags)</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">order</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="o">.</span><span class="mi">7</span> <span class="o">*</span> <span class="n">best</span><span class="p">[</span><span class="s1">&#39;order&#39;</span><span class="p">]</span> <span class="o">+</span> <span class="o">.</span><span class="mi">3</span> <span class="o">*</span> <span class="n">worst</span><span class="p">[</span><span class="s1">&#39;order&#39;</span><span class="p">]))</span>
<span class="n">lags</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">min_order</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">best</span><span class="p">[</span><span class="s1">&#39;order&#39;</span><span class="p">],</span> <span class="n">worst</span><span class="p">[</span><span class="s1">&#39;order&#39;</span><span class="p">])</span>
<span class="n">max_order</span> <span class="o">=</span> <span class="n">best</span> <span class="k">if</span> <span class="n">best</span><span class="p">[</span><span class="s1">&#39;order&#39;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">min_order</span> <span class="k">else</span> <span class="n">worst</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="k">if</span> <span class="n">k</span> <span class="o">&lt;</span> <span class="n">min_order</span><span class="p">:</span>
<span class="n">lags</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="o">.</span><span class="mi">7</span> <span class="o">*</span> <span class="n">best</span><span class="p">[</span><span class="s1">&#39;lags&#39;</span><span class="p">][</span><span class="n">k</span><span class="p">]</span> <span class="o">+</span> <span class="o">.</span><span class="mi">3</span> <span class="o">*</span> <span class="n">worst</span><span class="p">[</span><span class="s1">&#39;lags&#39;</span><span class="p">][</span><span class="n">k</span><span class="p">])))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">lags</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">max_order</span><span class="p">[</span><span class="s1">&#39;lags&#39;</span><span class="p">][</span><span class="n">k</span><span class="p">])</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="mi">1</span><span class="p">,</span> <span class="n">order</span><span class="p">):</span>
<span class="k">while</span> <span class="n">lags</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">&gt;=</span> <span class="n">lags</span><span class="p">[</span><span class="n">k</span><span class="p">]:</span>
<span class="n">lags</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">+=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
<span class="k">return</span> <span class="n">order</span><span class="p">,</span> <span class="n">lags</span></div>
<div class="viewcode-block" id="crossover"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Evolutionary.crossover">[docs]</a><span class="k">def</span> <span class="nf">crossover</span><span class="p">(</span><span class="n">population</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"> Crossover operation between two parents</span>
<span class="sd"> :param population: the original population</span>
<span class="sd"> :return: a genotype</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">random</span>
<span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">population</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span>
<span class="n">r1</span><span class="p">,</span> <span class="n">r2</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span>
<span class="k">while</span> <span class="n">r1</span> <span class="o">==</span> <span class="n">r2</span><span class="p">:</span>
<span class="n">r1</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="n">r2</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="k">if</span> <span class="n">population</span><span class="p">[</span><span class="n">r1</span><span class="p">][</span><span class="s1">&#39;f1&#39;</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">population</span><span class="p">[</span><span class="n">r2</span><span class="p">][</span><span class="s1">&#39;f1&#39;</span><span class="p">]:</span>
<span class="n">best</span> <span class="o">=</span> <span class="n">population</span><span class="p">[</span><span class="n">r1</span><span class="p">]</span>
<span class="n">worst</span> <span class="o">=</span> <span class="n">population</span><span class="p">[</span><span class="n">r2</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">best</span> <span class="o">=</span> <span class="n">population</span><span class="p">[</span><span class="n">r2</span><span class="p">]</span>
<span class="n">worst</span> <span class="o">=</span> <span class="n">population</span><span class="p">[</span><span class="n">r1</span><span class="p">]</span>
<span class="n">npart</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="o">.</span><span class="mi">7</span> <span class="o">*</span> <span class="n">best</span><span class="p">[</span><span class="s1">&#39;npart&#39;</span><span class="p">]</span> <span class="o">+</span> <span class="o">.</span><span class="mi">3</span> <span class="o">*</span> <span class="n">worst</span><span class="p">[</span><span class="s1">&#39;npart&#39;</span><span class="p">]))</span>
<span class="n">alpha</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="o">.</span><span class="mi">7</span> <span class="o">*</span> <span class="n">best</span><span class="p">[</span><span class="s1">&#39;alpha&#39;</span><span class="p">]</span> <span class="o">+</span> <span class="o">.</span><span class="mi">3</span> <span class="o">*</span> <span class="n">worst</span><span class="p">[</span><span class="s1">&#39;alpha&#39;</span><span class="p">])</span>
<span class="n">rnd</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">uniform</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">mf</span> <span class="o">=</span> <span class="n">best</span><span class="p">[</span><span class="s1">&#39;mf&#39;</span><span class="p">]</span> <span class="k">if</span> <span class="n">rnd</span> <span class="o">&lt;</span> <span class="o">.</span><span class="mi">7</span> <span class="k">else</span> <span class="n">worst</span><span class="p">[</span><span class="s1">&#39;mf&#39;</span><span class="p">]</span>
<span class="n">rnd</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">uniform</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">partitioner</span> <span class="o">=</span> <span class="n">best</span><span class="p">[</span><span class="s1">&#39;partitioner&#39;</span><span class="p">]</span> <span class="k">if</span> <span class="n">rnd</span> <span class="o">&lt;</span> <span class="o">.</span><span class="mi">7</span> <span class="k">else</span> <span class="n">worst</span><span class="p">[</span><span class="s1">&#39;partitioner&#39;</span><span class="p">]</span>
<span class="n">order</span><span class="p">,</span> <span class="n">lags</span> <span class="o">=</span> <span class="n">lag_crossover2</span><span class="p">(</span><span class="n">best</span><span class="p">,</span> <span class="n">worst</span><span class="p">)</span>
<span class="n">descendent</span> <span class="o">=</span> <span class="n">genotype</span><span class="p">(</span><span class="n">mf</span><span class="p">,</span> <span class="n">npart</span><span class="p">,</span> <span class="n">partitioner</span><span class="p">,</span> <span class="n">order</span><span class="p">,</span> <span class="n">alpha</span><span class="p">,</span> <span class="n">lags</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="k">return</span> <span class="n">descendent</span></div>
<div class="viewcode-block" id="mutation_lags"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Evolutionary.mutation_lags">[docs]</a><span class="k">def</span> <span class="nf">mutation_lags</span><span class="p">(</span><span class="n">lags</span><span class="p">,</span> <span class="n">order</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Mutation operation for lags gene</span>
<span class="sd"> :param lags:</span>
<span class="sd"> :param order:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">try</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">lags</span><span class="p">)</span>
<span class="n">new</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">lag</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="n">order</span><span class="p">):</span>
<span class="k">if</span> <span class="n">lag</span> <span class="o">&lt;</span> <span class="n">l</span><span class="p">:</span>
<span class="n">new</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="mi">50</span><span class="p">,</span> <span class="nb">max</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">lags</span><span class="p">[</span><span class="n">lag</span><span class="p">]</span> <span class="o">+</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">))))</span> <span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">new</span><span class="o">.</span><span class="n">append</span><span class="p">(</span> <span class="n">new</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span> <span class="p">)</span>
<span class="k">if</span> <span class="n">order</span> <span class="o">&gt;</span> <span class="mi">1</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">1</span><span class="p">,</span> <span class="n">order</span><span class="p">):</span>
<span class="k">while</span> <span class="n">new</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">new</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]:</span>
<span class="n">new</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">new</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">+</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">5</span><span class="p">))</span>
<span class="k">return</span> <span class="n">new</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="n">lags</span><span class="p">,</span> <span class="n">order</span><span class="p">,</span> <span class="n">new</span><span class="p">,</span> <span class="n">lag</span><span class="p">)</span></div>
<div class="viewcode-block" id="mutation"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Evolutionary.mutation">[docs]</a><span class="k">def</span> <span class="nf">mutation</span><span class="p">(</span><span class="n">individual</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"> Mutation operator</span>
<span class="sd"> :param individual: an individual genotype</span>
<span class="sd"> :param pmut: individual probability o</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">individual</span><span class="p">[</span><span class="s1">&#39;npart&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="mi">50</span><span class="p">,</span> <span class="nb">max</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">individual</span><span class="p">[</span><span class="s1">&#39;npart&#39;</span><span class="p">]</span> <span class="o">+</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">normal</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">4</span><span class="p">))))</span>
<span class="n">individual</span><span class="p">[</span><span class="s1">&#39;alpha&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="o">.</span><span class="mi">5</span><span class="p">,</span> <span class="nb">max</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;alpha&#39;</span><span class="p">]</span> <span class="o">+</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">normal</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="o">.</span><span class="mi">5</span><span class="p">)))</span>
<span class="n">individual</span><span class="p">[</span><span class="s1">&#39;mf&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</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="n">individual</span><span class="p">[</span><span class="s1">&#39;partitioner&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</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="n">individual</span><span class="p">[</span><span class="s1">&#39;order&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="nb">max</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">individual</span><span class="p">[</span><span class="s1">&#39;order&#39;</span><span class="p">]</span> <span class="o">+</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">normal</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="c1"># Chama a função mutation_lags</span>
<span class="n">individual</span><span class="p">[</span><span class="s1">&#39;lags&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">mutation_lags</span><span class="p">(</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;lags&#39;</span><span class="p">],</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;order&#39;</span><span class="p">])</span>
<span class="n">individual</span><span class="p">[</span><span class="s1">&#39;f1&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">individual</span><span class="p">[</span><span class="s1">&#39;f2&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">return</span> <span class="n">individual</span></div>
<div class="viewcode-block" id="elitism"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Evolutionary.elitism">[docs]</a><span class="k">def</span> <span class="nf">elitism</span><span class="p">(</span><span class="n">population</span><span class="p">,</span> <span class="n">new_population</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"> Elitism operation, always select the best individual of the population and discard the worst</span>
<span class="sd"> :param population:</span>
<span class="sd"> :param new_population:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">population</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">population</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="n">itemgetter</span><span class="p">(</span><span class="s1">&#39;f1&#39;</span><span class="p">))</span>
<span class="n">best</span> <span class="o">=</span> <span class="n">population</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">new_population</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">new_population</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="n">itemgetter</span><span class="p">(</span><span class="s1">&#39;f1&#39;</span><span class="p">))</span>
<span class="k">if</span> <span class="n">new_population</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s2">&quot;f1&quot;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">best</span><span class="p">[</span><span class="s2">&quot;f1&quot;</span><span class="p">]:</span>
<span class="n">new_population</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">best</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">new_population</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s2">&quot;f1&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="n">best</span><span class="p">[</span><span class="s2">&quot;f1&quot;</span><span class="p">]</span> <span class="ow">and</span> <span class="n">new_population</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s2">&quot;f2&quot;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">best</span><span class="p">[</span><span class="s2">&quot;f2&quot;</span><span class="p">]:</span>
<span class="n">new_population</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">best</span><span class="p">)</span>
<span class="k">return</span> <span class="n">new_population</span></div>
<div class="viewcode-block" id="GeneticAlgorithm"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Evolutionary.GeneticAlgorithm">[docs]</a><span class="k">def</span> <span class="nf">GeneticAlgorithm</span><span class="p">(</span><span class="n">dataset</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"> Genetic algoritm for Distributed Evolutionary Hyperparameter Optimization (DEHO)</span>
<span class="sd"> :param dataset: The time series to optimize the FTS</span>
<span class="sd"> :keyword ngen: An integer value with the maximum number of generations, default value: 30</span>
<span class="sd"> :keyword mgen: An integer value with the maximum number of generations without improvement to stop, default value 7</span>
<span class="sd"> :keyword npop: An integer value with the population size, default value: 20</span>
<span class="sd"> :keyword pcross: A float value between 0 and 1 with the probability of crossover, default: .5</span>
<span class="sd"> :keyword psel: A float value between 0 and 1 with the probability of selection, default: .5</span>
<span class="sd"> :keyword pmut: A float value between 0 and 1 with the probability of mutation, default: .3</span>
<span class="sd"> :keyword fts_method: The FTS method to optimize</span>
<span class="sd"> :keyword parameters: dict with model specific arguments for fts_method</span>
<span class="sd"> :keyword elitism: A boolean value indicating if the best individual must always survive to next population</span>
<span class="sd"> :keyword initial_operator: a function that receives npop and return a random population with size npop</span>
<span class="sd"> :keyword evalutation_operator: a function that receives a dataset and an individual and return its fitness</span>
<span class="sd"> :keyword selection_operator: a function that receives the whole population and return a selected individual</span>
<span class="sd"> :keyword crossover_operator: a function that receives the whole population and return a descendent individual</span>
<span class="sd"> :keyword mutation_operator: a function that receives one individual and return a changed individual</span>
<span class="sd"> :keyword window_size: An integer value with the the length of scrolling window for train/test on dataset</span>
<span class="sd"> :keyword train_rate: A float value between 0 and 1 with the train/test split ([0,1])</span>
<span class="sd"> :keyword increment_rate: A float value between 0 and 1 with the the increment of the scrolling window,</span>
<span class="sd"> relative to the window_size ([0,1])</span>
<span class="sd"> :keyword collect_statistics: A boolean value indicating to collect statistics for each generation</span>
<span class="sd"> :keyword distributed: A value indicating it the execution will be local and sequential (distributed=False),</span>
<span class="sd"> or parallel and distributed (distributed=&#39;dispy&#39; or distributed=&#39;spark&#39;)</span>
<span class="sd"> :keyword cluster: If distributed=&#39;dispy&#39; the list of cluster nodes, else if distributed=&#39;spark&#39; it is the master node</span>
<span class="sd"> :return: the best genotype</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">statistics</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">ngen</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;ngen&#39;</span><span class="p">,</span><span class="mi">30</span><span class="p">)</span>
<span class="n">mgen</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;mgen&#39;</span><span class="p">,</span> <span class="mi">7</span><span class="p">)</span>
<span class="n">npop</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;npop&#39;</span><span class="p">,</span><span class="mi">20</span><span class="p">)</span>
<span class="n">psel</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;psel&#39;</span><span class="p">,</span> <span class="o">.</span><span class="mi">5</span><span class="p">)</span>
<span class="n">pcross</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;pcross&#39;</span><span class="p">,</span><span class="o">.</span><span class="mi">5</span><span class="p">)</span>
<span class="n">pmut</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;pmut&#39;</span><span class="p">,</span><span class="o">.</span><span class="mi">3</span><span class="p">)</span>
<span class="n">distributed</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;distributed&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="n">initial_operator</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;initial_operator&#39;</span><span class="p">,</span> <span class="n">initial_population</span><span class="p">)</span>
<span class="n">evaluation_operator</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;evaluation_operator&#39;</span><span class="p">,</span> <span class="n">evaluate</span><span class="p">)</span>
<span class="n">selection_operator</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;selection_operator&#39;</span><span class="p">,</span> <span class="n">double_tournament</span><span class="p">)</span>
<span class="n">crossover_operator</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;crossover_operator&#39;</span><span class="p">,</span> <span class="n">crossover</span><span class="p">)</span>
<span class="n">mutation_operator</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;mutation_operator&#39;</span><span class="p">,</span> <span class="n">mutation</span><span class="p">)</span>
<span class="n">_elitism</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;elitism&#39;</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
<span class="n">elitism_operator</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;elitism_operator&#39;</span><span class="p">,</span> <span class="n">elitism</span><span class="p">)</span>
<span class="k">if</span> <span class="n">distributed</span> <span class="o">==</span> <span class="s1">&#39;dispy&#39;</span><span class="p">:</span>
<span class="n">cluster</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;cluster&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="n">collect_statistics</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;collect_statistics&#39;</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
<span class="n">no_improvement_count</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">new_population</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">population</span> <span class="o">=</span> <span class="n">initial_operator</span><span class="p">(</span><span class="n">npop</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">last_best</span> <span class="o">=</span> <span class="n">population</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">best</span> <span class="o">=</span> <span class="n">population</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Evaluating initial population </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()))</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">distributed</span><span class="p">:</span>
<span class="k">for</span> <span class="n">individual</span> <span class="ow">in</span> <span class="n">population</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">evaluation_operator</span><span class="p">(</span><span class="n">dataset</span><span class="p">,</span> <span class="n">individual</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">__measures</span><span class="p">:</span>
<span class="n">individual</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">ret</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
<span class="k">elif</span> <span class="n">distributed</span><span class="o">==</span><span class="s1">&#39;dispy&#39;</span><span class="p">:</span>
<span class="kn">from</span> <span class="nn">pyFTS.distributed</span> <span class="kn">import</span> <span class="n">dispy</span> <span class="k">as</span> <span class="n">dUtil</span>
<span class="kn">import</span> <span class="nn">dispy</span>
<span class="n">jobs</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">individual</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">population</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">dataset</span><span class="p">,</span> <span class="n">individual</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="n">ct</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">for</span> <span class="n">job</span> <span class="ow">in</span> <span class="n">jobs</span><span class="p">:</span>
<span class="n">result</span> <span class="o">=</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">result</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">key</span> <span class="ow">in</span> <span class="n">__measures</span><span class="p">:</span>
<span class="n">population</span><span class="p">[</span><span class="n">job</span><span class="o">.</span><span class="n">id</span><span class="p">][</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">result</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="nb">print</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="nb">print</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="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">ngen</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;GENERATION </span><span class="si">{}</span><span class="s2"> </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()))</span>
<span class="n">generation_statistics</span> <span class="o">=</span> <span class="p">{}</span>
<span class="c1"># Selection</span>
<span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">npop</span> <span class="o">*</span> <span class="n">psel</span><span class="p">)):</span>
<span class="n">new_population</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">selection_operator</span><span class="p">(</span><span class="n">population</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">))</span>
<span class="c1"># Crossover</span>
<span class="n">new</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">npop</span> <span class="o">*</span> <span class="n">pcross</span><span class="p">)):</span>
<span class="n">new</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">crossover_operator</span><span class="p">(</span><span class="n">new_population</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">))</span>
<span class="n">new_population</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">new</span><span class="p">)</span>
<span class="c1"># Mutation</span>
<span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">individual</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">new_population</span><span class="p">):</span>
<span class="n">rnd</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">uniform</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="k">if</span> <span class="n">rnd</span> <span class="o">&lt;</span> <span class="n">pmut</span><span class="p">:</span>
<span class="n">new_population</span><span class="p">[</span><span class="n">ct</span><span class="p">]</span> <span class="o">=</span> <span class="n">mutation_operator</span><span class="p">(</span><span class="n">individual</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="c1"># Evaluation</span>
<span class="k">if</span> <span class="n">collect_statistics</span><span class="p">:</span>
<span class="n">stats</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">__measures</span><span class="p">:</span>
<span class="n">stats</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">distributed</span><span class="p">:</span>
<span class="k">for</span> <span class="n">individual</span> <span class="ow">in</span> <span class="n">new_population</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">evaluation_operator</span><span class="p">(</span><span class="n">dataset</span><span class="p">,</span> <span class="n">individual</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">__measures</span><span class="p">:</span>
<span class="n">individual</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">ret</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
<span class="k">if</span> <span class="n">collect_statistics</span><span class="p">:</span> <span class="n">stats</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ret</span><span class="p">[</span><span class="n">key</span><span class="p">])</span>
<span class="k">elif</span> <span class="n">distributed</span> <span class="o">==</span> <span class="s1">&#39;dispy&#39;</span><span class="p">:</span>
<span class="n">jobs</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">individual</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">new_population</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">dataset</span><span class="p">,</span> <span class="n">individual</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="n">ct</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">for</span> <span class="n">job</span> <span class="ow">in</span> <span class="n">jobs</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;job id </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">job</span><span class="o">.</span><span class="n">id</span><span class="p">))</span>
<span class="n">result</span> <span class="o">=</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">result</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">key</span> <span class="ow">in</span> <span class="n">__measures</span><span class="p">:</span>
<span class="n">new_population</span><span class="p">[</span><span class="n">job</span><span class="o">.</span><span class="n">id</span><span class="p">][</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">result</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
<span class="k">if</span> <span class="n">collect_statistics</span><span class="p">:</span> <span class="n">stats</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">result</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="nb">print</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="nb">print</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="k">if</span> <span class="n">collect_statistics</span><span class="p">:</span>
<span class="n">mean_stats</span> <span class="o">=</span> <span class="p">{</span><span class="n">key</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmedian</span><span class="p">(</span><span class="n">stats</span><span class="p">[</span><span class="n">key</span><span class="p">])</span> <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">__measures</span> <span class="p">}</span>
<span class="n">generation_statistics</span><span class="p">[</span><span class="s1">&#39;population&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">mean_stats</span>
<span class="c1"># Elitism</span>
<span class="k">if</span> <span class="n">_elitism</span><span class="p">:</span>
<span class="n">population</span> <span class="o">=</span> <span class="n">elitism_operator</span><span class="p">(</span><span class="n">population</span><span class="p">,</span> <span class="n">new_population</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">population</span> <span class="o">=</span> <span class="n">population</span><span class="p">[:</span><span class="n">npop</span><span class="p">]</span>
<span class="n">new_population</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">last_best</span> <span class="o">=</span> <span class="n">best</span>
<span class="n">best</span> <span class="o">=</span> <span class="n">population</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">if</span> <span class="n">collect_statistics</span><span class="p">:</span>
<span class="n">generation_statistics</span><span class="p">[</span><span class="s1">&#39;best&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="n">key</span><span class="p">:</span> <span class="n">best</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">__measures</span> <span class="p">}</span>
<span class="n">statistics</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">generation_statistics</span><span class="p">)</span>
<span class="k">if</span> <span class="n">last_best</span><span class="p">[</span><span class="s1">&#39;f1&#39;</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">best</span><span class="p">[</span><span class="s1">&#39;f1&#39;</span><span class="p">]</span> <span class="ow">and</span> <span class="n">last_best</span><span class="p">[</span><span class="s1">&#39;f2&#39;</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">best</span><span class="p">[</span><span class="s1">&#39;f2&#39;</span><span class="p">]:</span>
<span class="n">no_improvement_count</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;WITHOUT IMPROVEMENT </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">no_improvement_count</span><span class="p">))</span>
<span class="n">pmut</span> <span class="o">+=</span> <span class="o">.</span><span class="mi">05</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">no_improvement_count</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">pcross</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;pcross&#39;</span><span class="p">,</span> <span class="o">.</span><span class="mi">5</span><span class="p">)</span>
<span class="n">pmut</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;pmut&#39;</span><span class="p">,</span> <span class="o">.</span><span class="mi">3</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">best</span><span class="p">)</span>
<span class="k">if</span> <span class="n">no_improvement_count</span> <span class="o">==</span> <span class="n">mgen</span><span class="p">:</span>
<span class="k">break</span>
<span class="k">return</span> <span class="n">best</span><span class="p">,</span> <span class="n">statistics</span></div>
<div class="viewcode-block" id="process_experiment"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Evolutionary.process_experiment">[docs]</a><span class="k">def</span> <span class="nf">process_experiment</span><span class="p">(</span><span class="n">fts_method</span><span class="p">,</span> <span class="n">result</span><span class="p">,</span> <span class="n">datasetname</span><span class="p">,</span> <span class="n">conn</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Persist the results of an DEHO execution in sqlite database (best hyperparameters) and json file (generation statistics)</span>
<span class="sd"> :param fts_method:</span>
<span class="sd"> :param result:</span>
<span class="sd"> :param datasetname:</span>
<span class="sd"> :param conn:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">log_result</span><span class="p">(</span><span class="n">conn</span><span class="p">,</span> <span class="n">datasetname</span><span class="p">,</span> <span class="n">fts_method</span><span class="p">,</span> <span class="n">result</span><span class="p">[</span><span class="s1">&#39;individual&#39;</span><span class="p">])</span>
<span class="n">persist_statistics</span><span class="p">(</span><span class="n">datasetname</span><span class="p">,</span> <span class="n">result</span><span class="p">[</span><span class="s1">&#39;statistics&#39;</span><span class="p">])</span>
<span class="k">return</span> <span class="n">result</span><span class="p">[</span><span class="s1">&#39;individual&#39;</span><span class="p">]</span></div>
<div class="viewcode-block" id="persist_statistics"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Evolutionary.persist_statistics">[docs]</a><span class="k">def</span> <span class="nf">persist_statistics</span><span class="p">(</span><span class="n">datasetname</span><span class="p">,</span> <span class="n">statistics</span><span class="p">):</span>
<span class="kn">import</span> <span class="nn">json</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s1">&#39;statistics_</span><span class="si">{}</span><span class="s1">.json&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">datasetname</span><span class="p">),</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">file</span><span class="p">:</span>
<span class="n">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">statistics</span><span class="p">))</span></div>
<div class="viewcode-block" id="log_result"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Evolutionary.log_result">[docs]</a><span class="k">def</span> <span class="nf">log_result</span><span class="p">(</span><span class="n">conn</span><span class="p">,</span> <span class="n">datasetname</span><span class="p">,</span> <span class="n">fts_method</span><span class="p">,</span> <span class="n">result</span><span class="p">):</span>
<span class="n">metrics</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;rmse&#39;</span><span class="p">,</span> <span class="s1">&#39;size&#39;</span><span class="p">,</span> <span class="s1">&#39;time&#39;</span><span class="p">]</span>
<span class="k">for</span> <span class="n">metric</span> <span class="ow">in</span> <span class="n">metrics</span><span class="p">:</span>
<span class="n">record</span> <span class="o">=</span> <span class="p">(</span><span class="n">datasetname</span><span class="p">,</span> <span class="s1">&#39;Evolutive&#39;</span><span class="p">,</span> <span class="n">fts_method</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">result</span><span class="p">[</span><span class="s1">&#39;mf&#39;</span><span class="p">],</span>
<span class="n">result</span><span class="p">[</span><span class="s1">&#39;order&#39;</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="s1">&#39;partitioner&#39;</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="s1">&#39;npart&#39;</span><span class="p">],</span>
<span class="n">result</span><span class="p">[</span><span class="s1">&#39;alpha&#39;</span><span class="p">],</span> <span class="nb">str</span><span class="p">(</span><span class="n">result</span><span class="p">[</span><span class="s1">&#39;lags&#39;</span><span class="p">]),</span> <span class="n">metric</span><span class="p">,</span> <span class="n">result</span><span class="p">[</span><span class="n">metric</span><span class="p">])</span>
<span class="nb">print</span><span class="p">(</span><span class="n">record</span><span class="p">)</span>
<span class="n">hUtil</span><span class="o">.</span><span class="n">insert_hyperparam</span><span class="p">(</span><span class="n">record</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span></div>
<div class="viewcode-block" id="execute"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Evolutionary.execute">[docs]</a><span class="k">def</span> <span class="nf">execute</span><span class="p">(</span><span class="n">datasetname</span><span class="p">,</span> <span class="n">dataset</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"> Batch execution of Distributed Evolutionary Hyperparameter Optimization (DEHO) for monovariate methods</span>
<span class="sd"> :param datasetname:</span>
<span class="sd"> :param dataset: The time series to optimize the FTS</span>
<span class="sd"> :keyword file:</span>
<span class="sd"> :keyword experiments:</span>
<span class="sd"> :keyword distributed:</span>
<span class="sd"> :keyword ngen: An integer value with the maximum number of generations, default value: 30</span>
<span class="sd"> :keyword mgen: An integer value with the maximum number of generations without improvement to stop, default value 7</span>
<span class="sd"> :keyword npop: An integer value with the population size, default value: 20</span>
<span class="sd"> :keyword pcross: A float value between 0 and 1 with the probability of crossover, default: .5</span>
<span class="sd"> :keyword psel: A float value between 0 and 1 with the probability of selection, default: .5</span>
<span class="sd"> :keyword pmut: A float value between 0 and 1 with the probability of mutation, default: .3</span>
<span class="sd"> :keyword fts_method: The FTS method to optimize</span>
<span class="sd"> :keyword parameters: dict with model specific arguments for fts_method</span>
<span class="sd"> :keyword elitism: A boolean value indicating if the best individual must always survive to next population</span>
<span class="sd"> :keyword initial_operator: a function that receives npop and return a random population with size npop</span>
<span class="sd"> :keyword random_individual: create an random genotype</span>
<span class="sd"> :keyword evalutation_operator: a function that receives a dataset and an individual and return its fitness</span>
<span class="sd"> :keyword selection_operator: a function that receives the whole population and return a selected individual</span>
<span class="sd"> :keyword crossover_operator: a function that receives the whole population and return a descendent individual</span>
<span class="sd"> :keyword mutation_operator: a function that receives one individual and return a changed individual</span>
<span class="sd"> :keyword window_size: An integer value with the the length of scrolling window for train/test on dataset</span>
<span class="sd"> :keyword train_rate: A float value between 0 and 1 with the train/test split ([0,1])</span>
<span class="sd"> :keyword increment_rate: A float value between 0 and 1 with the the increment of the scrolling window,</span>
<span class="sd"> relative to the window_size ([0,1])</span>
<span class="sd"> :keyword collect_statistics: A boolean value indicating to collect statistics for each generation</span>
<span class="sd"> :keyword distributed: A value indicating it the execution will be local and sequential (distributed=False),</span>
<span class="sd"> or parallel and distributed (distributed=&#39;dispy&#39; or distributed=&#39;spark&#39;)</span>
<span class="sd"> :keyword cluster: If distributed=&#39;dispy&#39; the list of cluster nodes, else if distributed=&#39;spark&#39; it is the master node</span>
<span class="sd"> :return: the best genotype</span>
<span class="sd"> &quot;&quot;&quot;</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="s1">&#39;hyperparam.db&#39;</span><span class="p">)</span>
<span class="n">conn</span> <span class="o">=</span> <span class="n">hUtil</span><span class="o">.</span><span class="n">open_hyperparam_db</span><span class="p">(</span><span class="n">file</span><span class="p">)</span>
<span class="n">experiments</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;experiments&#39;</span><span class="p">,</span> <span class="mi">30</span><span class="p">)</span>
<span class="n">distributed</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;distributed&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="n">fts_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;fts_method&#39;</span><span class="p">,</span> <span class="n">hofts</span><span class="o">.</span><span class="n">WeightedHighOrderFTS</span><span class="p">)</span>
<span class="n">shortname</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">fts_method</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="k">if</span> <span class="n">distributed</span> <span class="o">==</span> <span class="s1">&#39;dispy&#39;</span><span class="p">:</span>
<span class="kn">from</span> <span class="nn">pyFTS.distributed</span> <span class="kn">import</span> <span class="n">dispy</span> <span class="k">as</span> <span class="n">dUtil</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="s1">&#39;nodes&#39;</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">dUtil</span><span class="o">.</span><span class="n">start_dispy_cluster</span><span class="p">(</span><span class="n">evaluate</span><span class="p">,</span> <span class="n">nodes</span><span class="o">=</span><span class="n">nodes</span><span class="p">)</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;cluster&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">cluster</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">i</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="n">experiments</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Experiment </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">i</span><span class="p">))</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">ret</span><span class="p">,</span> <span class="n">statistics</span> <span class="o">=</span> <span class="n">GeneticAlgorithm</span><span class="p">(</span><span class="n">dataset</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">ret</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">end</span> <span class="o">-</span> <span class="n">start</span>
<span class="n">experiment</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;individual&#39;</span><span class="p">:</span> <span class="n">ret</span><span class="p">,</span> <span class="s1">&#39;statistics&#39;</span><span class="p">:</span> <span class="n">statistics</span><span class="p">}</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">process_experiment</span><span class="p">(</span><span class="n">shortname</span><span class="p">,</span> <span class="n">experiment</span><span class="p">,</span> <span class="n">datasetname</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
<span class="k">if</span> <span class="n">distributed</span> <span class="o">==</span> <span class="s1">&#39;dispy&#39;</span><span class="p">:</span>
<span class="n">dUtil</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="k">return</span> <span class="n">ret</span></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.hyperparam.Evolutionary</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,272 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.hyperparam.GridSearch &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.hyperparam.GridSearch</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.hyperparam.GridSearch</h1><div class="highlight"><pre>
<span></span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">Util</span><span class="p">,</span> <span class="n">Membership</span>
<span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="kn">import</span> <span class="n">hofts</span>
<span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="kn">import</span> <span class="n">Grid</span><span class="p">,</span> <span class="n">Entropy</span>
<span class="kn">from</span> <span class="nn">pyFTS.benchmarks</span> <span class="kn">import</span> <span class="n">Measures</span>
<span class="kn">from</span> <span class="nn">pyFTS.hyperparam</span> <span class="kn">import</span> <span class="n">Util</span> <span class="k">as</span> <span class="n">hUtil</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">itertools</span> <span class="kn">import</span> <span class="n">product</span>
<div class="viewcode-block" id="dict_individual"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.GridSearch.dict_individual">[docs]</a><span class="k">def</span> <span class="nf">dict_individual</span><span class="p">(</span><span class="n">mf</span><span class="p">,</span> <span class="n">partitioner</span><span class="p">,</span> <span class="n">partitions</span><span class="p">,</span> <span class="n">order</span><span class="p">,</span> <span class="n">lags</span><span class="p">,</span> <span class="n">alpha_cut</span><span class="p">):</span>
<span class="k">return</span> <span class="p">{</span>
<span class="s1">&#39;mf&#39;</span><span class="p">:</span> <span class="n">mf</span><span class="p">,</span>
<span class="s1">&#39;partitioner&#39;</span><span class="p">:</span> <span class="n">partitioner</span><span class="p">,</span>
<span class="s1">&#39;npart&#39;</span><span class="p">:</span> <span class="n">partitions</span><span class="p">,</span>
<span class="s1">&#39;alpha&#39;</span><span class="p">:</span> <span class="n">alpha_cut</span><span class="p">,</span>
<span class="s1">&#39;order&#39;</span><span class="p">:</span> <span class="n">order</span><span class="p">,</span>
<span class="s1">&#39;lags&#39;</span><span class="p">:</span> <span class="n">lags</span>
<span class="p">}</span></div>
<div class="viewcode-block" id="cluster_method"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.GridSearch.cluster_method">[docs]</a><span class="k">def</span> <span class="nf">cluster_method</span><span class="p">(</span><span class="n">individual</span><span class="p">,</span> <span class="n">dataset</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">Util</span><span class="p">,</span> <span class="n">Membership</span>
<span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="kn">import</span> <span class="n">hofts</span>
<span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="kn">import</span> <span class="n">Grid</span><span class="p">,</span> <span class="n">Entropy</span>
<span class="kn">from</span> <span class="nn">pyFTS.benchmarks</span> <span class="kn">import</span> <span class="n">Measures</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="k">if</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;mf&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">mf</span> <span class="o">=</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trimf</span>
<span class="k">elif</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;mf&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
<span class="n">mf</span> <span class="o">=</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trapmf</span>
<span class="k">elif</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;mf&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">3</span> <span class="ow">and</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;partitioner&#39;</span><span class="p">]</span> <span class="o">!=</span> <span class="mi">2</span><span class="p">:</span>
<span class="n">mf</span> <span class="o">=</span> <span class="n">Membership</span><span class="o">.</span><span class="n">gaussmf</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">mf</span> <span class="o">=</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trimf</span>
<span class="n">window_size</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;window_size&#39;</span><span class="p">,</span> <span class="mi">800</span><span class="p">)</span>
<span class="n">train_rate</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;train_rate&#39;</span><span class="p">,</span> <span class="o">.</span><span class="mi">8</span><span class="p">)</span>
<span class="n">increment_rate</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;increment_rate&#39;</span><span class="p">,</span> <span class="o">.</span><span class="mi">2</span><span class="p">)</span>
<span class="n">parameters</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;parameters&#39;</span><span class="p">,</span> <span class="p">{})</span>
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">sizes</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">train</span><span class="p">,</span> <span class="n">test</span> <span class="ow">in</span> <span class="n">Util</span><span class="o">.</span><span class="n">sliding_window</span><span class="p">(</span><span class="n">dataset</span><span class="p">,</span> <span class="n">window_size</span><span class="p">,</span> <span class="n">train</span><span class="o">=</span><span class="n">train_rate</span><span class="p">,</span> <span class="n">inc</span><span class="o">=</span><span class="n">increment_rate</span><span class="p">):</span>
<span class="k">if</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;partitioner&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</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">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">individual</span><span class="p">[</span><span class="s1">&#39;npart&#39;</span><span class="p">],</span> <span class="n">func</span><span class="o">=</span><span class="n">mf</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;partitioner&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
<span class="n">npart</span> <span class="o">=</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;npart&#39;</span><span class="p">]</span> <span class="k">if</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;npart&#39;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">10</span> <span class="k">else</span> <span class="mi">10</span>
<span class="n">partitioner</span> <span class="o">=</span> <span class="n">Entropy</span><span class="o">.</span><span class="n">EntropyPartitioner</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">npart</span><span class="p">,</span> <span class="n">func</span><span class="o">=</span><span class="n">mf</span><span class="p">)</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">hofts</span><span class="o">.</span><span class="n">WeightedHighOrderFTS</span><span class="p">(</span><span class="n">partitioner</span><span class="o">=</span><span class="n">partitioner</span><span class="p">,</span>
<span class="n">lags</span><span class="o">=</span><span class="n">individual</span><span class="p">[</span><span class="s1">&#39;lags&#39;</span><span class="p">],</span>
<span class="n">alpha_cut</span><span class="o">=</span><span class="n">individual</span><span class="p">[</span><span class="s1">&#39;alpha&#39;</span><span class="p">],</span>
<span class="n">order</span><span class="o">=</span><span class="n">individual</span><span class="p">[</span><span class="s1">&#39;order&#39;</span><span class="p">])</span>
<span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">train</span><span class="p">)</span>
<span class="n">forecasts</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">test</span><span class="p">)</span>
<span class="c1">#rmse, mape, u = Measures.get_point_statistics(test, model)</span>
<span class="n">rmse</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">test</span><span class="p">[</span><span class="n">model</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="n">forecasts</span><span class="p">)</span>
<span class="n">size</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">model</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">rmse</span><span class="p">)</span>
<span class="n">sizes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">size</span><span class="p">)</span>
<span class="k">return</span> <span class="p">{</span><span class="s1">&#39;parameters&#39;</span><span class="p">:</span> <span class="n">individual</span><span class="p">,</span> <span class="s1">&#39;rmse&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmean</span><span class="p">(</span><span class="n">errors</span><span class="p">),</span> <span class="s1">&#39;size&#39;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmean</span><span class="p">(</span><span class="n">size</span><span class="p">)}</span></div>
<div class="viewcode-block" id="process_jobs"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.GridSearch.process_jobs">[docs]</a><span class="k">def</span> <span class="nf">process_jobs</span><span class="p">(</span><span class="n">jobs</span><span class="p">,</span> <span class="n">datasetname</span><span class="p">,</span> <span class="n">conn</span><span class="p">):</span>
<span class="kn">from</span> <span class="nn">pyFTS.distributed</span> <span class="kn">import</span> <span class="n">dispy</span> <span class="k">as</span> <span class="n">dUtil</span>
<span class="kn">import</span> <span class="nn">dispy</span>
<span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">job</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">jobs</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Processing job </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ct</span><span class="p">))</span>
<span class="n">result</span> <span class="o">=</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">result</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Processing result of </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">result</span><span class="p">))</span>
<span class="n">metrics</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;rmse&#39;</span><span class="p">:</span> <span class="n">result</span><span class="p">[</span><span class="s1">&#39;rmse&#39;</span><span class="p">],</span> <span class="s1">&#39;size&#39;</span><span class="p">:</span> <span class="n">result</span><span class="p">[</span><span class="s1">&#39;size&#39;</span><span class="p">]}</span>
<span class="k">for</span> <span class="n">metric</span> <span class="ow">in</span> <span class="n">metrics</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="n">param</span> <span class="o">=</span> <span class="n">result</span><span class="p">[</span><span class="s1">&#39;parameters&#39;</span><span class="p">]</span>
<span class="n">record</span> <span class="o">=</span> <span class="p">(</span><span class="n">datasetname</span><span class="p">,</span> <span class="s1">&#39;GridSearch&#39;</span><span class="p">,</span> <span class="s1">&#39;WHOFTS&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">param</span><span class="p">[</span><span class="s1">&#39;mf&#39;</span><span class="p">],</span>
<span class="n">param</span><span class="p">[</span><span class="s1">&#39;order&#39;</span><span class="p">],</span> <span class="n">param</span><span class="p">[</span><span class="s1">&#39;partitioner&#39;</span><span class="p">],</span> <span class="n">param</span><span class="p">[</span><span class="s1">&#39;npart&#39;</span><span class="p">],</span>
<span class="n">param</span><span class="p">[</span><span class="s1">&#39;alpha&#39;</span><span class="p">],</span> <span class="nb">str</span><span class="p">(</span><span class="n">param</span><span class="p">[</span><span class="s1">&#39;lags&#39;</span><span class="p">]),</span> <span class="n">metric</span><span class="p">,</span> <span class="n">metrics</span><span class="p">[</span><span class="n">metric</span><span class="p">])</span>
<span class="n">hUtil</span><span class="o">.</span><span class="n">insert_hyperparam</span><span class="p">(</span><span class="n">record</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="n">job</span><span class="o">.</span><span class="n">exception</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">job</span><span class="o">.</span><span class="n">stdout</span><span class="p">)</span></div>
<div class="viewcode-block" id="execute"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.GridSearch.execute">[docs]</a><span class="k">def</span> <span class="nf">execute</span><span class="p">(</span><span class="n">hyperparams</span><span class="p">,</span> <span class="n">datasetname</span><span class="p">,</span> <span class="n">dataset</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="kn">from</span> <span class="nn">pyFTS.distributed</span> <span class="kn">import</span> <span class="n">dispy</span> <span class="k">as</span> <span class="n">dUtil</span>
<span class="kn">import</span> <span class="nn">dispy</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="s1">&#39;nodes&#39;</span><span class="p">,[</span><span class="s1">&#39;127.0.0.1&#39;</span><span class="p">])</span>
<span class="n">individuals</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="s1">&#39;lags&#39;</span> <span class="ow">in</span> <span class="n">hyperparams</span><span class="p">:</span>
<span class="n">lags</span> <span class="o">=</span> <span class="n">hyperparams</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;lags&#39;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">lags</span> <span class="o">=</span> <span class="p">[</span><span class="n">k</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">50</span><span class="p">)]</span>
<span class="n">keys_sorted</span> <span class="o">=</span> <span class="p">[</span><span class="n">k</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">hyperparams</span><span class="o">.</span><span class="n">keys</span><span class="p">())]</span>
<span class="n">index</span> <span class="o">=</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="nb">len</span><span class="p">(</span><span class="n">keys_sorted</span><span class="p">)):</span>
<span class="n">index</span><span class="p">[</span><span class="n">keys_sorted</span><span class="p">[</span><span class="n">k</span><span class="p">]]</span> <span class="o">=</span> <span class="n">k</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Evaluation order: </span><span class="se">\n</span><span class="s2"> </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">index</span><span class="p">))</span>
<span class="n">hp_values</span> <span class="o">=</span> <span class="p">[</span>
<span class="p">[</span><span class="n">v</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">hyperparams</span><span class="p">[</span><span class="n">hp</span><span class="p">]]</span>
<span class="k">for</span> <span class="n">hp</span> <span class="ow">in</span> <span class="n">keys_sorted</span>
<span class="p">]</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Evaluation values: </span><span class="se">\n</span><span class="s2"> </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">hp_values</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">dUtil</span><span class="o">.</span><span class="n">start_dispy_cluster</span><span class="p">(</span><span class="n">cluster_method</span><span class="p">,</span> <span class="n">nodes</span><span class="o">=</span><span class="n">nodes</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="s1">&#39;hyperparam.db&#39;</span><span class="p">)</span>
<span class="n">conn</span> <span class="o">=</span> <span class="n">hUtil</span><span class="o">.</span><span class="n">open_hyperparam_db</span><span class="p">(</span><span class="n">file</span><span class="p">)</span>
<span class="k">for</span> <span class="n">instance</span> <span class="ow">in</span> <span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">hp_values</span><span class="p">):</span>
<span class="n">partitions</span> <span class="o">=</span> <span class="n">instance</span><span class="p">[</span><span class="n">index</span><span class="p">[</span><span class="s1">&#39;partitions&#39;</span><span class="p">]]</span>
<span class="n">partitioner</span> <span class="o">=</span> <span class="n">instance</span><span class="p">[</span><span class="n">index</span><span class="p">[</span><span class="s1">&#39;partitioner&#39;</span><span class="p">]]</span>
<span class="n">mf</span> <span class="o">=</span> <span class="n">instance</span><span class="p">[</span><span class="n">index</span><span class="p">[</span><span class="s1">&#39;mf&#39;</span><span class="p">]]</span>
<span class="n">alpha_cut</span> <span class="o">=</span> <span class="n">instance</span><span class="p">[</span><span class="n">index</span><span class="p">[</span><span class="s1">&#39;alpha&#39;</span><span class="p">]]</span>
<span class="n">order</span> <span class="o">=</span> <span class="n">instance</span><span class="p">[</span><span class="n">index</span><span class="p">[</span><span class="s1">&#39;order&#39;</span><span class="p">]]</span>
<span class="n">count</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">lag1</span> <span class="ow">in</span> <span class="n">lags</span><span class="p">:</span> <span class="c1"># o é o lag1</span>
<span class="n">_lags</span> <span class="o">=</span> <span class="p">[</span><span class="n">lag1</span><span class="p">]</span>
<span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="k">if</span> <span class="n">order</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
<span class="k">for</span> <span class="n">lag2</span> <span class="ow">in</span> <span class="n">lags</span><span class="p">:</span> <span class="c1"># o é o lag1</span>
<span class="n">_lags2</span> <span class="o">=</span> <span class="p">[</span><span class="n">lag1</span><span class="p">,</span> <span class="n">lag1</span><span class="o">+</span><span class="n">lag2</span><span class="p">]</span>
<span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="k">if</span> <span class="n">order</span> <span class="o">&gt;</span> <span class="mi">2</span><span class="p">:</span>
<span class="k">for</span> <span class="n">lag3</span> <span class="ow">in</span> <span class="n">lags</span><span class="p">:</span> <span class="c1"># o é o lag1</span>
<span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="n">_lags3</span> <span class="o">=</span> <span class="p">[</span><span class="n">lag1</span><span class="p">,</span> <span class="n">lag1</span> <span class="o">+</span> <span class="n">lag2</span><span class="p">,</span> <span class="n">lag1</span> <span class="o">+</span> <span class="n">lag2</span><span class="o">+</span><span class="n">lag3</span> <span class="p">]</span>
<span class="n">individuals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dict_individual</span><span class="p">(</span><span class="n">mf</span><span class="p">,</span> <span class="n">partitioner</span><span class="p">,</span> <span class="n">partitions</span><span class="p">,</span> <span class="n">order</span><span class="p">,</span> <span class="n">_lags3</span><span class="p">,</span> <span class="n">alpha_cut</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">individuals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
<span class="n">dict_individual</span><span class="p">(</span><span class="n">mf</span><span class="p">,</span> <span class="n">partitioner</span><span class="p">,</span> <span class="n">partitions</span><span class="p">,</span> <span class="n">order</span><span class="p">,</span> <span class="n">_lags2</span><span class="p">,</span> <span class="n">alpha_cut</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">individuals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dict_individual</span><span class="p">(</span><span class="n">mf</span><span class="p">,</span> <span class="n">partitioner</span><span class="p">,</span> <span class="n">partitions</span><span class="p">,</span> <span class="n">order</span><span class="p">,</span> <span class="n">_lags</span><span class="p">,</span> <span class="n">alpha_cut</span><span class="p">))</span>
<span class="k">if</span> <span class="n">count</span> <span class="o">&gt;</span> <span class="mi">10</span><span class="p">:</span>
<span class="n">jobs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">ind</span> <span class="ow">in</span> <span class="n">individuals</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Testing individual </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ind</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">ind</span><span class="p">,</span> <span class="n">dataset</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">process_jobs</span><span class="p">(</span><span class="n">jobs</span><span class="p">,</span> <span class="n">datasetname</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
<span class="n">count</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">individuals</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">dUtil</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></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.hyperparam.GridSearch</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,189 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.chen &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.chen</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.chen</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">First Order Conventional Fuzzy Time Series by Chen (1996)</span>
<span class="sd">S.-M. Chen, “Forecasting enrollments based on fuzzy time series,” Fuzzy Sets Syst., vol. 81, no. 3, pp. 311319, 1996.</span>
<span class="sd">&quot;&quot;&quot;</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.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">FLR</span><span class="p">,</span> <span class="n">fts</span><span class="p">,</span> <span class="n">flrg</span>
<div class="viewcode-block" id="ConventionalFLRG"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.chen.ConventionalFLRG">[docs]</a><span class="k">class</span> <span class="nc">ConventionalFLRG</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">FLRG</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;First Order Conventional Fuzzy Logical Relationship Group&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">LHS</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">ConventionalFLRG</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">LHS</span> <span class="o">=</span> <span class="n">LHS</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
<div class="viewcode-block" id="ConventionalFLRG.get_key"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.chen.ConventionalFLRG.get_key">[docs]</a> <span class="k">def</span> <span class="nf">get_key</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sets</span><span class="p">):</span>
<span class="k">return</span> <span class="n">sets</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">name</span></div>
<div class="viewcode-block" id="ConventionalFLRG.append_rhs"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.chen.ConventionalFLRG.append_rhs">[docs]</a> <span class="k">def</span> <span class="nf">append_rhs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">c</span><span class="p">)</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; -&gt; &quot;</span>
<span class="n">tmp2</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="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">s</span><span class="p">:</span> <span class="n">s</span><span class="p">):</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">tmp2</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">tmp2</span> <span class="o">=</span> <span class="n">tmp2</span> <span class="o">+</span> <span class="s2">&quot;,&quot;</span>
<span class="n">tmp2</span> <span class="o">=</span> <span class="n">tmp2</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="k">return</span> <span class="n">tmp</span> <span class="o">+</span> <span class="n">tmp2</span></div>
<div class="viewcode-block" id="ConventionalFTS"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.chen.ConventionalFTS">[docs]</a><span class="k">class</span> <span class="nc">ConventionalFTS</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Conventional Fuzzy Time Series&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">ConventionalFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</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="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Conventional FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;Chen&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;CFTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span> <span class="o">=</span> <span class="p">{}</span>
<div class="viewcode-block" id="ConventionalFTS.generate_flrg"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.chen.ConventionalFTS.generate_flrg">[docs]</a> <span class="k">def</span> <span class="nf">generate_flrg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrs</span><span class="p">):</span>
<span class="k">for</span> <span class="n">flr</span> <span class="ow">in</span> <span class="n">flrs</span><span class="p">:</span>
<span class="k">if</span> <span class="n">flr</span><span class="o">.</span><span class="n">LHS</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span> <span class="o">=</span> <span class="n">ConventionalFLRG</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div>
<div class="viewcode-block" id="ConventionalFTS.train"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.chen.ConventionalFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">tmpdata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">fuzzyfy</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;maximum&#39;</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;sets&#39;</span><span class="p">)</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_non_recurrent_flrs</span><span class="p">(</span><span class="n">tmpdata</span><span class="p">,</span> <span class="n">steps</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">standard_horizon</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg</span><span class="p">(</span><span class="n">flrs</span><span class="p">)</span></div>
<div class="viewcode-block" id="ConventionalFTS.forecast"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.chen.ConventionalFTS.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">explain</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;explain&#39;</span><span class="p">,</span><span class="kc">False</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">ndata</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">explain</span> <span class="k">else</span> <span class="mi">1</span>
<span class="n">ret</span> <span class="o">=</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">actual</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">get_maximum_membership_fuzzyset</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Fuzzyfication:</span><span class="se">\n\n</span><span class="s2"> </span><span class="si">{}</span><span class="s2"> -&gt; </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">actual</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
<span class="k">if</span> <span class="n">actual</span><span class="o">.</span><span class="n">name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</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">actual</span><span class="o">.</span><span class="n">centroid</span><span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Rules:</span><span class="se">\n\n</span><span class="s2"> </span><span class="si">{}</span><span class="s2"> -&gt; </span><span class="si">{}</span><span class="s2"> (Naïve)</span><span class="se">\t</span><span class="s2"> Midpoint: </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">actual</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">actual</span><span class="o">.</span><span class="n">name</span><span class="p">,</span><span class="n">actual</span><span class="o">.</span><span class="n">centroid</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">_flrg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">actual</span><span class="o">.</span><span class="n">name</span><span class="p">]</span>
<span class="n">mp</span> <span class="o">=</span> <span class="n">_flrg</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</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">mp</span><span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Rules:</span><span class="se">\n\n</span><span class="s2"> </span><span class="si">{}</span><span class="s2"> </span><span class="se">\t</span><span class="s2"> Midpoint: </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">_flrg</span><span class="p">),</span> <span class="n">mp</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Deffuzyfied value: </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">mp</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ret</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.chen</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,160 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.cheng &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.cheng</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.cheng</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Trend Weighted Fuzzy Time Series by Cheng, Chen and Wu (2009)</span>
<span class="sd">C.-H. Cheng, Y.-S. Chen, and Y.-L. Wu, “Forecasting innovation diffusion of products using trend-weighted fuzzy time-series model,” </span>
<span class="sd">Expert Syst. Appl., vol. 36, no. 2, pp. 18261832, 2009.</span>
<span class="sd">&quot;&quot;&quot;</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.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">FLR</span><span class="p">,</span> <span class="n">fts</span>
<span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="kn">import</span> <span class="n">yu</span>
<div class="viewcode-block" id="TrendWeightedFLRG"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.cheng.TrendWeightedFLRG">[docs]</a><span class="k">class</span> <span class="nc">TrendWeightedFLRG</span><span class="p">(</span><span class="n">yu</span><span class="o">.</span><span class="n">WeightedFLRG</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> First Order Trend Weighted Fuzzy Logical Relationship Group</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">LHS</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">TrendWeightedFLRG</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">LHS</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">w</span> <span class="o">=</span> <span class="kc">None</span>
<div class="viewcode-block" id="TrendWeightedFLRG.weights"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.cheng.TrendWeightedFLRG.weights">[docs]</a> <span class="k">def</span> <span class="nf">weights</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sets</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">count_nochange</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="n">count_up</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="n">count_down</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="n">weights</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">if</span> <span class="n">sets</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span> <span class="o">==</span> <span class="n">sets</span><span class="p">[</span><span class="n">c</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span><span class="p">:</span>
<span class="n">count_nochange</span> <span class="o">+=</span> <span class="mf">1.0</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">count_nochange</span>
<span class="k">elif</span> <span class="n">sets</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span> <span class="o">&gt;</span> <span class="n">sets</span><span class="p">[</span><span class="n">c</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span><span class="p">:</span>
<span class="n">count_down</span> <span class="o">+=</span> <span class="mf">1.0</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">count_down</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">count_up</span> <span class="o">+=</span> <span class="mf">1.0</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">count_up</span>
<span class="n">weights</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>
<span class="n">tot</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">weights</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">w</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="n">k</span> <span class="o">/</span> <span class="n">tot</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">weights</span><span class="p">])</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span></div></div>
<div class="viewcode-block" id="TrendWeightedFTS"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.cheng.TrendWeightedFTS">[docs]</a><span class="k">class</span> <span class="nc">TrendWeightedFTS</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="sd">&quot;&quot;&quot;First Order Trend Weighted Fuzzy Time Series&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">TrendWeightedFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;TWFTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Trend Weighted FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;Cheng&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">False</span>
<div class="viewcode-block" id="TrendWeightedFTS.generate_FLRG"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.cheng.TrendWeightedFTS.generate_FLRG">[docs]</a> <span class="k">def</span> <span class="nf">generate_FLRG</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrs</span><span class="p">):</span>
<span class="k">for</span> <span class="n">flr</span> <span class="ow">in</span> <span class="n">flrs</span><span class="p">:</span>
<span class="k">if</span> <span class="n">flr</span><span class="o">.</span><span class="n">LHS</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span> <span class="o">=</span> <span class="n">TrendWeightedFLRG</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.cheng</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,453 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.ensemble.ensemble &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
<script src="../../../../_static/jquery.js"></script>
<script src="../../../../_static/underscore.js"></script>
<script src="../../../../_static/doctools.js"></script>
<script src="../../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.ensemble.ensemble</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.ensemble.ensemble</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">EnsembleFTS wraps several FTS methods to ensemble their forecasts, providing point,</span>
<span class="sd">interval and probabilistic forecasting.</span>
<span class="sd">Silva, P. C. L et al. Probabilistic Forecasting with Seasonal Ensemble Fuzzy Time-Series</span>
<span class="sd">XIII Brazilian Congress on Computational Intelligence, 2017. Rio de Janeiro, Brazil.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">SortedCollection</span><span class="p">,</span> <span class="n">fts</span><span class="p">,</span> <span class="n">tree</span>
<span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="kn">import</span> <span class="n">chen</span><span class="p">,</span> <span class="n">cheng</span><span class="p">,</span> <span class="n">hofts</span><span class="p">,</span> <span class="n">hwang</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">yu</span>
<span class="kn">from</span> <span class="nn">pyFTS.probabilistic</span> <span class="kn">import</span> <span class="n">ProbabilityDistribution</span>
<span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="kn">import</span> <span class="n">Grid</span>
<span class="kn">import</span> <span class="nn">scipy.stats</span> <span class="k">as</span> <span class="nn">st</span>
<span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">product</span>
<div class="viewcode-block" id="sampler"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.sampler">[docs]</a><span class="k">def</span> <span class="nf">sampler</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">quantiles</span><span class="p">,</span> <span class="n">bounds</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">qt</span> <span class="ow">in</span> <span class="n">quantiles</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">np</span><span class="o">.</span><span class="n">nanpercentile</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">q</span><span class="o">=</span><span class="n">qt</span> <span class="o">*</span> <span class="mi">100</span><span class="p">))</span>
<span class="k">if</span> <span class="n">bounds</span><span class="p">:</span>
<span class="n">ret</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="nb">min</span><span class="p">(</span><span class="n">data</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="nb">max</span><span class="p">(</span><span class="n">data</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="EnsembleFTS"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.EnsembleFTS">[docs]</a><span class="k">class</span> <span class="nc">EnsembleFTS</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Ensemble FTS</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">EnsembleFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;EnsembleFTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Ensemble FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_wrapper</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_point_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_interval_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_probability_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">models</span> <span class="o">=</span> <span class="p">[]</span>
<span class="sd">&quot;&quot;&quot;A list of FTS models, the ensemble components&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">parameters</span> <span class="o">=</span> <span class="p">[]</span>
<span class="sd">&quot;&quot;&quot;A list with the parameters for each component model&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">alpha</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;alpha&quot;</span><span class="p">,</span> <span class="mf">0.05</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;The quantiles &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">point_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;point_method&#39;</span><span class="p">,</span> <span class="s1">&#39;mean&#39;</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;The method used to mix the several model&#39;s forecasts into a unique point forecast. Options: mean, median, quantile, exponential&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">interval_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;interval_method&#39;</span><span class="p">,</span> <span class="s1">&#39;quantile&#39;</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;The method used to mix the several model&#39;s forecasts into a interval forecast. Options: quantile, extremum, normal&quot;&quot;&quot;</span>
<div class="viewcode-block" id="EnsembleFTS.append_model"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.EnsembleFTS.append_model">[docs]</a> <span class="k">def</span> <span class="nf">append_model</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Append a new trained model to the ensemble</span>
<span class="sd"> :param model: FTS model</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">models</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="k">if</span> <span class="n">model</span><span class="o">.</span><span class="n">order</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">order</span>
<span class="k">if</span> <span class="n">model</span><span class="o">.</span><span class="n">is_multivariate</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_multivariate</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">if</span> <span class="n">model</span><span class="o">.</span><span class="n">has_seasonality</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_seasonality</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">if</span> <span class="n">model</span><span class="o">.</span><span class="n">original_min</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_min</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">original_min</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">original_min</span>
<span class="k">elif</span> <span class="n">model</span><span class="o">.</span><span class="n">original_max</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_max</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">original_max</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">original_max</span></div>
<div class="viewcode-block" id="EnsembleFTS.get_UoD"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.EnsembleFTS.get_UoD">[docs]</a> <span class="k">def</span> <span class="nf">get_UoD</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">original_min</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_max</span><span class="p">]</span></div>
<div class="viewcode-block" id="EnsembleFTS.train"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.EnsembleFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">pass</span></div>
<div class="viewcode-block" id="EnsembleFTS.get_models_forecasts"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.EnsembleFTS.get_models_forecasts">[docs]</a> <span class="k">def</span> <span class="nf">get_models_forecasts</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">data</span><span class="p">):</span>
<span class="n">tmp</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="bp">self</span><span class="o">.</span><span class="n">models</span><span class="p">:</span>
<span class="k">if</span> <span class="n">model</span><span class="o">.</span><span class="n">is_multivariate</span> <span class="ow">or</span> <span class="n">model</span><span class="o">.</span><span class="n">has_seasonality</span><span class="p">:</span>
<span class="n">forecast</span> <span class="o">=</span> <span class="n">model</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="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">)</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">indexer</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">indexer</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="o">-</span><span class="n">model</span><span class="o">.</span><span class="n">order</span><span class="p">:]</span>
<span class="n">forecast</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">forecast</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</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="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">forecast</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">forecast</span> <span class="o">=</span> <span class="n">forecast</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">forecast</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</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="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">forecast</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">forecast</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">forecast</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">forecast</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">forecast</span><span class="p">)</span>
<span class="k">return</span> <span class="n">tmp</span></div>
<div class="viewcode-block" id="EnsembleFTS.get_point"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.EnsembleFTS.get_point">[docs]</a> <span class="k">def</span> <span class="nf">get_point</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">forecasts</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="bp">self</span><span class="o">.</span><span class="n">point_method</span> <span class="o">==</span> <span class="s1">&#39;mean&#39;</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmean</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">point_method</span> <span class="o">==</span> <span class="s1">&#39;median&#39;</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanpercentile</span><span class="p">(</span><span class="n">forecasts</span><span class="p">,</span> <span class="mi">50</span><span class="p">)</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">point_method</span> <span class="o">==</span> <span class="s1">&#39;quantile&#39;</span><span class="p">:</span>
<span class="n">alpha</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;alpha&quot;</span><span class="p">,</span><span class="mf">0.05</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanpercentile</span><span class="p">(</span><span class="n">forecasts</span><span class="p">,</span> <span class="n">alpha</span><span class="o">*</span><span class="mi">100</span><span class="p">)</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">point_method</span> <span class="o">==</span> <span class="s1">&#39;exponential&#39;</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="bp">self</span><span class="o">.</span><span class="n">models</span><span class="p">)</span>
<span class="k">if</span> <span class="n">l</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="k">return</span> <span class="n">forecasts</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">w</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="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="p">(</span><span class="n">l</span> <span class="o">-</span> <span class="n">k</span><span class="p">))</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="n">l</span><span class="p">)])</span>
<span class="n">w</span> <span class="o">=</span> <span class="n">w</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">w</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">([</span><span class="n">w</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">*</span> <span class="n">forecasts</span><span class="p">[</span><span class="n">k</span><span class="p">]</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="n">l</span><span class="p">)])</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="EnsembleFTS.get_interval"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.EnsembleFTS.get_interval">[docs]</a> <span class="k">def</span> <span class="nf">get_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">forecasts</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">interval_method</span> <span class="o">==</span> <span class="s1">&#39;extremum&#39;</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="nb">min</span><span class="p">(</span><span class="n">forecasts</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="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">interval_method</span> <span class="o">==</span> <span class="s1">&#39;quantile&#39;</span><span class="p">:</span>
<span class="n">qt_lo</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanpercentile</span><span class="p">(</span><span class="n">forecasts</span><span class="p">,</span> <span class="n">q</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">alpha</span> <span class="o">*</span> <span class="mi">100</span><span class="p">)</span>
<span class="n">qt_up</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanpercentile</span><span class="p">(</span><span class="n">forecasts</span><span class="p">,</span> <span class="n">q</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">alpha</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</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">qt_lo</span><span class="p">,</span> <span class="n">qt_up</span><span class="p">])</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">interval_method</span> <span class="o">==</span> <span class="s1">&#39;normal&#39;</span><span class="p">:</span>
<span class="n">mu</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmean</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span>
<span class="n">sigma</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">nanvar</span><span class="p">(</span><span class="n">forecasts</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">mu</span> <span class="o">+</span> <span class="n">st</span><span class="o">.</span><span class="n">norm</span><span class="o">.</span><span class="n">ppf</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">alpha</span><span class="p">)</span> <span class="o">*</span> <span class="n">sigma</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">mu</span> <span class="o">+</span> <span class="n">st</span><span class="o">.</span><span class="n">norm</span><span class="o">.</span><span class="n">ppf</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">alpha</span><span class="p">)</span> <span class="o">*</span> <span class="n">sigma</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="EnsembleFTS.get_distribution_interquantile"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.EnsembleFTS.get_distribution_interquantile">[docs]</a> <span class="k">def</span> <span class="nf">get_distribution_interquantile</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">forecasts</span><span class="p">,</span> <span class="n">alpha</span><span class="p">):</span>
<span class="n">size</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span>
<span class="n">qt_lower</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">size</span> <span class="o">*</span> <span class="n">alpha</span><span class="p">))</span> <span class="o">-</span> <span class="mi">1</span>
<span class="n">qt_upper</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">size</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span><span class="o">-</span> <span class="n">alpha</span><span class="p">)))</span> <span class="o">-</span> <span class="mi">1</span>
<span class="n">ret</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)[</span><span class="n">qt_lower</span> <span class="p">:</span> <span class="n">qt_upper</span><span class="p">]</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="EnsembleFTS.forecast"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.EnsembleFTS.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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="s2">&quot;method&quot;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">point_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="s1">&#39;mean&#39;</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">data</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">l</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_models_forecasts</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="n">point</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_point</span><span class="p">(</span><span class="n">tmp</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">point</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="EnsembleFTS.forecast_interval"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.EnsembleFTS.forecast_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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="s2">&quot;method&quot;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">interval_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="s1">&#39;quantile&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">alpha</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;alpha&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">alpha</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">data</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">l</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_models_forecasts</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="n">interval</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_interval</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">interval</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">interval</span> <span class="o">=</span> <span class="n">interval</span><span class="p">[</span><span class="o">-</span><span class="mi">1</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">interval</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="EnsembleFTS.forecast_ahead_interval"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.EnsembleFTS.forecast_ahead_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</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="s1">&#39;method&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">interval_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="s1">&#39;quantile&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">alpha</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;alpha&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">alpha</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">start</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;start_at&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">)</span>
<span class="n">sample</span> <span class="o">=</span> <span class="p">[[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="n">start</span><span class="p">:</span> <span class="n">start</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">order</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">steps</span> <span class="o">+</span> <span class="bp">self</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="p">[]</span>
<span class="n">lags</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">i</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">):</span>
<span class="n">lags</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sample</span><span class="p">[</span><span class="n">i</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">])</span>
<span class="c1"># Trace the possible paths</span>
<span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">lags</span><span class="p">):</span>
<span class="n">forecasts</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_models_forecasts</span><span class="p">(</span><span class="n">path</span><span class="p">))</span>
<span class="n">sample</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sampler</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">arange</span><span class="p">(</span><span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">),</span> <span class="n">bounds</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
<span class="n">interval</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_interval</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">interval</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">interval</span> <span class="o">=</span> <span class="n">interval</span><span class="p">[</span><span class="mi">0</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">interval</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span><span class="p">[</span><span class="o">-</span><span class="n">steps</span><span class="p">:]</span></div>
<div class="viewcode-block" id="EnsembleFTS.forecast_distribution"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.EnsembleFTS.forecast_distribution">[docs]</a> <span class="k">def</span> <span class="nf">forecast_distribution</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">smooth</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;smooth&quot;</span><span class="p">,</span> <span class="s2">&quot;KDE&quot;</span><span class="p">)</span>
<span class="n">alpha</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;alpha&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="n">uod</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_UoD</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="bp">self</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">data</span><span class="p">)):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">forecasts</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_models_forecasts</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="k">if</span> <span class="n">alpha</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">forecasts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ravel</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">forecasts</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_distribution_interquantile</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ravel</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span><span class="o">.</span><span class="n">tolist</span><span class="p">(),</span> <span class="n">alpha</span><span class="p">)</span>
<span class="n">dist</span> <span class="o">=</span> <span class="n">ProbabilityDistribution</span><span class="o">.</span><span class="n">ProbabilityDistribution</span><span class="p">(</span><span class="n">smooth</span><span class="p">,</span> <span class="n">uod</span><span class="o">=</span><span class="n">uod</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">forecasts</span><span class="p">,</span>
<span class="n">name</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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">dist</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="EnsembleFTS.forecast_ahead_distribution"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.EnsembleFTS.forecast_ahead_distribution">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_distribution</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</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="s1">&#39;method&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">point_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="s1">&#39;mean&#39;</span><span class="p">)</span>
<span class="n">smooth</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;smooth&quot;</span><span class="p">,</span> <span class="s2">&quot;histogram&quot;</span><span class="p">)</span>
<span class="n">alpha</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;alpha&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">start</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;start_at&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">)</span>
<span class="n">uod</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_UoD</span><span class="p">()</span>
<span class="n">sample</span> <span class="o">=</span> <span class="p">[[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="n">start</span><span class="p">:</span> <span class="n">start</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">order</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">steps</span><span class="o">+</span><span class="bp">self</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="p">[]</span>
<span class="n">lags</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">i</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">):</span>
<span class="n">lags</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sample</span><span class="p">[</span><span class="n">i</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">])</span>
<span class="c1"># Trace the possible paths</span>
<span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">lags</span><span class="p">):</span>
<span class="n">forecasts</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_models_forecasts</span><span class="p">(</span><span class="n">path</span><span class="p">))</span>
<span class="n">sample</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sampler</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">arange</span><span class="p">(</span><span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">),</span> <span class="n">bounds</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
<span class="k">if</span> <span class="n">alpha</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">forecasts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ravel</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">forecasts</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_distribution_interquantile</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ravel</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span><span class="o">.</span><span class="n">tolist</span><span class="p">(),</span> <span class="n">alpha</span><span class="p">)</span>
<span class="n">dist</span> <span class="o">=</span> <span class="n">ProbabilityDistribution</span><span class="o">.</span><span class="n">ProbabilityDistribution</span><span class="p">(</span><span class="n">smooth</span><span class="p">,</span> <span class="n">uod</span><span class="o">=</span><span class="n">uod</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">forecasts</span><span class="p">,</span>
<span class="n">name</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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">dist</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span><span class="p">[</span><span class="o">-</span><span class="n">steps</span><span class="p">:]</span></div></div>
<div class="viewcode-block" id="SimpleEnsembleFTS"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.SimpleEnsembleFTS">[docs]</a><span class="k">class</span> <span class="nc">SimpleEnsembleFTS</span><span class="p">(</span><span class="n">EnsembleFTS</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;</span>
<span class="sd"> An homogeneous FTS method ensemble with variations on partitionings and orders.</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">SimpleEnsembleFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</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;fts_method&#39;</span><span class="p">,</span> <span class="n">hofts</span><span class="o">.</span><span class="n">WeightedHighOrderFTS</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;FTS method class that will be used on internal models&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner_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;partitioner_method&#39;</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="sd">&quot;&quot;&quot;UoD partitioner class that will be used on internal methods&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitions</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;partitions&#39;</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">15</span><span class="p">,</span><span class="mi">35</span><span class="p">,</span><span class="mi">10</span><span class="p">))</span>
<span class="sd">&quot;&quot;&quot;Possible variations of number of partitions on internal models&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">orders</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;orders&#39;</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="sd">&quot;&quot;&quot;Possible variations of order on internal models&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">uod_clip</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</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;name&#39;</span><span class="p">,</span> <span class="s1">&#39;EnsembleFTS-&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">method</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>
<div class="viewcode-block" id="SimpleEnsembleFTS.train"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.SimpleEnsembleFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitions</span><span class="p">:</span>
<span class="n">fs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner_method</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">k</span><span class="p">)</span>
<span class="k">for</span> <span class="n">order</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">orders</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span><span class="p">(</span><span class="n">partitioner</span><span class="o">=</span><span class="n">fs</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">tmp</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">append_model</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span></div></div>
<div class="viewcode-block" id="AllMethodEnsembleFTS"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.AllMethodEnsembleFTS">[docs]</a><span class="k">class</span> <span class="nc">AllMethodEnsembleFTS</span><span class="p">(</span><span class="n">EnsembleFTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Creates an EnsembleFTS with all point forecast methods, sharing the same partitioner</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">AllMethodEnsembleFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_order</span> <span class="o">=</span> <span class="mi">3</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span><span class="s2">&quot;Ensemble FTS&quot;</span>
<div class="viewcode-block" id="AllMethodEnsembleFTS.set_transformations"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.AllMethodEnsembleFTS.set_transformations">[docs]</a> <span class="k">def</span> <span class="nf">set_transformations</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">):</span>
<span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">transformations</span><span class="p">:</span>
<span class="n">model</span><span class="o">.</span><span class="n">append_transformation</span><span class="p">(</span><span class="n">t</span><span class="p">)</span></div>
<div class="viewcode-block" id="AllMethodEnsembleFTS.train"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.AllMethodEnsembleFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">fo_methods</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">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">ismailefendi</span><span class="o">.</span><span class="n">ImprovedWeightedFTS</span><span class="p">]</span>
<span class="n">ho_methods</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">hwang</span><span class="o">.</span><span class="n">HighOrderFTS</span><span class="p">]</span>
<span class="k">for</span> <span class="n">method</span> <span class="ow">in</span> <span class="n">fo_methods</span><span class="p">:</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">method</span><span class="p">(</span><span class="n">partitioner</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_transformations</span><span class="p">(</span><span class="n">model</span><span class="p">)</span>
<span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">append_model</span><span class="p">(</span><span class="n">model</span><span class="p">)</span>
<span class="k">for</span> <span class="n">method</span> <span class="ow">in</span> <span class="n">ho_methods</span><span class="p">:</span>
<span class="k">for</span> <span class="n">o</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">method</span><span class="p">(</span><span class="n">partitioner</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="p">)</span>
<span class="k">if</span> <span class="n">model</span><span class="o">.</span><span class="n">min_order</span> <span class="o">&gt;=</span> <span class="n">o</span><span class="p">:</span>
<span class="n">model</span><span class="o">.</span><span class="n">order</span> <span class="o">=</span> <span class="n">o</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_transformations</span><span class="p">(</span><span class="n">model</span><span class="p">)</span>
<span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">append_model</span><span class="p">(</span><span class="n">model</span><span class="p">)</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.ensemble.ensemble</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,192 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.ensemble.multiseasonal &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
<script src="../../../../_static/jquery.js"></script>
<script src="../../../../_static/underscore.js"></script>
<script src="../../../../_static/doctools.js"></script>
<script src="../../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.ensemble.multiseasonal</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.ensemble.multiseasonal</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Silva, P. C. L et al. Probabilistic Forecasting with Seasonal Ensemble Fuzzy Time-Series</span>
<span class="sd">XIII Brazilian Congress on Computational Intelligence, 2017. Rio de Janeiro, Brazil.</span>
<span class="sd">&quot;&quot;&quot;</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.common</span> <span class="kn">import</span> <span class="n">Util</span> <span class="k">as</span> <span class="n">cUtil</span>
<span class="kn">from</span> <span class="nn">pyFTS.models.ensemble</span> <span class="kn">import</span> <span class="n">ensemble</span>
<span class="kn">from</span> <span class="nn">pyFTS.models.seasonal</span> <span class="kn">import</span> <span class="n">cmsfts</span>
<span class="kn">from</span> <span class="nn">pyFTS.probabilistic</span> <span class="kn">import</span> <span class="n">ProbabilityDistribution</span>
<span class="kn">from</span> <span class="nn">copy</span> <span class="kn">import</span> <span class="n">deepcopy</span>
<span class="kn">from</span> <span class="nn">joblib</span> <span class="kn">import</span> <span class="n">Parallel</span><span class="p">,</span> <span class="n">delayed</span>
<span class="kn">import</span> <span class="nn">multiprocessing</span>
<div class="viewcode-block" id="train_individual_model"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.multiseasonal.train_individual_model">[docs]</a><span class="k">def</span> <span class="nf">train_individual_model</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">indexer</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">diff</span> <span class="o">=</span> <span class="s2">&quot;_diff&quot;</span> <span class="k">if</span> <span class="n">partitioner</span><span class="o">.</span><span class="n">transformation</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">_key</span> <span class="o">=</span> <span class="s2">&quot;msfts_&quot;</span> <span class="o">+</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="n">partitions</span><span class="p">)</span> <span class="o">+</span> <span class="n">diff</span> <span class="o">+</span> <span class="s2">&quot;_&quot;</span> <span class="o">+</span> <span class="n">indexer</span><span class="o">.</span><span class="n">name</span>
<span class="nb">print</span><span class="p">(</span><span class="n">_key</span><span class="p">)</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">cmsfts</span><span class="o">.</span><span class="n">ContextualMultiSeasonalFTS</span><span class="p">(</span><span class="n">_key</span><span class="p">,</span> <span class="n">indexer</span><span class="o">=</span><span class="n">indexer</span><span class="p">)</span>
<span class="n">model</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">model</span><span class="o">.</span><span class="n">train</span><span class="p">(</span><span class="n">train_data</span><span class="p">,</span> <span class="n">partitioner</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">cUtil</span><span class="o">.</span><span class="n">persist_obj</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="s2">&quot;models/&quot;</span><span class="o">+</span><span class="n">_key</span><span class="o">+</span><span class="s2">&quot;.pkl&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">model</span></div>
<div class="viewcode-block" id="SeasonalEnsembleFTS"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.multiseasonal.SeasonalEnsembleFTS">[docs]</a><span class="k">class</span> <span class="nc">SeasonalEnsembleFTS</span><span class="p">(</span><span class="n">ensemble</span><span class="o">.</span><span class="n">EnsembleFTS</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">SeasonalEnsembleFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;Seasonal Ensemble FTS&quot;</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_order</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">indexers</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioners</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_multivariate</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_seasonality</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_probability_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<div class="viewcode-block" id="SeasonalEnsembleFTS.update_uod"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.multiseasonal.SeasonalEnsembleFTS.update_uod">[docs]</a> <span class="k">def</span> <span class="nf">update_uod</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">original_max</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">indexer</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">data</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">original_min</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">indexer</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">data</span><span class="p">))</span></div>
<div class="viewcode-block" id="SeasonalEnsembleFTS.train"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.multiseasonal.SeasonalEnsembleFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">original_max</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">indexer</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">data</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">original_min</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">indexer</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">data</span><span class="p">))</span>
<span class="n">num_cores</span> <span class="o">=</span> <span class="n">multiprocessing</span><span class="o">.</span><span class="n">cpu_count</span><span class="p">()</span>
<span class="n">pool</span> <span class="o">=</span> <span class="p">{}</span>
<span class="n">count</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">ix</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">indexers</span><span class="p">:</span>
<span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioners</span><span class="p">:</span>
<span class="n">pool</span><span class="p">[</span><span class="n">count</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;ix&#39;</span><span class="p">:</span> <span class="n">ix</span><span class="p">,</span> <span class="s1">&#39;pt&#39;</span><span class="p">:</span> <span class="n">pt</span><span class="p">}</span>
<span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="n">results</span> <span class="o">=</span> <span class="n">Parallel</span><span class="p">(</span><span class="n">n_jobs</span><span class="o">=</span><span class="n">num_cores</span><span class="p">)(</span>
<span class="n">delayed</span><span class="p">(</span><span class="n">train_individual_model</span><span class="p">)(</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">pool</span><span class="p">[</span><span class="n">m</span><span class="p">][</span><span class="s1">&#39;pt&#39;</span><span class="p">]),</span> <span class="n">data</span><span class="p">,</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">pool</span><span class="p">[</span><span class="n">m</span><span class="p">][</span><span class="s1">&#39;ix&#39;</span><span class="p">]))</span>
<span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">pool</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
<span class="k">for</span> <span class="n">tmp</span> <span class="ow">in</span> <span class="n">results</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">append_model</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>
<span class="n">cUtil</span><span class="o">.</span><span class="n">persist_obj</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">&quot;models/&quot;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="o">+</span><span class="s2">&quot;.pkl&quot;</span><span class="p">)</span></div>
<div class="viewcode-block" id="SeasonalEnsembleFTS.forecast_distribution"><a class="viewcode-back" href="../../../../pyFTS.models.ensemble.html#pyFTS.models.ensemble.multiseasonal.SeasonalEnsembleFTS.forecast_distribution">[docs]</a> <span class="k">def</span> <span class="nf">forecast_distribution</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">smooth</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;smooth&quot;</span><span class="p">,</span> <span class="s2">&quot;KDE&quot;</span><span class="p">)</span>
<span class="n">alpha</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;alpha&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="n">uod</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_UoD</span><span class="p">()</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">index</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_models_forecasts</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">ix</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
<span class="k">if</span> <span class="n">alpha</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ravel</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_distribution_interquantile</span><span class="p">(</span> <span class="n">np</span><span class="o">.</span><span class="n">ravel</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span><span class="o">.</span><span class="n">tolist</span><span class="p">(),</span> <span class="n">alpha</span><span class="p">)</span>
<span class="n">name</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">indexer</span><span class="o">.</span><span class="n">get_index</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">ix</span><span class="p">[</span><span class="n">k</span><span class="p">]))</span>
<span class="n">dist</span> <span class="o">=</span> <span class="n">ProbabilityDistribution</span><span class="o">.</span><span class="n">ProbabilityDistribution</span><span class="p">(</span><span class="n">smooth</span><span class="p">,</span> <span class="n">uod</span><span class="o">=</span><span class="n">uod</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">tmp</span><span class="p">,</span>
<span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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">dist</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.ensemble.multiseasonal</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,395 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.hofts &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.hofts</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.hofts</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">High Order FTS</span>
<span class="sd">Severiano, S. A. Jr; Silva, P. C. L.; Sadaei, H. J.; Guimarães, F. G. Very Short-term Solar Forecasting</span>
<span class="sd">using Fuzzy Time Series. 2017 IEEE International Conference on Fuzzy Systems. DOI10.1109/FUZZ-IEEE.2017.8015732</span>
<span class="sd">&quot;&quot;&quot;</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.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">FLR</span><span class="p">,</span> <span class="n">fts</span><span class="p">,</span> <span class="n">flrg</span>
<span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">product</span>
<div class="viewcode-block" id="HighOrderFLRG"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.HighOrderFLRG">[docs]</a><span class="k">class</span> <span class="nc">HighOrderFLRG</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">FLRG</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Conventional High Order Fuzzy Logical Relationship Group&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">order</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">HighOrderFLRG</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">order</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">LHS</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">strlhs</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<div class="viewcode-block" id="HighOrderFLRG.append_rhs"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.HighOrderFLRG.append_rhs">[docs]</a> <span class="k">def</span> <span class="nf">append_rhs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</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">c</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">=</span> <span class="n">c</span></div>
<div class="viewcode-block" id="HighOrderFLRG.append_lhs"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.HighOrderFLRG.append_lhs">[docs]</a> <span class="k">def</span> <span class="nf">append_lhs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">c</span><span class="p">,(</span><span class="nb">tuple</span><span class="p">,</span><span class="nb">list</span><span class="p">)):</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">c</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">c</span><span class="p">)</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">tmp</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="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">):</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">tmp</span> <span class="o">+</span> <span class="s2">&quot;,&quot;</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">tmp</span> <span class="o">+</span> <span class="n">c</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="o">+</span> <span class="s2">&quot; -&gt; &quot;</span> <span class="o">+</span> <span class="n">tmp</span>
<span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div>
<div class="viewcode-block" id="WeightedHighOrderFLRG"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.WeightedHighOrderFLRG">[docs]</a><span class="k">class</span> <span class="nc">WeightedHighOrderFLRG</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">FLRG</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Weighted High Order Fuzzy Logical Relationship Group&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">order</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">WeightedHighOrderFLRG</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">order</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">LHS</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">strlhs</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">w</span> <span class="o">=</span> <span class="kc">None</span>
<div class="viewcode-block" id="WeightedHighOrderFLRG.append_rhs"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.WeightedHighOrderFLRG.append_rhs">[docs]</a> <span class="k">def</span> <span class="nf">append_rhs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fset</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">count</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;count&#39;</span><span class="p">,</span><span class="mf">1.0</span><span class="p">)</span>
<span class="k">if</span> <span class="n">fset</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">fset</span><span class="p">]</span> <span class="o">=</span> <span class="n">count</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">fset</span><span class="p">]</span> <span class="o">+=</span> <span class="n">count</span>
<span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">+=</span> <span class="n">count</span></div>
<div class="viewcode-block" id="WeightedHighOrderFLRG.append_lhs"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.WeightedHighOrderFLRG.append_lhs">[docs]</a> <span class="k">def</span> <span class="nf">append_lhs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">c</span><span class="p">)</span></div>
<div class="viewcode-block" id="WeightedHighOrderFLRG.weights"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.WeightedHighOrderFLRG.weights">[docs]</a> <span class="k">def</span> <span class="nf">weights</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">w</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="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()])</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span></div>
<div class="viewcode-block" id="WeightedHighOrderFLRG.get_midpoint"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.WeightedHighOrderFLRG.get_midpoint">[docs]</a> <span class="k">def</span> <span class="nf">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sets</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">midpoint</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">mp</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="n">sets</span><span class="p">[</span><span class="n">c</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">midpoint</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">weights</span><span class="p">())</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">midpoint</span></div>
<div class="viewcode-block" id="WeightedHighOrderFLRG.get_lower"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.WeightedHighOrderFLRG.get_lower">[docs]</a> <span class="k">def</span> <span class="nf">get_lower</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sets</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">lower</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">lw</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="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">lower</span> <span class="o">=</span> <span class="n">lw</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">weights</span><span class="p">())</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">lower</span></div>
<div class="viewcode-block" id="WeightedHighOrderFLRG.get_upper"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.WeightedHighOrderFLRG.get_upper">[docs]</a> <span class="k">def</span> <span class="nf">get_upper</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sets</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">upper</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">up</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="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">upper</span> <span class="o">=</span> <span class="n">up</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">weights</span><span class="p">())</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">upper</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">_str</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="n">_str</span> <span class="o">+=</span> <span class="s2">&quot;, &quot;</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">_str</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="s2">&quot;&quot;</span>
<span class="n">_str</span> <span class="o">+=</span> <span class="n">k</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="nb">round</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span> <span class="o">+</span> <span class="s2">&quot;)&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="o">+</span> <span class="s2">&quot; -&gt; &quot;</span> <span class="o">+</span> <span class="n">_str</span>
<span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div>
<div class="viewcode-block" id="HighOrderFTS"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.HighOrderFTS">[docs]</a><span class="k">class</span> <span class="nc">HighOrderFTS</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Conventional High Order Fuzzy Time Series&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">HighOrderFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;High Order FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;HOFTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;Severiano, Silva, Sadaei and Guimarães&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_order</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</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;order&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">min_order</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">configure_lags</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<div class="viewcode-block" id="HighOrderFTS.configure_lags"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.HighOrderFTS.configure_lags">[docs]</a> <span class="k">def</span> <span class="nf">configure_lags</span><span class="p">(</span><span class="bp">self</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="s2">&quot;order&quot;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</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;order&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">min_order</span><span class="p">)</span>
<span class="k">if</span> <span class="s2">&quot;lags&quot;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">lags</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;lags&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">lags</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lags</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span>
<span class="bp">self</span><span class="o">.</span><span class="n">lags</span> <span class="o">=</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span></div>
<div class="viewcode-block" id="HighOrderFTS.generate_lhs_flrg"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.HighOrderFTS.generate_lhs_flrg">[docs]</a> <span class="k">def</span> <span class="nf">generate_lhs_flrg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sample</span><span class="p">,</span> <span class="n">explain</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="n">nsample</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">fuzzyfy</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s2">&quot;sets&quot;</span><span class="p">,</span> <span class="n">alpha_cut</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">alpha_cut</span><span class="p">)</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">sample</span><span class="p">]</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">append_log</span><span class="p">(</span><span class="s2">&quot;Fuzzyfication&quot;</span><span class="p">,</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2"> -&gt; </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">nsample</span><span class="p">))</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_lhs_flrg_fuzzyfied</span><span class="p">(</span><span class="n">nsample</span><span class="p">,</span> <span class="n">explain</span><span class="p">)</span></div>
<div class="viewcode-block" id="HighOrderFTS.generate_lhs_flrg_fuzzyfied"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.HighOrderFTS.generate_lhs_flrg_fuzzyfied">[docs]</a> <span class="k">def</span> <span class="nf">generate_lhs_flrg_fuzzyfied</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sample</span><span class="p">,</span> <span class="n">explain</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="n">lags</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">flrgs</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">o</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lags</span><span class="p">):</span>
<span class="n">lhs</span> <span class="o">=</span> <span class="n">sample</span><span class="p">[</span><span class="n">o</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span>
<span class="n">lags</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">lhs</span><span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">append_log</span><span class="p">(</span><span class="s2">&quot;Ordering Lags&quot;</span><span class="p">,</span> <span class="s2">&quot;Lag </span><span class="si">{}</span><span class="s2"> Value </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">o</span><span class="p">,</span> <span class="n">lhs</span><span class="p">))</span>
<span class="c1"># Trace the possible paths</span>
<span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">lags</span><span class="p">):</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="n">HighOrderFLRG</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">)</span>
<span class="k">for</span> <span class="n">lhs</span> <span class="ow">in</span> <span class="n">path</span><span class="p">:</span>
<span class="n">flrg</span><span class="o">.</span><span class="n">append_lhs</span><span class="p">(</span><span class="n">lhs</span><span class="p">)</span>
<span class="n">flrgs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">flrg</span><span class="p">)</span>
<span class="k">return</span> <span class="n">flrgs</span></div>
<div class="viewcode-block" id="HighOrderFTS.generate_flrg"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.HighOrderFTS.generate_flrg">[docs]</a> <span class="k">def</span> <span class="nf">generate_flrg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="n">_tmp_steps</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">standard_horizon</span> <span class="o">-</span> <span class="mi">1</span>
<span class="n">l</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="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="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="n">l</span> <span class="o">-</span> <span class="n">_tmp_steps</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dump</span><span class="p">:</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;FLR: &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">k</span><span class="p">))</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">rhs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">fuzzyfy</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="o">+</span><span class="n">_tmp_steps</span><span class="p">],</span> <span class="n">mode</span><span class="o">=</span><span class="s2">&quot;sets&quot;</span><span class="p">,</span> <span class="n">alpha_cut</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">alpha_cut</span><span class="p">)</span>
<span class="n">flrgs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_lhs_flrg</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="k">for</span> <span class="n">flrg</span> <span class="ow">in</span> <span class="n">flrgs</span><span class="p">:</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span> <span class="o">=</span> <span class="n">flrg</span><span class="p">;</span>
<span class="k">for</span> <span class="n">st</span> <span class="ow">in</span> <span class="n">rhs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">st</span><span class="p">)</span></div>
<div class="viewcode-block" id="HighOrderFTS.generate_flrg_fuzzyfied"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.HighOrderFTS.generate_flrg_fuzzyfied">[docs]</a> <span class="k">def</span> <span class="nf">generate_flrg_fuzzyfied</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="n">_tmp_steps</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">standard_horizon</span> <span class="o">-</span> <span class="mi">1</span>
<span class="n">l</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="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="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dump</span><span class="p">:</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;FLR: &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">k</span><span class="p">))</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">rhs</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="o">+</span><span class="n">_tmp_steps</span><span class="p">]</span>
<span class="n">flrgs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_lhs_flrg_fuzzyfied</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="k">for</span> <span class="n">flrg</span> <span class="ow">in</span> <span class="n">flrgs</span><span class="p">:</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span> <span class="o">=</span> <span class="n">flrg</span>
<span class="k">for</span> <span class="n">st</span> <span class="ow">in</span> <span class="n">rhs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">st</span><span class="p">)</span></div>
<div class="viewcode-block" id="HighOrderFTS.train"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.HighOrderFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">configure_lags</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="ow">not</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;fuzzyfied&#39;</span><span class="p">,</span><span class="kc">False</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg_fuzzyfied</span><span class="p">(</span><span class="n">data</span><span class="p">)</span></div>
<div class="viewcode-block" id="HighOrderFTS.forecast"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.HighOrderFTS.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">explain</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;explain&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="n">fuzzyfied</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;fuzzyfied&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="n">mode</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;mode&#39;</span><span class="p">,</span> <span class="s1">&#39;mean&#39;</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</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">ndata</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">explain</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">+</span> <span class="mi">1</span>
<span class="k">if</span> <span class="n">l</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span>
<span class="k">return</span> <span class="n">ndata</span>
<span class="k">elif</span> <span class="n">l</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span>
<span class="n">l</span> <span class="o">+=</span> <span class="mi">1</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="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">ndata</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">fuzzyfied</span><span class="p">:</span>
<span class="n">flrgs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_lhs_flrg</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">explain</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">flrgs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_lhs_flrg_fuzzyfied</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">explain</span><span class="p">)</span>
<span class="n">midpoints</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">memberships</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">flrg</span> <span class="ow">in</span> <span class="n">flrgs</span><span class="p">:</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">mp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span><span class="o">.</span><span class="n">centroid</span>
<span class="n">mv</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">sample</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="ow">not</span> <span class="n">fuzzyfied</span> <span class="k">else</span> <span class="kc">None</span>
<span class="n">midpoints</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mp</span><span class="p">)</span>
<span class="n">memberships</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mv</span><span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">append_log</span><span class="p">(</span><span class="s2">&quot;Rule Matching&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2"> -&gt; </span><span class="si">{}</span><span class="s2"> (Naïve) Midpoint: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">),</span> <span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span>
<span class="n">mp</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span>
<span class="n">mp</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">mv</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_membership</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">fuzzyfied</span> <span class="k">else</span> <span class="kc">None</span>
<span class="n">midpoints</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mp</span><span class="p">)</span>
<span class="n">memberships</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mv</span><span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">append_log</span><span class="p">(</span><span class="s2">&quot;Rule Matching&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">, Midpoint: </span><span class="si">{}</span><span class="s2"> Membership: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">(),</span> <span class="n">mp</span><span class="p">,</span> <span class="n">mv</span><span class="p">))</span>
<span class="k">if</span> <span class="n">mode</span> <span class="o">==</span> <span class="s2">&quot;mean&quot;</span> <span class="ow">or</span> <span class="n">fuzzyfied</span><span class="p">:</span>
<span class="n">final</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmean</span><span class="p">(</span><span class="n">midpoints</span><span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">append_log</span><span class="p">(</span><span class="s2">&quot;Deffuzyfication&quot;</span><span class="p">,</span> <span class="s2">&quot;By Mean: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">final</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">final</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">midpoints</span><span class="p">,</span> <span class="n">memberships</span><span class="p">)</span><span class="o">/</span><span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">memberships</span><span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">append_log</span><span class="p">(</span><span class="s2">&quot;Deffuzyfication&quot;</span><span class="p">,</span> <span class="s2">&quot;By Memberships: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">final</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">final</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div></div>
<div class="viewcode-block" id="WeightedHighOrderFTS"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.WeightedHighOrderFTS">[docs]</a><span class="k">class</span> <span class="nc">WeightedHighOrderFTS</span><span class="p">(</span><span class="n">HighOrderFTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Weighted High Order Fuzzy Time Series&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">WeightedHighOrderFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Weighted High Order FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;WHOFTS&quot;</span>
<div class="viewcode-block" id="WeightedHighOrderFTS.generate_lhs_flrg_fuzzyfied"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hofts.WeightedHighOrderFTS.generate_lhs_flrg_fuzzyfied">[docs]</a> <span class="k">def</span> <span class="nf">generate_lhs_flrg_fuzzyfied</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sample</span><span class="p">,</span> <span class="n">explain</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="n">lags</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">flrgs</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">o</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lags</span><span class="p">):</span>
<span class="n">lags</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sample</span><span class="p">[</span><span class="n">o</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\t</span><span class="s2"> (Lag </span><span class="si">{}</span><span class="s2">) </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">o</span><span class="p">,</span> <span class="n">sample</span><span class="p">[</span><span class="n">o</span><span class="o">-</span><span class="mi">1</span><span class="p">]))</span>
<span class="c1"># Trace the possible paths</span>
<span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">lags</span><span class="p">):</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="n">WeightedHighOrderFLRG</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">)</span>
<span class="k">for</span> <span class="n">lhs</span> <span class="ow">in</span> <span class="n">path</span><span class="p">:</span>
<span class="n">flrg</span><span class="o">.</span><span class="n">append_lhs</span><span class="p">(</span><span class="n">lhs</span><span class="p">)</span>
<span class="n">flrgs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">flrg</span><span class="p">)</span>
<span class="k">return</span> <span class="n">flrgs</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.hofts</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,164 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.hwang &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.hwang</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.hwang</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">High Order Fuzzy Time Series by Hwang, Chen and Lee (1998)</span>
<span class="sd">Jeng-Ren Hwang, Shyi-Ming Chen, and Chia-Hoang Lee, “Handling forecasting problems using fuzzy time series,” </span>
<span class="sd">Fuzzy Sets Syst., no. 100, pp. 217228, 1998.</span>
<span class="sd">&quot;&quot;&quot;</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.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">FLR</span><span class="p">,</span> <span class="n">Transformations</span><span class="p">,</span> <span class="n">fts</span>
<div class="viewcode-block" id="HighOrderFTS"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hwang.HighOrderFTS">[docs]</a><span class="k">class</span> <span class="nc">HighOrderFTS</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">HighOrderFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_order</span> <span class="o">=</span> <span class="mi">2</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Hwang High Order FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;Hwang&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;Hwang&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">configure_lags</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<div class="viewcode-block" id="HighOrderFTS.configure_lags"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hwang.HighOrderFTS.configure_lags">[docs]</a> <span class="k">def</span> <span class="nf">configure_lags</span><span class="p">(</span><span class="bp">self</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="s2">&quot;order&quot;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</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;order&quot;</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span></div>
<div class="viewcode-block" id="HighOrderFTS.forecast"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hwang.HighOrderFTS.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">cn</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="mf">0.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="n">l</span><span class="p">)])</span>
<span class="n">ow</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="mf">0.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="n">l</span><span class="p">)]</span> <span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)])</span>
<span class="n">rn</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="mf">0.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="n">l</span><span class="p">)]</span> <span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)])</span>
<span class="n">ft</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="mf">0.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="n">l</span><span class="p">)])</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">t</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">ndata</span><span class="p">)):</span>
<span class="k">for</span> <span class="n">ix</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">l</span><span class="p">):</span>
<span class="n">s</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span>
<span class="n">cn</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">grant_bounds</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">t</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">))</span>
<span class="k">for</span> <span class="n">w</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="o">-</span><span class="mi">1</span><span class="p">):</span>
<span class="n">ow</span><span class="p">[</span><span class="n">w</span><span class="p">,</span> <span class="n">ix</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">FuzzySet</span><span class="o">.</span><span class="n">grant_bounds</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">t</span> <span class="o">-</span> <span class="n">w</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">))</span>
<span class="n">rn</span><span class="p">[</span><span class="n">w</span><span class="p">,</span> <span class="n">ix</span><span class="p">]</span> <span class="o">=</span> <span class="n">ow</span><span class="p">[</span><span class="n">w</span><span class="p">,</span> <span class="n">ix</span><span class="p">]</span> <span class="o">*</span> <span class="n">cn</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span>
<span class="n">ft</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">ft</span><span class="p">[</span><span class="n">ix</span><span class="p">],</span> <span class="n">rn</span><span class="p">[</span><span class="n">w</span><span class="p">,</span> <span class="n">ix</span><span class="p">])</span>
<span class="n">mft</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">ft</span><span class="p">)</span>
<span class="n">out</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="n">count</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="k">for</span> <span class="n">ix</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">l</span><span class="p">):</span>
<span class="n">s</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span>
<span class="k">if</span> <span class="n">ft</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span> <span class="o">==</span> <span class="n">mft</span><span class="p">:</span>
<span class="n">out</span> <span class="o">=</span> <span class="n">out</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span>
<span class="n">count</span> <span class="o">+=</span> <span class="mf">1.0</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">out</span> <span class="o">/</span> <span class="n">count</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="HighOrderFTS.train"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.hwang.HighOrderFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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="bp">self</span><span class="o">.</span><span class="n">sets</span> <span class="o">==</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">sets</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span>
<span class="bp">self</span><span class="o">.</span><span class="n">configure_lags</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.hwang</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,285 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.ifts &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.ifts</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.ifts</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;</span>
<span class="sd">High Order Interval Fuzzy Time Series</span>
<span class="sd">SILVA, Petrônio CL; SADAEI, Hossein Javedani; GUIMARÃES, Frederico Gadelha. Interval Forecasting with Fuzzy Time Series.</span>
<span class="sd">In: Computational Intelligence (SSCI), 2016 IEEE Symposium Series on. IEEE, 2016. p. 1-8.</span>
<span class="sd">&quot;&quot;&quot;</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.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">FLR</span><span class="p">,</span> <span class="n">fts</span><span class="p">,</span> <span class="n">tree</span>
<span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="kn">import</span> <span class="n">hofts</span>
<div class="viewcode-block" id="IntervalFTS"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ifts.IntervalFTS">[docs]</a><span class="k">class</span> <span class="nc">IntervalFTS</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="sd">&quot;&quot;&quot;</span>
<span class="sd"> High Order Interval Fuzzy Time Series</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">IntervalFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;IFTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Interval FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;Silva, P.; Guimarães, F.; Sadaei, H. (2016)&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_point_forecasting</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_interval_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_order</span> <span class="o">=</span> <span class="mi">1</span>
<div class="viewcode-block" id="IntervalFTS.get_upper"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ifts.IntervalFTS.get_upper">[docs]</a> <span class="k">def</span> <span class="nf">get_upper</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrg</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">tmp</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span><span class="o">.</span><span class="n">upper</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="IntervalFTS.get_lower"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ifts.IntervalFTS.get_lower">[docs]</a> <span class="k">def</span> <span class="nf">get_lower</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrg</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">tmp</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span><span class="o">.</span><span class="n">lower</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="IntervalFTS.get_sequence_membership"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ifts.IntervalFTS.get_sequence_membership">[docs]</a> <span class="k">def</span> <span class="nf">get_sequence_membership</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">fuzzySets</span><span class="p">):</span>
<span class="n">mb</span> <span class="o">=</span> <span class="p">[</span><span class="n">fuzzySets</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">k</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="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">))]</span>
<span class="k">return</span> <span class="n">mb</span></div>
<div class="viewcode-block" id="IntervalFTS.forecast_interval"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ifts.IntervalFTS.forecast_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</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">ndata</span><span class="p">)</span>
<span class="k">if</span> <span class="n">l</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:</span>
<span class="k">return</span> <span class="n">ndata</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="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="n">l</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">ndata</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">flrgs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_lhs_flrg</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="n">up</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">lo</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">affected_flrgs_memberships</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">flrg</span> <span class="ow">in</span> <span class="n">flrgs</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">mv</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_membership</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">up</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mv</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="n">flrg</span><span class="p">))</span>
<span class="n">lo</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mv</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="n">flrg</span><span class="p">))</span>
<span class="n">affected_flrgs_memberships</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mv</span><span class="p">)</span>
<span class="c1"># gerar o intervalo</span>
<span class="n">norm</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">affected_flrgs_memberships</span><span class="p">)</span>
<span class="n">lo_</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">lo</span><span class="p">)</span> <span class="o">/</span> <span class="n">norm</span>
<span class="n">up_</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">up</span><span class="p">)</span> <span class="o">/</span> <span class="n">norm</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">lo_</span><span class="p">,</span> <span class="n">up_</span><span class="p">])</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="IntervalFTS.forecast_ahead_interval"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ifts.IntervalFTS.forecast_ahead_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">start</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;start_at&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[[</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="n">start</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">max_lag</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="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">+</span> <span class="n">steps</span><span class="p">):</span>
<span class="n">interval_lower</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">clip_uod</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">forecast_interval</span><span class="p">([</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">ret</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span> <span class="n">k</span><span class="p">]])[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">interval_upper</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">clip_uod</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">forecast_interval</span><span class="p">([</span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">ret</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span> <span class="n">k</span><span class="p">]])[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">interval</span> <span class="o">=</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">nanmin</span><span class="p">(</span><span class="n">interval_lower</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmax</span><span class="p">(</span><span class="n">interval_upper</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">interval</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span><span class="p">[</span><span class="o">-</span><span class="n">steps</span><span class="p">:]</span></div></div>
<div class="viewcode-block" id="WeightedIntervalFTS"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ifts.WeightedIntervalFTS">[docs]</a><span class="k">class</span> <span class="nc">WeightedIntervalFTS</span><span class="p">(</span><span class="n">hofts</span><span class="o">.</span><span class="n">WeightedHighOrderFTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Weighted High Order Interval Fuzzy Time Series</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">WeightedIntervalFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;WIFTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Weighted Interval FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;Silva, P.; Guimarães, F.; Sadaei, H. (2016)&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_point_forecasting</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_interval_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_order</span> <span class="o">=</span> <span class="mi">1</span>
<div class="viewcode-block" id="WeightedIntervalFTS.get_upper"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ifts.WeightedIntervalFTS.get_upper">[docs]</a> <span class="k">def</span> <span class="nf">get_upper</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrg</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">tmp</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span><span class="o">.</span><span class="n">upper</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="WeightedIntervalFTS.get_lower"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ifts.WeightedIntervalFTS.get_lower">[docs]</a> <span class="k">def</span> <span class="nf">get_lower</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrg</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">tmp</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span><span class="o">.</span><span class="n">lower</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="WeightedIntervalFTS.get_sequence_membership"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ifts.WeightedIntervalFTS.get_sequence_membership">[docs]</a> <span class="k">def</span> <span class="nf">get_sequence_membership</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">fuzzySets</span><span class="p">):</span>
<span class="n">mb</span> <span class="o">=</span> <span class="p">[</span><span class="n">fuzzySets</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">k</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="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">))]</span>
<span class="k">return</span> <span class="n">mb</span></div>
<div class="viewcode-block" id="WeightedIntervalFTS.forecast_interval"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ifts.WeightedIntervalFTS.forecast_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</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">ndata</span><span class="p">)</span>
<span class="k">if</span> <span class="n">l</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:</span>
<span class="k">return</span> <span class="n">ndata</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="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="n">l</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">ndata</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">flrgs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_lhs_flrg</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="n">up</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">lo</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">affected_flrgs_memberships</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">flrg</span> <span class="ow">in</span> <span class="n">flrgs</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">mv</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_membership</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">up</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mv</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="n">flrg</span><span class="p">))</span>
<span class="n">lo</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mv</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="n">flrg</span><span class="p">))</span>
<span class="n">affected_flrgs_memberships</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mv</span><span class="p">)</span>
<span class="c1"># gerar o intervalo</span>
<span class="n">norm</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">affected_flrgs_memberships</span><span class="p">)</span>
<span class="n">lo_</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">lo</span><span class="p">)</span> <span class="o">/</span> <span class="n">norm</span>
<span class="n">up_</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">up</span><span class="p">)</span> <span class="o">/</span> <span class="n">norm</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">lo_</span><span class="p">,</span> <span class="n">up_</span><span class="p">])</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="WeightedIntervalFTS.forecast_ahead_interval"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ifts.WeightedIntervalFTS.forecast_ahead_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">start</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;start_at&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[[</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="n">start</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</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="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">+</span> <span class="n">steps</span><span class="p">):</span>
<span class="n">interval_lower</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">clip_uod</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">forecast_interval</span><span class="p">([</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">ret</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span> <span class="n">k</span><span class="p">]])[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">interval_upper</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">clip_uod</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">forecast_interval</span><span class="p">([</span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">ret</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span> <span class="n">k</span><span class="p">]])[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">interval</span> <span class="o">=</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">nanmin</span><span class="p">(</span><span class="n">interval_lower</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmax</span><span class="p">(</span><span class="n">interval_upper</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">interval</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span><span class="p">[</span><span class="o">-</span><span class="n">steps</span><span class="p">:]</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.ifts</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,224 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.incremental.IncrementalEnsemble &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
<script src="../../../../_static/jquery.js"></script>
<script src="../../../../_static/underscore.js"></script>
<script src="../../../../_static/doctools.js"></script>
<script src="../../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.incremental.IncrementalEnsemble</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.incremental.IncrementalEnsemble</h1><div class="highlight"><pre>
<span></span><span class="sd">&#39;&#39;&#39;</span>
<span class="sd">Time Variant/Incremental Ensemble of FTS methods</span>
<span class="sd">&#39;&#39;&#39;</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">FLR</span><span class="p">,</span> <span class="n">fts</span><span class="p">,</span> <span class="n">flrg</span>
<span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="kn">import</span> <span class="n">Grid</span>
<span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="kn">import</span> <span class="n">hofts</span>
<span class="kn">from</span> <span class="nn">pyFTS.models.ensemble</span> <span class="kn">import</span> <span class="n">ensemble</span>
<div class="viewcode-block" id="IncrementalEnsembleFTS"><a class="viewcode-back" href="../../../../pyFTS.models.incremental.html#pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS">[docs]</a><span class="k">class</span> <span class="nc">IncrementalEnsembleFTS</span><span class="p">(</span><span class="n">ensemble</span><span class="o">.</span><span class="n">EnsembleFTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Time Variant/Incremental Ensemble of FTS methods</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">IncrementalEnsembleFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;IncrementalEnsembleFTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Incremental Ensemble FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</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;order&#39;</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner_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;partitioner_method&#39;</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="sd">&quot;&quot;&quot;The partitioner method to be called when a new model is build&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner_params</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;partitioner_params&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s1">&#39;npart&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">})</span>
<span class="sd">&quot;&quot;&quot;The partitioner method parameters&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fts_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;fts_method&#39;</span><span class="p">,</span> <span class="n">hofts</span><span class="o">.</span><span class="n">WeightedHighOrderFTS</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;The FTS method to be called when a new model is build&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fts_params</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;fts_params&#39;</span><span class="p">,</span> <span class="p">{})</span>
<span class="sd">&quot;&quot;&quot;The FTS method specific parameters&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">window_length</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;window_length&#39;</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;The memory window length&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">batch_size</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;batch_size&#39;</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;The batch interval between each retraining&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">num_models</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;num_models&#39;</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;The number of models to hold in the ensemble&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">point_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;point_method&#39;</span><span class="p">,</span> <span class="s1">&#39;exponential&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">uod_clip</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">window_length</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span>
<div class="viewcode-block" id="IncrementalEnsembleFTS.offset"><a class="viewcode-back" href="../../../../pyFTS.models.incremental.html#pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.offset">[docs]</a> <span class="k">def</span> <span class="nf">offset</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span></div>
<div class="viewcode-block" id="IncrementalEnsembleFTS.train"><a class="viewcode-back" href="../../../../pyFTS.models.incremental.html#pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">partitioner</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner_method</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="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner_params</span><span class="p">)</span>
<span class="n">model</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fts_method</span><span class="p">(</span><span class="n">partitioner</span><span class="o">=</span><span class="n">partitioner</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">fts_params</span><span class="p">)</span>
<span class="k">if</span> <span class="n">model</span><span class="o">.</span><span class="n">is_high_order</span><span class="p">:</span>
<span class="n">model</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fts_method</span><span class="p">(</span><span class="n">partitioner</span><span class="o">=</span><span class="n">partitioner</span><span class="p">,</span> <span class="n">order</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">fts_params</span><span class="p">)</span>
<span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">append_model</span><span class="p">(</span><span class="n">model</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">models</span><span class="p">)</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">num_models</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">models</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span></div>
<div class="viewcode-block" id="IncrementalEnsembleFTS.forecast"><a class="viewcode-back" href="../../../../pyFTS.models.incremental.html#pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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">data</span><span class="p">)</span>
<span class="n">no_update</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;no_update&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="k">if</span> <span class="n">no_update</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">l</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_models_forecasts</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="n">point</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_point</span><span class="p">(</span><span class="n">tmp</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">point</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span>
<span class="n">data_window</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">ret</span> <span class="o">=</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="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>
<span class="n">k2</span> <span class="o">=</span> <span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span>
<span class="n">data_window</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">k2</span><span class="p">])</span>
<span class="k">if</span> <span class="n">k2</span> <span class="o">&gt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">window_length</span><span class="p">:</span>
<span class="n">data_window</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="k">if</span> <span class="n">k</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">batch_size</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">k2</span> <span class="o">&gt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">window_length</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">train</span><span class="p">(</span><span class="n">data_window</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="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">models</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k2</span><span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_models_forecasts</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="n">point</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_point</span><span class="p">(</span><span class="n">tmp</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">point</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="IncrementalEnsembleFTS.forecast_ahead"><a class="viewcode-back" href="../../../../pyFTS.models.incremental.html#pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.forecast_ahead">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</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="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:</span>
<span class="k">return</span> <span class="n">data</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</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">data</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
<span class="n">start</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;start_at&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">data</span><span class="p">[:</span><span class="n">start</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">order</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="n">start</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">steps</span><span class="o">+</span><span class="n">start</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">ret</span><span class="p">[</span><span class="n">k</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:</span><span class="n">k</span><span class="p">],</span> <span class="n">no_update</span><span class="o">=</span><span class="kc">True</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="nb">isinstance</span><span class="p">(</span><span class="n">tmp</span><span class="p">,(</span><span class="nb">list</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">tmp</span> <span class="o">=</span> <span class="n">tmp</span><span class="p">[</span><span class="o">-</span><span class="mi">1</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">tmp</span><span class="p">)</span>
<span class="n">data</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span><span class="p">[</span><span class="o">-</span><span class="n">steps</span><span class="p">:]</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.incremental.IncrementalEnsemble</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,215 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.incremental.TimeVariant &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
<script src="../../../../_static/jquery.js"></script>
<script src="../../../../_static/underscore.js"></script>
<script src="../../../../_static/doctools.js"></script>
<script src="../../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.incremental.TimeVariant</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.incremental.TimeVariant</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Meta model that wraps another FTS method and continously retrain it using a data window with</span>
<span class="sd">the most recent data</span>
<span class="sd">&quot;&quot;&quot;</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.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">FLR</span><span class="p">,</span> <span class="n">fts</span><span class="p">,</span> <span class="n">flrg</span>
<span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="kn">import</span> <span class="n">Grid</span>
<div class="viewcode-block" id="Retrainer"><a class="viewcode-back" href="../../../../pyFTS.models.incremental.html#pyFTS.models.incremental.TimeVariant.Retrainer">[docs]</a><span class="k">class</span> <span class="nc">Retrainer</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Meta model for incremental/online learning that retrain its internal model after</span>
<span class="sd"> data windows controlled by the parameter &#39;batch_size&#39;, using as the training data a</span>
<span class="sd"> window of recent lags, whose size is controlled by the parameter &#39;window_length&#39;.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">Retrainer</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner_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;partitioner_method&#39;</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="sd">&quot;&quot;&quot;The partitioner method to be called when a new model is build&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner_params</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;partitioner_params&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s1">&#39;npart&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">})</span>
<span class="sd">&quot;&quot;&quot;The partitioner method parameters&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span> <span class="o">=</span> <span class="kc">None</span>
<span class="sd">&quot;&quot;&quot;The most recent trained partitioner&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fts_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;fts_method&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;The FTS method to be called when a new model is build&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fts_params</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;fts_params&#39;</span><span class="p">,</span> <span class="p">{})</span>
<span class="sd">&quot;&quot;&quot;The FTS method specific parameters&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="kc">None</span>
<span class="sd">&quot;&quot;&quot;The most recent trained model&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">window_length</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;window_length&#39;</span><span class="p">,</span><span class="mi">100</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;The memory window length&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">auto_update</span> <span class="o">=</span> <span class="kc">False</span>
<span class="sd">&quot;&quot;&quot;If true the model is updated at each time and not recreated&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">batch_size</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;batch_size&#39;</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;The batch interval between each retraining&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_time_variant</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">uod_clip</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">window_length</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_wrapper</span> <span class="o">=</span> <span class="kc">True</span>
<div class="viewcode-block" id="Retrainer.train"><a class="viewcode-back" href="../../../../pyFTS.models.incremental.html#pyFTS.models.incremental.TimeVariant.Retrainer.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner_method</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="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner_params</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fts_method</span><span class="p">(</span><span class="n">partitioner</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">fts_params</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">is_high_order</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">order</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fts_method</span><span class="p">(</span><span class="n">partitioner</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="p">,</span>
<span class="n">order</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">fts_params</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;TimeVariant - &quot;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">shortname</span></div>
<div class="viewcode-block" id="Retrainer.forecast"><a class="viewcode-back" href="../../../../pyFTS.models.incremental.html#pyFTS.models.incremental.TimeVariant.Retrainer.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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">data</span><span class="p">)</span>
<span class="n">no_update</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;no_update&#39;</span><span class="p">,</span><span class="kc">False</span><span class="p">)</span>
<span class="k">if</span> <span class="n">no_update</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">horizon</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">window_length</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span>
<span class="n">ret</span> <span class="o">=</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="n">horizon</span><span class="p">,</span> <span class="n">l</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
<span class="n">_train</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="n">horizon</span><span class="p">:</span> <span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">]</span>
<span class="n">_test</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="k">if</span> <span class="n">k</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">batch_size</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">auto_update</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model</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="k">else</span><span class="p">:</span>
<span class="bp">self</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="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">ret</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">predict</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="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="Retrainer.forecast_ahead"><a class="viewcode-back" href="../../../../pyFTS.models.incremental.html#pyFTS.models.incremental.TimeVariant.Retrainer.forecast_ahead">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</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="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:</span>
<span class="k">return</span> <span class="n">data</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</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">data</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
<span class="n">start</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;start_at&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">data</span><span class="p">[:</span><span class="n">start</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">order</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="n">start</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="n">steps</span><span class="o">+</span><span class="n">start</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">ret</span><span class="p">[</span><span class="n">k</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:</span><span class="n">k</span><span class="p">],</span> <span class="n">no_update</span><span class="o">=</span><span class="kc">True</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="nb">isinstance</span><span class="p">(</span><span class="n">tmp</span><span class="p">,(</span><span class="nb">list</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">tmp</span> <span class="o">=</span> <span class="n">tmp</span><span class="p">[</span><span class="o">-</span><span class="mi">1</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">tmp</span><span class="p">)</span>
<span class="n">data</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span><span class="p">[</span><span class="o">-</span><span class="n">steps</span><span class="p">:]</span></div>
<div class="viewcode-block" id="Retrainer.offset"><a class="viewcode-back" href="../../../../pyFTS.models.incremental.html#pyFTS.models.incremental.TimeVariant.Retrainer.offset">[docs]</a> <span class="k">def</span> <span class="nf">offset</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;String representation of the model&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">)</span>
<span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> The length (number of rules) of the model</span>
<span class="sd"> :return: number of rules</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">)</span></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.incremental.TimeVariant</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,211 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.ismailefendi &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.ismailefendi</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.ismailefendi</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">First Order Improved Weighted Fuzzy Time Series by Efendi, Ismail and Deris (2013)</span>
<span class="sd">R. Efendi, Z. Ismail, and M. M. Deris, “Improved weight Fuzzy Time Series as used in the exchange rates forecasting of </span>
<span class="sd">US Dollar to Ringgit Malaysia,” Int. J. Comput. Intell. Appl., vol. 12, no. 1, p. 1350005, 2013.</span>
<span class="sd">&quot;&quot;&quot;</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.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">FLR</span><span class="p">,</span> <span class="n">fts</span><span class="p">,</span> <span class="n">flrg</span>
<div class="viewcode-block" id="ImprovedWeightedFLRG"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ismailefendi.ImprovedWeightedFLRG">[docs]</a><span class="k">class</span> <span class="nc">ImprovedWeightedFLRG</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">FLRG</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;First Order Improved Weighted Fuzzy Logical Relationship Group&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">LHS</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">ImprovedWeightedFLRG</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">LHS</span> <span class="o">=</span> <span class="n">LHS</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">rhs_counts</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">w</span> <span class="o">=</span> <span class="kc">None</span>
<div class="viewcode-block" id="ImprovedWeightedFLRG.append_rhs"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ismailefendi.ImprovedWeightedFLRG.append_rhs">[docs]</a> <span class="k">def</span> <span class="nf">append_rhs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">count</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;count&#39;</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
<span class="k">if</span> <span class="n">c</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">=</span> <span class="n">c</span>
<span class="bp">self</span><span class="o">.</span><span class="n">rhs_counts</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">=</span> <span class="n">count</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">rhs_counts</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">+=</span> <span class="n">count</span>
<span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">+=</span> <span class="n">count</span></div>
<div class="viewcode-block" id="ImprovedWeightedFLRG.weights"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ismailefendi.ImprovedWeightedFLRG.weights">[docs]</a> <span class="k">def</span> <span class="nf">weights</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">w</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="bp">self</span><span class="o">.</span><span class="n">rhs_counts</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()])</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">LHS</span> <span class="o">+</span> <span class="s2">&quot; -&gt; &quot;</span>
<span class="n">tmp2</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="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()):</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">tmp2</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">tmp2</span> <span class="o">=</span> <span class="n">tmp2</span> <span class="o">+</span> <span class="s2">&quot;,&quot;</span>
<span class="n">tmp2</span> <span class="o">=</span> <span class="n">tmp2</span> <span class="o">+</span> <span class="n">c</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="nb">round</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">rhs_counts</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span> <span class="o">+</span> <span class="s2">&quot;)&quot;</span>
<span class="k">return</span> <span class="n">tmp</span> <span class="o">+</span> <span class="n">tmp2</span>
<span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div>
<div class="viewcode-block" id="ImprovedWeightedFTS"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ismailefendi.ImprovedWeightedFTS">[docs]</a><span class="k">class</span> <span class="nc">ImprovedWeightedFTS</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;First Order Improved Weighted Fuzzy Time Series&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">ImprovedWeightedFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</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">name</span><span class="o">=</span><span class="s2">&quot;IWFTS&quot;</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Improved Weighted FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;Ismail &amp; Efendi&quot;</span>
<div class="viewcode-block" id="ImprovedWeightedFTS.generate_flrg"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ismailefendi.ImprovedWeightedFTS.generate_flrg">[docs]</a> <span class="k">def</span> <span class="nf">generate_flrg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrs</span><span class="p">):</span>
<span class="k">for</span> <span class="n">flr</span> <span class="ow">in</span> <span class="n">flrs</span><span class="p">:</span>
<span class="k">if</span> <span class="n">flr</span><span class="o">.</span><span class="n">LHS</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span> <span class="o">=</span> <span class="n">ImprovedWeightedFLRG</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div>
<div class="viewcode-block" id="ImprovedWeightedFTS.train"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ismailefendi.ImprovedWeightedFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">tmpdata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">fuzzyfy</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;maximum&#39;</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;sets&#39;</span><span class="p">)</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_recurrent_flrs</span><span class="p">(</span><span class="n">tmpdata</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg</span><span class="p">(</span><span class="n">flrs</span><span class="p">)</span></div>
<div class="viewcode-block" id="ImprovedWeightedFTS.forecast"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ismailefendi.ImprovedWeightedFTS.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">explain</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;explain&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">ordered_sets</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ordered_sets</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">set_ordered</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">ndata</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="n">ndata</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">ndata</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">explain</span> <span class="k">else</span> <span class="mi">1</span>
<span class="n">ret</span> <span class="o">=</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">actual</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">get_maximum_membership_fuzzyset</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">ordered_sets</span><span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Fuzzyfication:</span><span class="se">\n\n</span><span class="s2"> </span><span class="si">{}</span><span class="s2"> -&gt; </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">actual</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
<span class="k">if</span> <span class="n">actual</span><span class="o">.</span><span class="n">name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</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">actual</span><span class="o">.</span><span class="n">centroid</span><span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Rules:</span><span class="se">\n\n</span><span class="s2"> </span><span class="si">{}</span><span class="s2"> -&gt; </span><span class="si">{}</span><span class="s2"> (Naïve)</span><span class="se">\t</span><span class="s2"> Midpoint: </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">actual</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">actual</span><span class="o">.</span><span class="n">name</span><span class="p">,</span><span class="n">actual</span><span class="o">.</span><span class="n">centroid</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">actual</span><span class="o">.</span><span class="n">name</span><span class="p">]</span>
<span class="n">mp</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_midpoints</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">final</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">weights</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">final</span><span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Rules:</span><span class="se">\n\n</span><span class="s2"> </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n\n</span><span class="s2"> &quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">flrg</span><span class="p">)))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Midpoints: </span><span class="se">\n\n</span><span class="s2"> </span><span class="si">{}</span><span class="se">\n\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">mp</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Deffuzyfied value: </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">final</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ret</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.ismailefendi</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,316 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.multivariate.cmvfts &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
<script src="../../../../_static/jquery.js"></script>
<script src="../../../../_static/underscore.js"></script>
<script src="../../../../_static/doctools.js"></script>
<script src="../../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.multivariate.cmvfts</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.multivariate.cmvfts</h1><div class="highlight"><pre>
<span></span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">FLR</span><span class="p">,</span> <span class="n">fts</span><span class="p">,</span> <span class="n">flrg</span>
<span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="kn">import</span> <span class="n">hofts</span>
<span class="kn">from</span> <span class="nn">pyFTS.models.multivariate</span> <span class="kn">import</span> <span class="n">mvfts</span><span class="p">,</span> <span class="n">grid</span><span class="p">,</span> <span class="n">common</span>
<span class="kn">from</span> <span class="nn">types</span> <span class="kn">import</span> <span class="n">LambdaType</span>
<div class="viewcode-block" id="ClusteredMVFTS"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS">[docs]</a><span class="k">class</span> <span class="nc">ClusteredMVFTS</span><span class="p">(</span><span class="n">mvfts</span><span class="o">.</span><span class="n">MVFTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Meta model for high order, clustered multivariate FTS</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">ClusteredMVFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fts_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;fts_method&#39;</span><span class="p">,</span> <span class="n">hofts</span><span class="o">.</span><span class="n">WeightedHighOrderFTS</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;The FTS method to be called when a new model is build&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fts_params</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;fts_params&#39;</span><span class="p">,</span> <span class="p">{})</span>
<span class="sd">&quot;&quot;&quot;The FTS method specific parameters&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="kc">None</span>
<span class="sd">&quot;&quot;&quot;The most recent trained model&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">knn</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;knn&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_clustered</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</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;order&quot;</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">lags</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;lags&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">alpha_cut</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;alpha_cut&#39;</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;ClusteredMVFTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Clustered Multivariate FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">pre_fuzzyfy</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;pre_fuzzyfy&#39;</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fuzzyfy_mode</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;fuzzyfy_mode&#39;</span><span class="p">,</span> <span class="s1">&#39;sets&#39;</span><span class="p">)</span>
<div class="viewcode-block" id="ClusteredMVFTS.fuzzyfy"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.fuzzyfy">[docs]</a> <span class="k">def</span> <span class="nf">fuzzyfy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">data</span><span class="p">):</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">index</span><span class="p">,</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">iterrows</span><span class="p">()</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">)</span> <span class="k">else</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">data</span><span class="p">):</span>
<span class="n">data_point</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">format_data</span><span class="p">(</span><span class="n">row</span><span class="p">)</span>
<span class="n">ndata</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">fuzzyfy</span><span class="p">(</span><span class="n">data_point</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">fuzzyfy_mode</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ndata</span></div>
<div class="viewcode-block" id="ClusteredMVFTS.train"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fts_params</span><span class="p">[</span><span class="s1">&#39;order&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fts_method</span><span class="p">(</span><span class="n">partitioner</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">fts_params</span><span class="p">)</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">apply_transformations</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_data</span><span class="p">(</span><span class="n">ndata</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">train</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">fuzzyfied</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">pre_fuzzyfy</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">prune</span><span class="p">()</span></div>
<div class="viewcode-block" id="ClusteredMVFTS.check_data"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.check_data">[docs]</a> <span class="k">def</span> <span class="nf">check_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">pre_fuzzyfy</span><span class="p">:</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fuzzyfy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">format_data</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">to_dict</span><span class="p">(</span><span class="s1">&#39;records&#39;</span><span class="p">)]</span>
<span class="k">return</span> <span class="n">ndata</span></div>
<div class="viewcode-block" id="ClusteredMVFTS.forecast"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">ndata1</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">apply_transformations</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_data</span><span class="p">(</span><span class="n">ndata1</span><span class="p">)</span>
<span class="n">pre_fuzz</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;pre_fuzzyfy&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">pre_fuzzyfy</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">fuzzyfied</span><span class="o">=</span><span class="n">pre_fuzz</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">apply_inverse_transformations</span><span class="p">(</span><span class="n">ret</span><span class="p">,</span>
<span class="n">params</span><span class="o">=</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="ClusteredMVFTS.forecast_interval"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.forecast_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">has_interval_forecasting</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;The internal method does not support interval forecasting!&quot;</span><span class="p">)</span>
<span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_data</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">pre_fuzz</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;pre_fuzzyfy&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">pre_fuzzyfy</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</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">fuzzyfied</span><span class="o">=</span><span class="n">pre_fuzz</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div>
<div class="viewcode-block" id="ClusteredMVFTS.forecast_distribution"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.forecast_distribution">[docs]</a> <span class="k">def</span> <span class="nf">forecast_distribution</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">has_probability_forecasting</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;The internal method does not support probabilistic forecasting!&quot;</span><span class="p">)</span>
<span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_data</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">pre_fuzz</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;pre_fuzzyfy&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">pre_fuzzyfy</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">forecast_distribution</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">fuzzyfied</span><span class="o">=</span><span class="n">pre_fuzz</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div>
<div class="viewcode-block" id="ClusteredMVFTS.forecast_ahead_distribution"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.forecast_ahead_distribution">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_distribution</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">generators</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;generators&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="n">generators</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s1">&#39;You must provide parameter </span><span class="se">\&#39;</span><span class="s1">generators</span><span class="se">\&#39;</span><span class="s1">! generators is a dict where the keys&#39;</span> <span class="o">+</span>
<span class="s1">&#39; are the dataframe column names (except the target_variable) and the values are &#39;</span> <span class="o">+</span>
<span class="s1">&#39;lambda functions that accept one value (the actual value of the variable) &#39;</span>
<span class="s1">&#39; and return the next value or trained FTS models that accept the actual values and &#39;</span>
<span class="s1">&#39;forecast new ones.&#39;</span><span class="p">)</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">apply_transformations</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">start</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;start_at&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">ndata</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="n">start</span><span class="p">:</span> <span class="n">start</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</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">steps</span><span class="p">):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_distribution</span><span class="p">(</span><span class="n">sample</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)[</span><span class="mi">0</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">tmp</span><span class="p">)</span>
<span class="n">new_data_point</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">data_label</span> <span class="ow">in</span> <span class="n">generators</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="k">if</span> <span class="n">data_label</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">data_label</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">generators</span><span class="p">[</span><span class="n">data_label</span><span class="p">],</span> <span class="n">LambdaType</span><span class="p">):</span>
<span class="n">last_data_point</span> <span class="o">=</span> <span class="n">sample</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="n">new_data_point</span><span class="p">[</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">generators</span><span class="p">[</span><span class="n">data_label</span><span class="p">](</span><span class="n">last_data_point</span><span class="p">[</span><span class="n">data_label</span><span class="p">])</span>
<span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">generators</span><span class="p">[</span><span class="n">data_label</span><span class="p">],</span> <span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="n">gen_model</span> <span class="o">=</span> <span class="n">generators</span><span class="p">[</span><span class="n">data_label</span><span class="p">]</span>
<span class="n">last_data_point</span> <span class="o">=</span> <span class="n">sample</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="o">-</span><span class="n">gen_model</span><span class="o">.</span><span class="n">order</span><span class="p">:]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">gen_model</span><span class="o">.</span><span class="n">is_multivariate</span><span class="p">:</span>
<span class="n">last_data_point</span> <span class="o">=</span> <span class="n">last_data_point</span><span class="p">[</span><span class="n">data_label</span><span class="p">]</span><span class="o">.</span><span class="n">values</span>
<span class="n">new_data_point</span><span class="p">[</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">gen_model</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">last_data_point</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">new_data_point</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">tmp</span><span class="o">.</span><span class="n">expected_value</span><span class="p">()</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">sample</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">new_data_point</span><span class="p">,</span> <span class="n">ignore_index</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span><span class="p">[</span><span class="o">-</span><span class="n">steps</span><span class="p">:]</span></div>
<div class="viewcode-block" id="ClusteredMVFTS.forecast_multivariate"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.forecast_multivariate">[docs]</a> <span class="k">def</span> <span class="nf">forecast_multivariate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_data</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">generators</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;generators&#39;</span><span class="p">,</span> <span class="p">{})</span>
<span class="n">already_processed_cols</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">{}</span>
<span class="n">ret</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">fuzzyfied</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">pre_fuzzyfy</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="k">for</span> <span class="n">var</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">explanatory_variables</span><span class="p">:</span>
<span class="k">if</span> <span class="n">var</span><span class="o">.</span><span class="n">data_label</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">already_processed_cols</span><span class="p">:</span>
<span class="k">if</span> <span class="n">var</span><span class="o">.</span><span class="n">data_label</span> <span class="ow">in</span> <span class="n">generators</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">generators</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">data_label</span><span class="p">],</span> <span class="n">LambdaType</span><span class="p">):</span>
<span class="n">fx</span> <span class="o">=</span> <span class="n">generators</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span><span class="o">.</span><span class="n">values</span><span class="p">)</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:</span>
<span class="n">ret</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">fx</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span><span class="o">.</span><span class="n">values</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:]]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ret</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">fx</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span><span class="o">.</span><span class="n">values</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])]</span>
<span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">generators</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">data_label</span><span class="p">],</span> <span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">generators</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">model</span><span class="o">.</span><span class="n">is_multivariate</span><span class="p">:</span>
<span class="n">ret</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">model</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">var</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ret</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">model</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="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">name</span> <span class="o">!=</span> <span class="n">var</span><span class="o">.</span><span class="n">name</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span> <span class="o">=</span> <span class="n">var</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">change_target_variable</span><span class="p">(</span><span class="n">var</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">partitioner</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">reset_calculated_values</span><span class="p">()</span>
<span class="n">ret</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">fuzzyfied</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">pre_fuzzyfy</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">already_processed_cols</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">var</span><span class="o">.</span><span class="n">data_label</span><span class="p">)</span>
<span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">ret</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="n">ret</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span></div>
<div class="viewcode-block" id="ClusteredMVFTS.forecast_ahead_multivariate"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.forecast_ahead_multivariate">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_multivariate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">apply_transformations</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">start</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;start_at&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">ndata</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="o">+</span><span class="n">start</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">steps</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">ret</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="n">k</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="o">+</span><span class="n">k</span><span class="p">]</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_multivariate</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span> <span class="n">ignore_index</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;String representation of the model&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">)</span>
<span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> The length (number of rules) of the model</span>
<span class="sd"> :return: number of rules</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">)</span></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.multivariate.cmvfts</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,127 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.multivariate.granular &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
<script src="../../../../_static/jquery.js"></script>
<script src="../../../../_static/underscore.js"></script>
<script src="../../../../_static/doctools.js"></script>
<script src="../../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.multivariate.granular</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.multivariate.granular</h1><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">pyFTS.models.multivariate</span> <span class="kn">import</span> <span class="n">cmvfts</span><span class="p">,</span> <span class="n">grid</span>
<span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="kn">import</span> <span class="n">hofts</span>
<div class="viewcode-block" id="GranularWMVFTS"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.granular.GranularWMVFTS">[docs]</a><span class="k">class</span> <span class="nc">GranularWMVFTS</span><span class="p">(</span><span class="n">cmvfts</span><span class="o">.</span><span class="n">ClusteredMVFTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Granular multivariate weighted high order FTS</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">GranularWMVFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fts_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;fts_method&#39;</span><span class="p">,</span> <span class="n">hofts</span><span class="o">.</span><span class="n">WeightedHighOrderFTS</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="kc">None</span>
<span class="sd">&quot;&quot;&quot;The most recent trained model&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">knn</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;knn&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</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;order&quot;</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;FIG-FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Fuzzy Information Granular FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mode</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;mode&#39;</span><span class="p">,</span><span class="s1">&#39;sets&#39;</span><span class="p">)</span>
<div class="viewcode-block" id="GranularWMVFTS.train"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.granular.GranularWMVFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span> <span class="o">=</span> <span class="n">grid</span><span class="o">.</span><span class="n">IncrementalGridCluster</span><span class="p">(</span>
<span class="n">explanatory_variables</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">explanatory_variables</span><span class="p">,</span>
<span class="n">target_variable</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="p">,</span>
<span class="n">neighbors</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">knn</span><span class="p">)</span>
<span class="nb">super</span><span class="p">(</span><span class="n">GranularWMVFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</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">mode</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">mode</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.multivariate.granular</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,427 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.multivariate.mvfts &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
<script src="../../../../_static/jquery.js"></script>
<script src="../../../../_static/underscore.js"></script>
<script src="../../../../_static/doctools.js"></script>
<script src="../../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.multivariate.mvfts</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.multivariate.mvfts</h1><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">fts</span><span class="p">,</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">FLR</span><span class="p">,</span> <span class="n">Membership</span>
<span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="kn">import</span> <span class="n">Grid</span>
<span class="kn">from</span> <span class="nn">pyFTS.models.multivariate</span> <span class="kn">import</span> <span class="n">FLR</span> <span class="k">as</span> <span class="n">MVFLR</span><span class="p">,</span> <span class="n">common</span><span class="p">,</span> <span class="n">flrg</span> <span class="k">as</span> <span class="n">mvflrg</span>
<span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">product</span>
<span class="kn">from</span> <span class="nn">types</span> <span class="kn">import</span> <span class="n">LambdaType</span>
<span class="kn">from</span> <span class="nn">copy</span> <span class="kn">import</span> <span class="n">deepcopy</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<div class="viewcode-block" id="product_dict"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.mvfts.product_dict">[docs]</a><span class="k">def</span> <span class="nf">product_dict</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"> Code by Seth Johnson</span>
<span class="sd"> :param kwargs:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">keys</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
<span class="n">vals</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">values</span><span class="p">()</span>
<span class="k">for</span> <span class="n">instance</span> <span class="ow">in</span> <span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">vals</span><span class="p">):</span>
<span class="k">yield</span> <span class="nb">dict</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">keys</span><span class="p">,</span> <span class="n">instance</span><span class="p">))</span></div>
<div class="viewcode-block" id="MVFTS"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.mvfts.MVFTS">[docs]</a><span class="k">class</span> <span class="nc">MVFTS</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Multivariate extension of Chen&#39;s ConventionalFTS method</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">MVFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">explanatory_variables</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;explanatory_variables&#39;</span><span class="p">,[])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">target_variable</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;target_variable&#39;</span><span class="p">,</span><span class="kc">None</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_multivariate</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;MVFTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Multivariate FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">uod_clip</span> <span class="o">=</span> <span class="kc">False</span>
<div class="viewcode-block" id="MVFTS.append_transformation"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.mvfts.MVFTS.append_transformation">[docs]</a> <span class="k">def</span> <span class="nf">append_transformation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">transformation</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="ow">not</span> <span class="n">transformation</span><span class="o">.</span><span class="n">is_multivariate</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s1">&#39;The transformation is not multivariate&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transformations</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">transformation</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transformations_param</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">kwargs</span><span class="p">)</span></div>
<div class="viewcode-block" id="MVFTS.append_variable"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.mvfts.MVFTS.append_variable">[docs]</a> <span class="k">def</span> <span class="nf">append_variable</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">var</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Append a new endogenous variable to the model</span>
<span class="sd"> :param var: variable object</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">explanatory_variables</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">var</span><span class="p">)</span></div>
<div class="viewcode-block" id="MVFTS.format_data"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.mvfts.MVFTS.format_data">[docs]</a> <span class="k">def</span> <span class="nf">format_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">var</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">explanatory_variables</span><span class="p">:</span>
<span class="n">ndata</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">var</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">extractor</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">data_label</span><span class="p">])</span>
<span class="k">return</span> <span class="n">ndata</span></div>
<div class="viewcode-block" id="MVFTS.apply_transformations"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.mvfts.MVFTS.apply_transformations">[docs]</a> <span class="k">def</span> <span class="nf">apply_transformations</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">updateUoD</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">deep</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">transformation</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transformations</span><span class="p">):</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="n">transformation</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">transformations_param</span><span class="p">[</span><span class="n">ct</span><span class="p">])</span>
<span class="k">for</span> <span class="n">var</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">explanatory_variables</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">values</span> <span class="o">=</span> <span class="n">ndata</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span><span class="o">.</span><span class="n">values</span> <span class="c1">#if isinstance(ndata, pd.DataFrame) else ndata[var.data_label]</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">uod_clip</span> <span class="ow">and</span> <span class="n">var</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s1">&#39;common&#39;</span><span class="p">:</span>
<span class="n">ndata</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">clip</span><span class="p">(</span><span class="n">values</span><span class="p">,</span>
<span class="n">var</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">min</span><span class="p">,</span> <span class="n">var</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">max</span><span class="p">)</span>
<span class="n">ndata</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">var</span><span class="o">.</span><span class="n">apply_transformations</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>
<span class="k">except</span><span class="p">:</span>
<span class="k">pass</span>
<span class="k">return</span> <span class="n">ndata</span></div>
<div class="viewcode-block" id="MVFTS.generate_lhs_flrs"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.mvfts.MVFTS.generate_lhs_flrs">[docs]</a> <span class="k">def</span> <span class="nf">generate_lhs_flrs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">lags</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">vc</span><span class="p">,</span> <span class="n">var</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">explanatory_variables</span><span class="p">):</span>
<span class="n">data_point</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">name</span><span class="p">]</span>
<span class="n">lags</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">common</span><span class="o">.</span><span class="n">fuzzyfy_instance</span><span class="p">(</span><span class="n">data_point</span><span class="p">,</span> <span class="n">var</span><span class="p">,</span> <span class="n">tuples</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">product_dict</span><span class="p">(</span><span class="o">**</span><span class="n">lags</span><span class="p">):</span>
<span class="n">flr</span> <span class="o">=</span> <span class="n">MVFLR</span><span class="o">.</span><span class="n">FLR</span><span class="p">()</span>
<span class="n">flr</span><span class="o">.</span><span class="n">LHS</span> <span class="o">=</span> <span class="n">path</span>
<span class="c1">#for var, fset in path.items():</span>
<span class="c1"># flr.set_lhs(var, fset)</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">explanatory_variables</span><span class="p">):</span>
<span class="n">flrs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">flr</span><span class="p">)</span>
<span class="k">return</span> <span class="n">flrs</span></div>
<div class="viewcode-block" id="MVFTS.generate_flrs"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.mvfts.MVFTS.generate_flrs">[docs]</a> <span class="k">def</span> <span class="nf">generate_flrs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">ct</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="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">index</span><span class="p">)):</span>
<span class="n">ix</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="n">ct</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="n">data_point</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">format_data</span><span class="p">(</span> <span class="n">data</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span> <span class="p">)</span>
<span class="n">tmp_flrs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_lhs_flrs</span><span class="p">(</span><span class="n">data_point</span><span class="p">)</span>
<span class="n">target_ix</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="n">ct</span><span class="p">]</span>
<span class="n">target_point</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">data_label</span><span class="p">][</span><span class="n">target_ix</span><span class="p">]</span>
<span class="n">target</span> <span class="o">=</span> <span class="n">common</span><span class="o">.</span><span class="n">fuzzyfy_instance</span><span class="p">(</span><span class="n">target_point</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="p">)</span>
<span class="k">for</span> <span class="n">flr</span> <span class="ow">in</span> <span class="n">tmp_flrs</span><span class="p">:</span>
<span class="k">for</span> <span class="n">v</span><span class="p">,</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">target</span><span class="p">:</span>
<span class="n">new_flr</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">flr</span><span class="p">)</span>
<span class="n">new_flr</span><span class="o">.</span><span class="n">set_rhs</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
<span class="n">flrs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">new_flr</span><span class="p">)</span>
<span class="k">return</span> <span class="n">flrs</span></div>
<div class="viewcode-block" id="MVFTS.generate_flrg"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.mvfts.MVFTS.generate_flrg">[docs]</a> <span class="k">def</span> <span class="nf">generate_flrg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrs</span><span class="p">):</span>
<span class="k">for</span> <span class="n">flr</span> <span class="ow">in</span> <span class="n">flrs</span><span class="p">:</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="n">mvflrg</span><span class="o">.</span><span class="n">FLRG</span><span class="p">(</span><span class="n">lhs</span><span class="o">=</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span> <span class="o">=</span> <span class="n">flrg</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div>
<div class="viewcode-block" id="MVFTS.train"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.mvfts.MVFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">apply_transformations</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_flrs</span><span class="p">(</span><span class="n">ndata</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg</span><span class="p">(</span><span class="n">flrs</span><span class="p">)</span></div>
<div class="viewcode-block" id="MVFTS.forecast"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.mvfts.MVFTS.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">apply_transformations</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">c</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">index</span><span class="p">,</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">ndata</span><span class="o">.</span><span class="n">iterrows</span><span class="p">()</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">)</span> <span class="k">else</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">ndata</span><span class="p">):</span>
<span class="n">data_point</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">format_data</span><span class="p">(</span><span class="n">row</span><span class="p">)</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_lhs_flrs</span><span class="p">(</span><span class="n">data_point</span><span class="p">)</span>
<span class="n">mvs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">mps</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">flr</span> <span class="ow">in</span> <span class="n">flrs</span><span class="p">:</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="n">mvflrg</span><span class="o">.</span><span class="n">FLRG</span><span class="p">(</span><span class="n">lhs</span><span class="o">=</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="c1">#Naïve approach is applied when no rules were found</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">name</span> <span class="ow">in</span> <span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">:</span>
<span class="n">fs</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">name</span><span class="p">]</span>
<span class="n">fset</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">fs</span><span class="p">]</span>
<span class="n">mp</span> <span class="o">=</span> <span class="n">fset</span><span class="o">.</span><span class="n">centroid</span>
<span class="n">mv</span> <span class="o">=</span> <span class="n">fset</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">data_point</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">name</span><span class="p">])</span>
<span class="n">mvs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mv</span><span class="p">)</span>
<span class="n">mps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mp</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">mvs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.</span><span class="p">)</span>
<span class="n">mps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">_flrg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span>
<span class="n">mvs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">_flrg</span><span class="o">.</span><span class="n">get_membership</span><span class="p">(</span><span class="n">data_point</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">explanatory_variables</span><span class="p">))</span>
<span class="n">mps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">_flrg</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">))</span>
<span class="n">mv</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="n">mvs</span><span class="p">)</span>
<span class="n">mp</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="n">mps</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">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">mv</span><span class="p">,</span><span class="n">mp</span><span class="o">.</span><span class="n">T</span><span class="p">)</span><span class="o">/</span><span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">mv</span><span class="p">))</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">apply_inverse_transformations</span><span class="p">(</span><span class="n">ret</span><span class="p">,</span>
<span class="n">params</span><span class="o">=</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="MVFTS.forecast_ahead"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.mvfts.MVFTS.forecast_ahead">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">generators</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;generators&#39;</span><span class="p">,</span><span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="n">generators</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s1">&#39;You must provide parameter </span><span class="se">\&#39;</span><span class="s1">generators</span><span class="se">\&#39;</span><span class="s1">! generators is a dict where the keys&#39;</span> <span class="o">+</span>
<span class="s1">&#39; are the dataframe column names (except the target_variable) and the values are &#39;</span> <span class="o">+</span>
<span class="s1">&#39;lambda functions that accept one value (the actual value of the variable) &#39;</span>
<span class="s1">&#39; and return the next value or trained FTS models that accept the actual values and &#39;</span>
<span class="s1">&#39;forecast new ones.&#39;</span><span class="p">)</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">apply_transformations</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">start</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;start_at&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="n">ndata</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="n">start</span><span class="p">:</span> <span class="n">start</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">]</span>
<span class="n">ret</span> <span class="o">=</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">steps</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">ndata</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:]</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">sample</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="nb">isinstance</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</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">tmp</span> <span class="o">=</span> <span class="n">tmp</span><span class="p">[</span><span class="o">-</span><span class="mi">1</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">tmp</span><span class="p">)</span>
<span class="n">new_data_point</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">data_label</span> <span class="ow">in</span> <span class="n">generators</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="k">if</span> <span class="n">data_label</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">data_label</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">generators</span><span class="p">[</span><span class="n">data_label</span><span class="p">],</span> <span class="n">LambdaType</span><span class="p">):</span>
<span class="n">last_data_point</span> <span class="o">=</span> <span class="n">ndata</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">ndata</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span>
<span class="n">new_data_point</span><span class="p">[</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">generators</span><span class="p">[</span><span class="n">data_label</span><span class="p">](</span><span class="n">last_data_point</span><span class="p">[</span><span class="n">data_label</span><span class="p">])</span>
<span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">generators</span><span class="p">[</span><span class="n">data_label</span><span class="p">],</span> <span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="n">gen_model</span> <span class="o">=</span> <span class="n">generators</span><span class="p">[</span><span class="n">data_label</span><span class="p">]</span>
<span class="n">last_data_point</span> <span class="o">=</span> <span class="n">sample</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="o">-</span><span class="n">gen_model</span><span class="o">.</span><span class="n">order</span><span class="p">:]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">gen_model</span><span class="o">.</span><span class="n">is_multivariate</span><span class="p">:</span>
<span class="n">last_data_point</span> <span class="o">=</span> <span class="n">last_data_point</span><span class="p">[</span><span class="n">data_label</span><span class="p">]</span><span class="o">.</span><span class="n">values</span>
<span class="n">new_data_point</span><span class="p">[</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">gen_model</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">last_data_point</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">new_data_point</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">tmp</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="n">ndata</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">new_data_point</span><span class="p">,</span> <span class="n">ignore_index</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span><span class="p">[</span><span class="o">-</span><span class="n">steps</span><span class="p">:]</span></div>
<div class="viewcode-block" id="MVFTS.forecast_interval"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.mvfts.MVFTS.forecast_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">apply_transformations</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">c</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">index</span><span class="p">,</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">ndata</span><span class="o">.</span><span class="n">iterrows</span><span class="p">()</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">)</span> <span class="k">else</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">ndata</span><span class="p">):</span>
<span class="n">data_point</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">format_data</span><span class="p">(</span><span class="n">row</span><span class="p">)</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_lhs_flrs</span><span class="p">(</span><span class="n">data_point</span><span class="p">)</span>
<span class="n">mvs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">ups</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">los</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">flr</span> <span class="ow">in</span> <span class="n">flrs</span><span class="p">:</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="n">mvflrg</span><span class="o">.</span><span class="n">FLRG</span><span class="p">(</span><span class="n">lhs</span><span class="o">=</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="c1">#Naïve approach is applied when no rules were found</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">name</span> <span class="ow">in</span> <span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">:</span>
<span class="n">fs</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">name</span><span class="p">]</span>
<span class="n">fset</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">fs</span><span class="p">]</span>
<span class="n">up</span> <span class="o">=</span> <span class="n">fset</span><span class="o">.</span><span class="n">upper</span>
<span class="n">lo</span> <span class="o">=</span> <span class="n">fset</span><span class="o">.</span><span class="n">lower</span>
<span class="n">mv</span> <span class="o">=</span> <span class="n">fset</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">data_point</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">name</span><span class="p">])</span>
<span class="n">mvs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mv</span><span class="p">)</span>
<span class="n">ups</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">up</span><span class="p">)</span>
<span class="n">los</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">lo</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">mvs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.</span><span class="p">)</span>
<span class="n">ups</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.</span><span class="p">)</span>
<span class="n">los</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">_flrg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span>
<span class="n">mvs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">_flrg</span><span class="o">.</span><span class="n">get_membership</span><span class="p">(</span><span class="n">data_point</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">explanatory_variables</span><span class="p">))</span>
<span class="n">ups</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">_flrg</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">))</span>
<span class="n">los</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">_flrg</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">))</span>
<span class="n">mv</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="n">mvs</span><span class="p">)</span>
<span class="n">up</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">mv</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">ups</span><span class="p">)</span><span class="o">.</span><span class="n">T</span><span class="p">)</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">mv</span><span class="p">)</span>
<span class="n">lo</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">mv</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">los</span><span class="p">)</span><span class="o">.</span><span class="n">T</span><span class="p">)</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">mv</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">lo</span><span class="p">,</span> <span class="n">up</span><span class="p">])</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">apply_inverse_transformations</span><span class="p">(</span><span class="n">ret</span><span class="p">,</span>
<span class="n">params</span><span class="o">=</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="MVFTS.forecast_ahead_interval"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.mvfts.MVFTS.forecast_ahead_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">generators</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;generators&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="n">generators</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s1">&#39;You must provide parameter </span><span class="se">\&#39;</span><span class="s1">generators</span><span class="se">\&#39;</span><span class="s1">! generators is a dict where the keys&#39;</span> <span class="o">+</span>
<span class="s1">&#39; are the dataframe column names (except the target_variable) and the values are &#39;</span> <span class="o">+</span>
<span class="s1">&#39;lambda functions that accept one value (the actual value of the variable) &#39;</span>
<span class="s1">&#39; and return the next value or trained FTS models that accept the actual values and &#39;</span>
<span class="s1">&#39;forecast new ones.&#39;</span><span class="p">)</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">apply_transformations</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">start</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;start_at&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">ix</span> <span class="o">=</span> <span class="n">ndata</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="n">start</span><span class="p">:</span> <span class="n">start</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">]</span>
<span class="n">lo</span> <span class="o">=</span> <span class="n">ndata</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span> <span class="c1">#[ndata.loc[k] for k in ix]</span>
<span class="n">up</span> <span class="o">=</span> <span class="n">ndata</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span> <span class="c1">#[ndata.loc[k] for k in ix]</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">steps</span><span class="p">):</span>
<span class="n">tmp_lo</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_interval</span><span class="p">(</span><span class="n">lo</span><span class="p">[</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">tmp_up</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_interval</span><span class="p">(</span><span class="n">up</span><span class="p">[</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)[</span><span class="mi">0</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="nb">min</span><span class="p">(</span><span class="n">tmp_lo</span><span class="p">),</span> <span class="nb">max</span><span class="p">(</span><span class="n">tmp_up</span><span class="p">)])</span>
<span class="n">new_data_point_lo</span> <span class="o">=</span> <span class="p">{}</span>
<span class="n">new_data_point_up</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">data_label</span> <span class="ow">in</span> <span class="n">generators</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="k">if</span> <span class="n">data_label</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">data_label</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">generators</span><span class="p">[</span><span class="n">data_label</span><span class="p">],</span> <span class="n">LambdaType</span><span class="p">):</span>
<span class="n">last_data_point_lo</span> <span class="o">=</span> <span class="n">lo</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">lo</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span>
<span class="n">new_data_point_lo</span><span class="p">[</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">generators</span><span class="p">[</span><span class="n">data_label</span><span class="p">](</span><span class="n">last_data_point_lo</span><span class="p">[</span><span class="n">data_label</span><span class="p">])</span>
<span class="n">last_data_point_up</span> <span class="o">=</span> <span class="n">up</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">up</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span>
<span class="n">new_data_point_up</span><span class="p">[</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">generators</span><span class="p">[</span><span class="n">data_label</span><span class="p">](</span><span class="n">last_data_point_up</span><span class="p">[</span><span class="n">data_label</span><span class="p">])</span>
<span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">generators</span><span class="p">[</span><span class="n">data_label</span><span class="p">],</span> <span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">generators</span><span class="p">[</span><span class="n">data_label</span><span class="p">]</span>
<span class="n">last_data_point_lo</span> <span class="o">=</span> <span class="n">lo</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">lo</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="o">-</span><span class="n">model</span><span class="o">.</span><span class="n">order</span><span class="p">:]]</span>
<span class="n">last_data_point_up</span> <span class="o">=</span> <span class="n">up</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">up</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="o">-</span><span class="n">model</span><span class="o">.</span><span class="n">order</span><span class="p">:]]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">model</span><span class="o">.</span><span class="n">is_multivariate</span><span class="p">:</span>
<span class="n">last_data_point_lo</span> <span class="o">=</span> <span class="n">last_data_point_lo</span><span class="p">[</span><span class="n">data_label</span><span class="p">]</span><span class="o">.</span><span class="n">values</span>
<span class="n">last_data_point_up</span> <span class="o">=</span> <span class="n">last_data_point_up</span><span class="p">[</span><span class="n">data_label</span><span class="p">]</span><span class="o">.</span><span class="n">values</span>
<span class="n">new_data_point_lo</span><span class="p">[</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">last_data_point_lo</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">new_data_point_up</span><span class="p">[</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">last_data_point_up</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">new_data_point_lo</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">tmp_lo</span><span class="p">)</span>
<span class="n">new_data_point_up</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">tmp_up</span><span class="p">)</span>
<span class="n">lo</span> <span class="o">=</span> <span class="n">lo</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">new_data_point_lo</span><span class="p">,</span> <span class="n">ignore_index</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">up</span> <span class="o">=</span> <span class="n">up</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">new_data_point_up</span><span class="p">,</span> <span class="n">ignore_index</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span><span class="p">[</span><span class="o">-</span><span class="n">steps</span><span class="p">:]</span></div>
<div class="viewcode-block" id="MVFTS.clone_parameters"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.mvfts.MVFTS.clone_parameters">[docs]</a> <span class="k">def</span> <span class="nf">clone_parameters</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">MVFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">clone_parameters</span><span class="p">(</span><span class="n">model</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">explanatory_variables</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">explanatory_variables</span>
<span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">target_variable</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">_str</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">+</span> <span class="s2">&quot;:</span><span class="se">\n</span><span class="s2">&quot;</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="n">_str</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>
<span class="k">return</span> <span class="n">_str</span></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.multivariate.mvfts</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,181 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.multivariate.variable &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
<script src="../../../../_static/jquery.js"></script>
<script src="../../../../_static/underscore.js"></script>
<script src="../../../../_static/doctools.js"></script>
<script src="../../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.multivariate.variable</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.multivariate.variable</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">fts</span><span class="p">,</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">FLR</span><span class="p">,</span> <span class="n">Membership</span><span class="p">,</span> <span class="n">tree</span>
<span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="kn">import</span> <span class="n">Grid</span>
<span class="kn">from</span> <span class="nn">pyFTS.models.multivariate</span> <span class="kn">import</span> <span class="n">FLR</span> <span class="k">as</span> <span class="n">MVFLR</span>
<div class="viewcode-block" id="Variable"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.variable.Variable">[docs]</a><span class="k">class</span> <span class="nc">Variable</span><span class="p">:</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> A variable of a fuzzy time series multivariate model. Each variable contains its own</span>
<span class="sd"> transformations and partitioners.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</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"> :param name:</span>
<span class="sd"> :param \**kwargs: See below</span>
<span class="sd"> :Keyword Arguments:</span>
<span class="sd"> * *alias* -- Alternative name for the variable</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
<span class="sd">&quot;&quot;&quot;A string with the name of the variable&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">alias</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;alias&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;A string with the alias of the variable&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">data_label</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;data_label&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;A string with the column name on DataFrame&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">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="s1">&#39;type&#39;</span><span class="p">,</span> <span class="s1">&#39;common&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">data_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="s1">&#39;data_type&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;The type of the data column on Pandas Dataframe&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mask</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;mask&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;The mask for format the data column on Pandas Dataframe&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transformation</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;transformation&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;Pre processing transformation for the variable&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transformation_params</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;transformation_params&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span> <span class="o">=</span> <span class="kc">None</span>
<span class="sd">&quot;&quot;&quot;UoD partitioner for the variable data&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">alpha_cut</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;alpha_cut&#39;</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;Minimal membership value to be considered on fuzzyfication process&quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;data&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">build</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<div class="viewcode-block" id="Variable.build"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.variable.Variable.build">[docs]</a> <span class="k">def</span> <span class="nf">build</span><span class="p">(</span><span class="bp">self</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"> :param kwargs:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">fs</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;partitioner&#39;</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">mf</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;func&#39;</span><span class="p">,</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trimf</span><span class="p">)</span>
<span class="n">np</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;npart&#39;</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
<span class="n">data</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;data&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="n">kw</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;partitioner_specific&#39;</span><span class="p">,</span> <span class="p">{})</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span> <span class="o">=</span> <span class="n">fs</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="bp">self</span><span class="o">.</span><span class="n">data_label</span><span class="p">]</span><span class="o">.</span><span class="n">values</span><span class="p">,</span> <span class="n">npart</span><span class="o">=</span><span class="n">np</span><span class="p">,</span> <span class="n">func</span><span class="o">=</span><span class="n">mf</span><span class="p">,</span>
<span class="n">transformation</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transformation</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">alias</span><span class="p">,</span>
<span class="n">variable</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">name</span></div>
<div class="viewcode-block" id="Variable.apply_transformations"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.variable.Variable.apply_transformations">[docs]</a> <span class="k">def</span> <span class="nf">apply_transformations</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;params&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transformation_params</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;params&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">transformation</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">transformation</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">transformation_params</span><span class="p">)</span>
<span class="k">return</span> <span class="n">data</span></div>
<div class="viewcode-block" id="Variable.apply_inverse_transformations"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.variable.Variable.apply_inverse_transformations">[docs]</a> <span class="k">def</span> <span class="nf">apply_inverse_transformations</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;params&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transformation_params</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;params&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">transformation</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">transformation</span><span class="o">.</span><span class="n">inverse</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">transformation_params</span><span class="p">)</span>
<span class="k">return</span> <span class="n">data</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.multivariate.variable</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,178 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.multivariate.wmvfts &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
<script src="../../../../_static/jquery.js"></script>
<script src="../../../../_static/underscore.js"></script>
<script src="../../../../_static/doctools.js"></script>
<script src="../../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.multivariate.wmvfts</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.multivariate.wmvfts</h1><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">fts</span><span class="p">,</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">FLR</span><span class="p">,</span> <span class="n">Membership</span><span class="p">,</span> <span class="n">tree</span>
<span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="kn">import</span> <span class="n">Grid</span>
<span class="kn">from</span> <span class="nn">pyFTS.models.multivariate</span> <span class="kn">import</span> <span class="n">mvfts</span><span class="p">,</span> <span class="n">FLR</span> <span class="k">as</span> <span class="n">MVFLR</span><span class="p">,</span> <span class="n">common</span><span class="p">,</span> <span class="n">flrg</span> <span class="k">as</span> <span class="n">mvflrg</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<div class="viewcode-block" id="WeightedFLRG"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.wmvfts.WeightedFLRG">[docs]</a><span class="k">class</span> <span class="nc">WeightedFLRG</span><span class="p">(</span><span class="n">mvflrg</span><span class="o">.</span><span class="n">FLRG</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Weighted Multivariate Fuzzy Logical Rule Group</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">WeightedFLRG</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</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;order&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">LHS</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;lhs&#39;</span><span class="p">,</span> <span class="p">{})</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">w</span> <span class="o">=</span> <span class="kc">None</span>
<div class="viewcode-block" id="WeightedFLRG.append_rhs"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.wmvfts.WeightedFLRG.append_rhs">[docs]</a> <span class="k">def</span> <span class="nf">append_rhs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fset</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">count</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;count&#39;</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
<span class="k">if</span> <span class="n">fset</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">fset</span><span class="p">]</span> <span class="o">=</span> <span class="n">count</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">fset</span><span class="p">]</span> <span class="o">+=</span> <span class="n">count</span>
<span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">+=</span> <span class="n">count</span></div>
<div class="viewcode-block" id="WeightedFLRG.weights"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.wmvfts.WeightedFLRG.weights">[docs]</a> <span class="k">def</span> <span class="nf">weights</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">w</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="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()])</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span></div>
<div class="viewcode-block" id="WeightedFLRG.get_midpoint"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.wmvfts.WeightedFLRG.get_midpoint">[docs]</a> <span class="k">def</span> <span class="nf">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sets</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">midpoint</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">mp</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="n">sets</span><span class="p">[</span><span class="n">c</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">midpoint</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">weights</span><span class="p">())</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">midpoint</span></div>
<div class="viewcode-block" id="WeightedFLRG.get_lower"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.wmvfts.WeightedFLRG.get_lower">[docs]</a> <span class="k">def</span> <span class="nf">get_lower</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sets</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">lower</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">lw</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="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">lower</span> <span class="o">=</span> <span class="n">lw</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">weights</span><span class="p">())</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">lower</span></div>
<div class="viewcode-block" id="WeightedFLRG.get_upper"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.wmvfts.WeightedFLRG.get_upper">[docs]</a> <span class="k">def</span> <span class="nf">get_upper</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sets</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">upper</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">up</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="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">upper</span> <span class="o">=</span> <span class="n">up</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">weights</span><span class="p">())</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">upper</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">_str</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="n">_str</span> <span class="o">+=</span> <span class="s2">&quot;, &quot;</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">_str</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="s2">&quot;&quot;</span>
<span class="n">_str</span> <span class="o">+=</span> <span class="n">k</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="nb">round</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span> <span class="o">+</span> <span class="s2">&quot;)&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="o">+</span> <span class="s2">&quot; -&gt; &quot;</span> <span class="o">+</span> <span class="n">_str</span></div>
<div class="viewcode-block" id="WeightedMVFTS"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.wmvfts.WeightedMVFTS">[docs]</a><span class="k">class</span> <span class="nc">WeightedMVFTS</span><span class="p">(</span><span class="n">mvfts</span><span class="o">.</span><span class="n">MVFTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Weighted Multivariate FTS</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">WeightedMVFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</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="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;WeightedMVFTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Weighted Multivariate FTS&quot;</span>
<div class="viewcode-block" id="WeightedMVFTS.generate_flrg"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.wmvfts.WeightedMVFTS.generate_flrg">[docs]</a> <span class="k">def</span> <span class="nf">generate_flrg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrs</span><span class="p">):</span>
<span class="k">for</span> <span class="n">flr</span> <span class="ow">in</span> <span class="n">flrs</span><span class="p">:</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="n">WeightedFLRG</span><span class="p">(</span><span class="n">lhs</span><span class="o">=</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span> <span class="o">=</span> <span class="n">flrg</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.multivariate.wmvfts</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,371 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.nonstationary.cvfts &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
<script src="../../../../_static/jquery.js"></script>
<script src="../../../../_static/underscore.js"></script>
<script src="../../../../_static/doctools.js"></script>
<script src="../../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.nonstationary.cvfts</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.nonstationary.cvfts</h1><div class="highlight"><pre>
<span></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="kn">import</span> <span class="n">hofts</span>
<span class="kn">from</span> <span class="nn">pyFTS.models.nonstationary</span> <span class="kn">import</span> <span class="n">common</span><span class="p">,</span><span class="n">nsfts</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">FLR</span><span class="p">,</span> <span class="n">flrg</span><span class="p">,</span> <span class="n">tree</span>
<div class="viewcode-block" id="HighOrderNonstationaryFLRG"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.cvfts.HighOrderNonstationaryFLRG">[docs]</a><span class="k">class</span> <span class="nc">HighOrderNonstationaryFLRG</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="sd">&quot;&quot;&quot;Conventional High Order Fuzzy Logical Relationship Group&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">order</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">HighOrderNonstationaryFLRG</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">order</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">LHS</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">strlhs</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<div class="viewcode-block" id="HighOrderNonstationaryFLRG.append_rhs"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.cvfts.HighOrderNonstationaryFLRG.append_rhs">[docs]</a> <span class="k">def</span> <span class="nf">append_rhs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</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">c</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">=</span> <span class="n">c</span></div>
<div class="viewcode-block" id="HighOrderNonstationaryFLRG.append_lhs"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.cvfts.HighOrderNonstationaryFLRG.append_lhs">[docs]</a> <span class="k">def</span> <span class="nf">append_lhs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">c</span><span class="p">)</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">tmp</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="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">):</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">tmp</span> <span class="o">+</span> <span class="s2">&quot;,&quot;</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">tmp</span> <span class="o">+</span> <span class="n">c</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="o">+</span> <span class="s2">&quot; -&gt; &quot;</span> <span class="o">+</span> <span class="n">tmp</span>
<span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div>
<div class="viewcode-block" id="ConditionalVarianceFTS"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS">[docs]</a><span class="k">class</span> <span class="nc">ConditionalVarianceFTS</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="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">ConditionalVarianceFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Conditional Variance FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;CVFTS &quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">append_transformation</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">transformation</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_stack</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">0</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_stack</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">0</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">uod_clip</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_order</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">inputs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">residuals</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">variance_residual</span> <span class="o">=</span> <span class="mf">0.</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mean_residual</span> <span class="o">=</span> <span class="mf">0.</span>
<span class="bp">self</span><span class="o">.</span><span class="n">memory_window</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;memory_window&quot;</span><span class="p">,</span><span class="mi">5</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">sets</span> <span class="o">=</span> <span class="p">{}</span>
<div class="viewcode-block" id="ConditionalVarianceFTS.train"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">tmpdata</span> <span class="o">=</span> <span class="n">common</span><span class="o">.</span><span class="n">fuzzySeries</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">,</span>
<span class="n">method</span><span class="o">=</span><span class="s1">&#39;fuzzy&#39;</span><span class="p">,</span> <span class="n">const_t</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_non_recurrent_flrs</span><span class="p">(</span><span class="n">tmpdata</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg</span><span class="p">(</span><span class="n">flrs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">no_update</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">residuals</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="n">ndata</span><span class="p">[</span><span class="mi">1</span><span class="p">:])</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="bp">self</span><span class="o">.</span><span class="n">forecasts</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">variance_residual</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="p">)</span> <span class="c1"># np.max(self.residuals</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mean_residual</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">residuals</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="p">[</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">memory_window</span><span class="p">:]</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span><span class="p">[</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">memory_window</span><span class="p">:]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">inputs</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="n">ndata</span><span class="p">[</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">memory_window</span><span class="p">:])</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span></div>
<div class="viewcode-block" id="ConditionalVarianceFTS.generate_flrg"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS.generate_flrg">[docs]</a> <span class="k">def</span> <span class="nf">generate_flrg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrs</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">for</span> <span class="n">flr</span> <span class="ow">in</span> <span class="n">flrs</span><span class="p">:</span>
<span class="k">if</span> <span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</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="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">nsfts</span><span class="o">.</span><span class="n">ConventionalNonStationaryFLRG</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">name</span><span class="p">)</span></div>
<span class="k">def</span> <span class="nf">_smooth</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a</span><span class="p">):</span>
<span class="k">return</span> <span class="o">.</span><span class="mi">1</span> <span class="o">*</span> <span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="o">.</span><span class="mi">3</span> <span class="o">*</span> <span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="o">.</span><span class="mi">6</span> <span class="o">*</span> <span class="n">a</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
<div class="viewcode-block" id="ConditionalVarianceFTS.perturbation_factors"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS.perturbation_factors">[docs]</a> <span class="k">def</span> <span class="nf">perturbation_factors</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">npart</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">_max</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">_min</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">if</span> <span class="n">data</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_min</span><span class="p">:</span>
<span class="n">_min</span> <span class="o">=</span> <span class="n">data</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_min</span> <span class="k">if</span> <span class="n">data</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_min</span> <span class="o">-</span> <span class="n">data</span>
<span class="k">elif</span> <span class="n">data</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_max</span><span class="p">:</span>
<span class="n">_max</span> <span class="o">=</span> <span class="n">data</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_max</span> <span class="k">if</span> <span class="n">data</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_max</span> <span class="o">-</span> <span class="n">data</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_stack</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_stack</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">_min</span><span class="p">)</span>
<span class="n">_min</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">min_stack</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_stack</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_stack</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">_max</span><span class="p">)</span>
<span class="n">_max</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">max_stack</span><span class="p">)</span>
<span class="n">_range</span> <span class="o">=</span> <span class="p">(</span><span class="n">_max</span> <span class="o">-</span> <span class="n">_min</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span>
<span class="n">translate</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="n">_min</span><span class="p">,</span> <span class="n">_max</span><span class="p">,</span> <span class="n">npart</span><span class="p">)</span>
<span class="n">var</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">std</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="p">)</span>
<span class="n">var</span> <span class="o">=</span> <span class="mi">0</span> <span class="k">if</span> <span class="n">var</span> <span class="o">&lt;</span> <span class="mi">1</span> <span class="k">else</span> <span class="n">var</span>
<span class="n">loc</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mean_residual</span> <span class="o">+</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="p">))</span>
<span class="n">location</span> <span class="o">=</span> <span class="p">[</span><span class="n">_range</span> <span class="o">+</span> <span class="n">w</span> <span class="o">+</span> <span class="n">loc</span> <span class="o">+</span> <span class="n">k</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">linspace</span><span class="p">(</span><span class="o">-</span><span class="n">var</span><span class="p">,</span><span class="n">var</span><span class="p">,</span> <span class="n">npart</span><span class="p">)</span> <span class="k">for</span> <span class="n">w</span> <span class="ow">in</span> <span class="n">translate</span><span class="p">]</span>
<span class="n">scale</span> <span class="o">=</span> <span class="p">[</span><span class="nb">abs</span><span class="p">(</span><span class="n">location</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">location</span><span class="p">[</span><span class="mi">2</span><span class="p">])]</span>
<span class="n">scale</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="nb">abs</span><span class="p">(</span><span class="n">location</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">location</span><span class="p">[</span><span class="n">k</span> <span class="o">+</span> <span class="mi">1</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">1</span><span class="p">,</span> <span class="n">npart</span><span class="p">)])</span>
<span class="n">scale</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">location</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">location</span><span class="p">[</span><span class="o">-</span><span class="mi">3</span><span class="p">]))</span>
<span class="n">perturb</span> <span class="o">=</span> <span class="p">[[</span><span class="n">location</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">scale</span><span class="p">[</span><span class="n">k</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="n">npart</span><span class="p">)]</span>
<span class="k">return</span> <span class="n">perturb</span></div>
<div class="viewcode-block" id="ConditionalVarianceFTS.perturbation_factors__old"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS.perturbation_factors__old">[docs]</a> <span class="k">def</span> <span class="nf">perturbation_factors__old</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="n">npart</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">_max</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">_min</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">if</span> <span class="n">data</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_min</span><span class="p">:</span>
<span class="n">_min</span> <span class="o">=</span> <span class="n">data</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_min</span> <span class="k">if</span> <span class="n">data</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_min</span> <span class="o">-</span> <span class="n">data</span>
<span class="k">elif</span> <span class="n">data</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_max</span><span class="p">:</span>
<span class="n">_max</span> <span class="o">=</span> <span class="n">data</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_max</span> <span class="k">if</span> <span class="n">data</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_max</span> <span class="o">-</span> <span class="n">data</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_stack</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_stack</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">_min</span><span class="p">)</span>
<span class="n">_min</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">min_stack</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_stack</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_stack</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">_max</span><span class="p">)</span>
<span class="n">_max</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">max_stack</span><span class="p">)</span>
<span class="n">location</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="n">_min</span><span class="p">,</span> <span class="n">_max</span><span class="p">,</span> <span class="n">npart</span><span class="p">)</span>
<span class="n">scale</span> <span class="o">=</span> <span class="p">[</span><span class="nb">abs</span><span class="p">(</span><span class="n">location</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">location</span><span class="p">[</span><span class="mi">2</span><span class="p">])]</span>
<span class="n">scale</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="nb">abs</span><span class="p">(</span><span class="n">location</span><span class="p">[</span><span class="n">k</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">location</span><span class="p">[</span><span class="n">k</span><span class="o">+</span><span class="mi">1</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">1</span><span class="p">,</span> <span class="n">npart</span><span class="p">)])</span>
<span class="n">scale</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">location</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">location</span><span class="p">[</span><span class="o">-</span><span class="mi">3</span><span class="p">]))</span>
<span class="n">perturb</span> <span class="o">=</span> <span class="p">[[</span><span class="n">location</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">scale</span><span class="p">[</span><span class="n">k</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">npart</span><span class="p">)]</span>
<span class="k">return</span> <span class="n">perturb</span></div>
<span class="k">def</span> <span class="nf">_fsset_key</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ix</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">_affected_sets</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sample</span><span class="p">,</span> <span class="n">perturb</span><span class="p">):</span>
<span class="n">affected_sets</span> <span class="o">=</span> <span class="p">[[</span><span class="n">ct</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_fsset_key</span><span class="p">(</span><span class="n">ct</span><span class="p">)]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">perturb</span><span class="p">[</span><span class="n">ct</span><span class="p">])]</span>
<span class="k">for</span> <span class="n">ct</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="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">))</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_fsset_key</span><span class="p">(</span><span class="n">ct</span><span class="p">)]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">perturb</span><span class="p">[</span><span class="n">ct</span><span class="p">])</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">]</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">affected_sets</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">if</span> <span class="n">sample</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">lower_set</span><span class="p">()</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="n">perturb</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
<span class="n">affected_sets</span><span class="o">.</span><span class="n">append</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="k">elif</span> <span class="n">sample</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">upper_set</span><span class="p">()</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="n">perturb</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]):</span>
<span class="n">affected_sets</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="k">return</span> <span class="n">affected_sets</span>
<div class="viewcode-block" id="ConditionalVarianceFTS.forecast"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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">ndata</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">no_update</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;no_update&quot;</span><span class="p">,</span><span class="kc">False</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">sample</span> <span class="o">=</span> <span class="n">ndata</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">no_update</span><span class="p">:</span>
<span class="n">perturb</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">perturbation_factors</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">perturb</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="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="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">))]</span>
<span class="n">affected_sets</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_affected_sets</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">perturb</span><span class="p">)</span>
<span class="n">numerator</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">denominator</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">affected_sets</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">ix</span> <span class="o">=</span> <span class="n">affected_sets</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="n">aset</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span>
<span class="k">if</span> <span class="n">aset</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">numerator</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">aset</span><span class="p">]</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">perturb</span><span class="p">[</span><span class="n">ix</span><span class="p">]))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">fuzzy_set</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">aset</span><span class="p">]</span>
<span class="n">numerator</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">fuzzy_set</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="n">perturb</span><span class="p">[</span><span class="n">ix</span><span class="p">]))</span>
<span class="n">denominator</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">for</span> <span class="n">aset</span> <span class="ow">in</span> <span class="n">affected_sets</span><span class="p">:</span>
<span class="n">ix</span> <span class="o">=</span> <span class="n">aset</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">fs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span>
<span class="n">tdisp</span> <span class="o">=</span> <span class="n">perturb</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span>
<span class="k">if</span> <span class="n">fs</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">numerator</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">fs</span><span class="p">]</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">tdisp</span><span class="p">)</span> <span class="o">*</span> <span class="n">aset</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">fuzzy_set</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">fs</span><span class="p">]</span>
<span class="n">numerator</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">fuzzy_set</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="n">tdisp</span><span class="p">)</span> <span class="o">*</span> <span class="n">aset</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="n">denominator</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">aset</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="k">if</span> <span class="nb">sum</span><span class="p">(</span><span class="n">denominator</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">pto</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">numerator</span><span class="p">)</span> <span class="o">/</span><span class="nb">sum</span><span class="p">(</span><span class="n">denominator</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">pto</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">numerator</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">pto</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">no_update</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pto</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">inputs</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">inputs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">inputs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="ConditionalVarianceFTS.forecast_interval"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS.forecast_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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">ndata</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</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">sample</span> <span class="o">=</span> <span class="n">ndata</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>
<span class="n">perturb</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">perturbation_factors</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="n">affected_sets</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_affected_sets</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">perturb</span><span class="p">)</span>
<span class="n">upper</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">lower</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">affected_sets</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">ix</span> <span class="o">=</span> <span class="n">affected_sets</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="n">aset</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span>
<span class="k">if</span> <span class="n">aset</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">lower</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">aset</span><span class="p">]</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="n">perturb</span><span class="p">[</span><span class="n">ix</span><span class="p">]))</span>
<span class="n">upper</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">aset</span><span class="p">]</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="n">perturb</span><span class="p">[</span><span class="n">ix</span><span class="p">]))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">fuzzy_set</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">aset</span><span class="p">]</span>
<span class="n">lower</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">fuzzy_set</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="n">perturb</span><span class="p">[</span><span class="n">ix</span><span class="p">]))</span>
<span class="n">upper</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">fuzzy_set</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="n">perturb</span><span class="p">[</span><span class="n">ix</span><span class="p">]))</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">for</span> <span class="n">aset</span> <span class="ow">in</span> <span class="n">affected_sets</span><span class="p">:</span>
<span class="n">ix</span> <span class="o">=</span> <span class="n">aset</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">fs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span>
<span class="n">tdisp</span> <span class="o">=</span> <span class="n">perturb</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span>
<span class="k">if</span> <span class="n">fs</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">lower</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">fs</span><span class="p">]</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="n">tdisp</span><span class="p">)</span> <span class="o">*</span> <span class="n">aset</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="n">upper</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">fs</span><span class="p">]</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="n">tdisp</span><span class="p">)</span> <span class="o">*</span> <span class="n">aset</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">fuzzy_set</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">fs</span><span class="p">]</span>
<span class="n">lower</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">fuzzy_set</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="n">tdisp</span><span class="p">)</span> <span class="o">*</span> <span class="n">aset</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="n">upper</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">fuzzy_set</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="n">tdisp</span><span class="p">)</span> <span class="o">*</span> <span class="n">aset</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="n">itvl</span> <span class="o">=</span> <span class="p">[</span><span class="nb">sum</span><span class="p">(</span><span class="n">lower</span><span class="p">),</span> <span class="nb">sum</span><span class="p">(</span><span class="n">upper</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">itvl</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.nonstationary.cvfts</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,357 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.nonstationary.honsfts &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
<script src="../../../../_static/jquery.js"></script>
<script src="../../../../_static/underscore.js"></script>
<script src="../../../../_static/doctools.js"></script>
<script src="../../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.nonstationary.honsfts</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.nonstationary.honsfts</h1><div class="highlight"><pre>
<span></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.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">FLR</span><span class="p">,</span> <span class="n">fts</span>
<span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="kn">import</span> <span class="n">hofts</span>
<span class="kn">from</span> <span class="nn">pyFTS.models.nonstationary</span> <span class="kn">import</span> <span class="n">common</span><span class="p">,</span> <span class="n">flrg</span><span class="p">,</span> <span class="n">nsfts</span>
<span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">product</span>
<div class="viewcode-block" id="HighOrderNonStationaryFLRG"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG">[docs]</a><span class="k">class</span> <span class="nc">HighOrderNonStationaryFLRG</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">NonStationaryFLRG</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;First Order NonStationary Fuzzy Logical Relationship Group&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">order</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">HighOrderNonStationaryFLRG</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">order</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">LHS</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">strlhs</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">w</span> <span class="o">=</span> <span class="kc">None</span>
<div class="viewcode-block" id="HighOrderNonStationaryFLRG.append_rhs"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG.append_rhs">[docs]</a> <span class="k">def</span> <span class="nf">append_rhs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fset</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">count</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;count&#39;</span><span class="p">,</span><span class="mf">1.0</span><span class="p">)</span>
<span class="k">if</span> <span class="n">fset</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">fset</span><span class="p">]</span> <span class="o">=</span> <span class="n">count</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">fset</span><span class="p">]</span> <span class="o">+=</span> <span class="n">count</span>
<span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">+=</span> <span class="n">count</span></div>
<div class="viewcode-block" id="HighOrderNonStationaryFLRG.append_lhs"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG.append_lhs">[docs]</a> <span class="k">def</span> <span class="nf">append_lhs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">c</span><span class="p">)</span></div>
<div class="viewcode-block" id="HighOrderNonStationaryFLRG.weights"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG.weights">[docs]</a> <span class="k">def</span> <span class="nf">weights</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">w</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="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()])</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span></div>
<div class="viewcode-block" id="HighOrderNonStationaryFLRG.get_midpoint"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG.get_midpoint">[docs]</a> <span class="k">def</span> <span class="nf">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sets</span><span class="p">,</span> <span class="n">perturb</span><span class="p">):</span>
<span class="n">mp</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="n">sets</span><span class="p">[</span><span class="n">c</span><span class="p">]</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="n">perturb</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()])</span>
<span class="n">midpoint</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">weights</span><span class="p">())</span>
<span class="k">return</span> <span class="n">midpoint</span></div>
<div class="viewcode-block" id="HighOrderNonStationaryFLRG.get_lower"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG.get_lower">[docs]</a> <span class="k">def</span> <span class="nf">get_lower</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sets</span><span class="p">,</span> <span class="n">perturb</span><span class="p">):</span>
<span class="n">lw</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="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="n">perturb</span><span class="p">)</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()])</span>
<span class="n">lower</span> <span class="o">=</span> <span class="n">lw</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">weights</span><span class="p">())</span>
<span class="k">return</span> <span class="n">lower</span></div>
<div class="viewcode-block" id="HighOrderNonStationaryFLRG.get_upper"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG.get_upper">[docs]</a> <span class="k">def</span> <span class="nf">get_upper</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sets</span><span class="p">,</span> <span class="n">perturb</span><span class="p">):</span>
<span class="n">up</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="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="n">perturb</span><span class="p">)</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()])</span>
<span class="n">upper</span> <span class="o">=</span> <span class="n">up</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">weights</span><span class="p">())</span>
<span class="k">return</span> <span class="n">upper</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">_str</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="n">_str</span> <span class="o">+=</span> <span class="s2">&quot;, &quot;</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">_str</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="s2">&quot;&quot;</span>
<span class="n">_str</span> <span class="o">+=</span> <span class="n">k</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="nb">round</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span> <span class="o">+</span> <span class="s2">&quot;)&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="o">+</span> <span class="s2">&quot; -&gt; &quot;</span> <span class="o">+</span> <span class="n">_str</span>
<span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div>
<div class="viewcode-block" id="HighOrderNonStationaryFTS"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFTS">[docs]</a><span class="k">class</span> <span class="nc">HighOrderNonStationaryFTS</span><span class="p">(</span><span class="n">nsfts</span><span class="o">.</span><span class="n">NonStationaryFTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;NonStationaryFTS Fuzzy Time Series&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">HighOrderNonStationaryFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;High Order Non Stationary FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;HONSFTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</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;order&quot;</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">configure_lags</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<div class="viewcode-block" id="HighOrderNonStationaryFTS.configure_lags"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFTS.configure_lags">[docs]</a> <span class="k">def</span> <span class="nf">configure_lags</span><span class="p">(</span><span class="bp">self</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="s2">&quot;order&quot;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</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;order&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">min_order</span><span class="p">)</span>
<span class="k">if</span> <span class="s2">&quot;lags&quot;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">lags</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;lags&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">lags</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lags</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span>
<span class="bp">self</span><span class="o">.</span><span class="n">lags</span> <span class="o">=</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="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span></div>
<div class="viewcode-block" id="HighOrderNonStationaryFTS.train"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;conditional&#39;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span> <span class="o">=</span> <span class="bp">self</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">no_update</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">residuals</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="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">:])</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="bp">self</span><span class="o">.</span><span class="n">forecasts</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">variance_residual</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="p">)</span> <span class="c1"># np.max(self.residuals</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mean_residual</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">residuals</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="p">[</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">memory_window</span><span class="p">:]</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span><span class="p">[</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">memory_window</span><span class="p">:]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">inputs</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="n">data</span><span class="p">[</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">memory_window</span><span class="p">:])</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span></div>
<div class="viewcode-block" id="HighOrderNonStationaryFTS.generate_flrg"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFTS.generate_flrg">[docs]</a> <span class="k">def</span> <span class="nf">generate_flrg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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">data</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="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dump</span><span class="p">:</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;FLR: &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">k</span><span class="p">))</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">rhs</span> <span class="o">=</span> <span class="p">[</span><span class="n">key</span> <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="p">],</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="o">&gt;</span> <span class="mf">0.0</span><span class="p">]</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">rhs</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">rhs</span> <span class="o">=</span> <span class="p">[</span><span class="n">common</span><span class="o">.</span><span class="n">check_bounds</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="p">,</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="o">.</span><span class="n">name</span><span class="p">]</span>
<span class="n">lags</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">o</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="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">):</span>
<span class="n">tdisp</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="n">lhs</span> <span class="o">=</span> <span class="p">[</span><span class="n">key</span> <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">sample</span><span class="p">[</span><span class="n">o</span><span class="p">],</span> <span class="n">tdisp</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">]</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">lhs</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">lhs</span> <span class="o">=</span> <span class="p">[</span><span class="n">common</span><span class="o">.</span><span class="n">check_bounds</span><span class="p">(</span><span class="n">sample</span><span class="p">[</span><span class="n">o</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="p">,</span> <span class="n">tdisp</span><span class="p">)</span><span class="o">.</span><span class="n">name</span><span class="p">]</span>
<span class="n">lags</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">lhs</span><span class="p">)</span>
<span class="c1"># Trace the possible paths</span>
<span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">lags</span><span class="p">):</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="n">HighOrderNonStationaryFLRG</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">)</span>
<span class="k">for</span> <span class="n">c</span><span class="p">,</span> <span class="n">e</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">path</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">flrg</span><span class="o">.</span><span class="n">append_lhs</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span> <span class="o">=</span> <span class="n">flrg</span><span class="p">;</span>
<span class="k">for</span> <span class="n">st</span> <span class="ow">in</span> <span class="n">rhs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">st</span><span class="p">)</span></div>
<span class="k">def</span> <span class="nf">_affected_flrgs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sample</span><span class="p">,</span> <span class="n">perturb</span><span class="p">):</span>
<span class="n">affected_flrgs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">affected_flrgs_memberships</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">lags</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">dat</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">sample</span><span class="p">):</span>
<span class="n">affected_sets</span> <span class="o">=</span> <span class="p">[</span><span class="n">key</span> <span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">dat</span><span class="p">,</span> <span class="n">perturb</span><span class="p">[</span><span class="n">ct</span><span class="p">])</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">]</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">affected_sets</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">if</span> <span class="n">dat</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">lower_set</span><span class="p">()</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="n">perturb</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
<span class="n">affected_sets</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">lower_set</span><span class="p">()</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">dat</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">upper_set</span><span class="p">()</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="n">perturb</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]):</span>
<span class="n">affected_sets</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">upper_set</span><span class="p">()</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="n">lags</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">affected_sets</span><span class="p">)</span>
<span class="c1"># Build the tree with all possible paths</span>
<span class="c1"># Trace the possible paths</span>
<span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">lags</span><span class="p">):</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="n">HighOrderNonStationaryFLRG</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">)</span>
<span class="k">for</span> <span class="n">kk</span> <span class="ow">in</span> <span class="n">path</span><span class="p">:</span>
<span class="n">flrg</span><span class="o">.</span><span class="n">append_lhs</span><span class="p">(</span><span class="n">kk</span><span class="p">)</span>
<span class="n">affected_flrgs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">flrg</span><span class="p">)</span>
<span class="n">mv</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">dat</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">sample</span><span class="p">):</span>
<span class="n">fset</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="n">ct</span><span class="p">]]</span>
<span class="n">ix</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="n">ct</span><span class="p">])</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">fset</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">dat</span><span class="p">,</span> <span class="n">perturb</span><span class="p">[</span><span class="n">ix</span><span class="p">])</span>
<span class="n">mv</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>
<span class="n">affected_flrgs_memberships</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">prod</span><span class="p">(</span><span class="n">mv</span><span class="p">))</span>
<span class="k">return</span> <span class="p">[</span><span class="n">affected_flrgs</span><span class="p">,</span> <span class="n">affected_flrgs_memberships</span><span class="p">]</span>
<div class="viewcode-block" id="HighOrderNonStationaryFTS.forecast"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFTS.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">explain</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;explain&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="n">time_displacement</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;time_displacement&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="n">window_size</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;window_size&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">no_update</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;no_update&quot;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</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">ndata</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">explain</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">+</span> <span class="mi">1</span>
<span class="k">if</span> <span class="n">l</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span>
<span class="k">return</span> <span class="n">ndata</span>
<span class="k">elif</span> <span class="n">l</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span>
<span class="n">l</span> <span class="o">+=</span> <span class="mi">1</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="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">ndata</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;unconditional&#39;</span><span class="p">:</span>
<span class="n">perturb</span> <span class="o">=</span> <span class="n">common</span><span class="o">.</span><span class="n">window_index</span><span class="p">(</span><span class="n">k</span> <span class="o">+</span> <span class="n">time_displacement</span><span class="p">,</span> <span class="n">window_size</span><span class="p">)</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;conditional&#39;</span><span class="p">:</span>
<span class="k">if</span> <span class="n">no_update</span><span class="p">:</span>
<span class="n">perturb</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="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="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">partitions</span><span class="p">)]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">perturb</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">conditional_perturbation_factors</span><span class="p">(</span><span class="n">sample</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="n">affected_flrgs</span><span class="p">,</span> <span class="n">affected_flrgs_memberships</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_affected_flrgs</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">perturb</span><span class="p">)</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">perturb2</span> <span class="o">=</span> <span class="n">perturb</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">affected_flrgs</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">common</span><span class="o">.</span><span class="n">check_bounds</span><span class="p">(</span><span class="n">sample</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">perturb2</span><span class="p">))</span>
<span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">affected_flrgs</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="n">affected_flrgs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">perturb2</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">fset</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span>
<span class="n">ix</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">fset</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="n">perturb</span><span class="p">[</span><span class="n">ix</span><span class="p">]))</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">aset</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">affected_flrgs</span><span class="p">):</span>
<span class="k">if</span> <span class="n">aset</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">aset</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">perturb2</span><span class="p">)</span> <span class="o">*</span>
<span class="n">affected_flrgs_memberships</span><span class="p">[</span><span class="n">ct</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">fset</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">aset</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span>
<span class="n">ix</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">aset</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">fset</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="n">perturb</span><span class="p">[</span><span class="n">ix</span><span class="p">])</span><span class="o">*</span><span class="n">affected_flrgs_memberships</span><span class="p">[</span><span class="n">ct</span><span class="p">])</span>
<span class="n">pto</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">tmp</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">pto</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;conditional&#39;</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">no_update</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pto</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">inputs</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">inputs</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="k">for</span> <span class="n">g</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">inputs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">+</span> <span class="s2">&quot;:</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="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{0}{1}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">r</span><span class="p">]))</span>
<span class="k">return</span> <span class="n">tmp</span></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.nonstationary.honsfts</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,458 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.nonstationary.nsfts &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
<script src="../../../../_static/jquery.js"></script>
<script src="../../../../_static/underscore.js"></script>
<script src="../../../../_static/doctools.js"></script>
<script src="../../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.nonstationary.nsfts</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.nonstationary.nsfts</h1><div class="highlight"><pre>
<span></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.common</span> <span class="kn">import</span> <span class="n">FLR</span><span class="p">,</span> <span class="n">fts</span>
<span class="kn">from</span> <span class="nn">pyFTS.models.nonstationary</span> <span class="kn">import</span> <span class="n">common</span><span class="p">,</span> <span class="n">flrg</span>
<div class="viewcode-block" id="ConventionalNonStationaryFLRG"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.nsfts.ConventionalNonStationaryFLRG">[docs]</a><span class="k">class</span> <span class="nc">ConventionalNonStationaryFLRG</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">NonStationaryFLRG</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;First Order NonStationary Fuzzy Logical Relationship Group&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">LHS</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">ConventionalNonStationaryFLRG</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">LHS</span> <span class="o">=</span> <span class="n">LHS</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
<div class="viewcode-block" id="ConventionalNonStationaryFLRG.get_key"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.nsfts.ConventionalNonStationaryFLRG.get_key">[docs]</a> <span class="k">def</span> <span class="nf">get_key</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">LHS</span></div>
<div class="viewcode-block" id="ConventionalNonStationaryFLRG.append_rhs"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.nsfts.ConventionalNonStationaryFLRG.append_rhs">[docs]</a> <span class="k">def</span> <span class="nf">append_rhs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">c</span><span class="p">)</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">LHS</span> <span class="o">+</span> <span class="s2">&quot; -&gt; &quot;</span>
<span class="n">tmp2</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="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">):</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">tmp2</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">tmp2</span> <span class="o">=</span> <span class="n">tmp2</span> <span class="o">+</span> <span class="s2">&quot;,&quot;</span>
<span class="n">tmp2</span> <span class="o">=</span> <span class="n">tmp2</span> <span class="o">+</span> <span class="n">c</span>
<span class="k">return</span> <span class="n">tmp</span> <span class="o">+</span> <span class="n">tmp2</span></div>
<div class="viewcode-block" id="WeightedNonStationaryFLRG"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFLRG">[docs]</a><span class="k">class</span> <span class="nc">WeightedNonStationaryFLRG</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">NonStationaryFLRG</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;First Order NonStationary Fuzzy Logical Relationship Group&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">LHS</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">WeightedNonStationaryFLRG</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">LHS</span> <span class="o">=</span> <span class="n">LHS</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">strlhs</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">w</span> <span class="o">=</span> <span class="kc">None</span>
<div class="viewcode-block" id="WeightedNonStationaryFLRG.get_key"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFLRG.get_key">[docs]</a> <span class="k">def</span> <span class="nf">get_key</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">LHS</span></div>
<div class="viewcode-block" id="WeightedNonStationaryFLRG.append_rhs"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFLRG.append_rhs">[docs]</a> <span class="k">def</span> <span class="nf">append_rhs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</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">c</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span></div>
<div class="viewcode-block" id="WeightedNonStationaryFLRG.weights"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFLRG.weights">[docs]</a> <span class="k">def</span> <span class="nf">weights</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">w</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="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()])</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span></div>
<div class="viewcode-block" id="WeightedNonStationaryFLRG.get_midpoint"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFLRG.get_midpoint">[docs]</a> <span class="k">def</span> <span class="nf">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sets</span><span class="p">,</span> <span class="n">perturb</span><span class="p">):</span>
<span class="n">mp</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="n">sets</span><span class="p">[</span><span class="n">c</span><span class="p">]</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="n">perturb</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()])</span>
<span class="n">midpoint</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">weights</span><span class="p">())</span>
<span class="k">return</span> <span class="n">midpoint</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">_str</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="n">_str</span> <span class="o">+=</span> <span class="s2">&quot;, &quot;</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">_str</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="s2">&quot;&quot;</span>
<span class="n">_str</span> <span class="o">+=</span> <span class="n">k</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="nb">round</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span> <span class="o">+</span> <span class="s2">&quot;)&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="o">+</span> <span class="s2">&quot; -&gt; &quot;</span> <span class="o">+</span> <span class="n">_str</span></div>
<div class="viewcode-block" id="NonStationaryFTS"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.nsfts.NonStationaryFTS">[docs]</a><span class="k">class</span> <span class="nc">NonStationaryFTS</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;NonStationaryFTS Fuzzy Time Series&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">NonStationaryFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Non Stationary FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;NSFTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</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="s1">&#39;conditional&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">append_transformation</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">transformation</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;conditional&#39;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_stack</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">0</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_stack</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">0</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">uod_clip</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_order</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">inputs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">residuals</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">variance_residual</span> <span class="o">=</span> <span class="mf">0.</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mean_residual</span> <span class="o">=</span> <span class="mf">0.</span>
<span class="bp">self</span><span class="o">.</span><span class="n">memory_window</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;memory_window&quot;</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<div class="viewcode-block" id="NonStationaryFTS.generate_flrg"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.nsfts.NonStationaryFTS.generate_flrg">[docs]</a> <span class="k">def</span> <span class="nf">generate_flrg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrs</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">for</span> <span class="n">flr</span> <span class="ow">in</span> <span class="n">flrs</span><span class="p">:</span>
<span class="k">if</span> <span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</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="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">ConventionalNonStationaryFLRG</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">name</span><span class="p">)</span></div>
<span class="k">def</span> <span class="nf">_smooth</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a</span><span class="p">):</span>
<span class="k">return</span> <span class="o">.</span><span class="mi">1</span> <span class="o">*</span> <span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="o">.</span><span class="mi">3</span> <span class="o">*</span> <span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="o">.</span><span class="mi">6</span> <span class="o">*</span> <span class="n">a</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
<div class="viewcode-block" id="NonStationaryFTS.train"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.nsfts.NonStationaryFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;unconditional&#39;</span><span class="p">:</span>
<span class="n">window_size</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;parameters&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">tmpdata</span> <span class="o">=</span> <span class="n">common</span><span class="o">.</span><span class="n">fuzzySeries</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">,</span>
<span class="n">window_size</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;fuzzy&#39;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">tmpdata</span> <span class="o">=</span> <span class="n">common</span><span class="o">.</span><span class="n">fuzzySeries</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">,</span>
<span class="n">method</span><span class="o">=</span><span class="s1">&#39;fuzzy&#39;</span><span class="p">,</span> <span class="n">const_t</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_non_recurrent_flrs</span><span class="p">(</span><span class="n">tmpdata</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg</span><span class="p">(</span><span class="n">flrs</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;conditional&#39;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span> <span class="o">=</span> <span class="bp">self</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">no_update</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">residuals</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="n">data</span><span class="p">[</span><span class="mi">1</span><span class="p">:])</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="bp">self</span><span class="o">.</span><span class="n">forecasts</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">variance_residual</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="p">)</span> <span class="c1"># np.max(self.residuals</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mean_residual</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">residuals</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="p">[</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">memory_window</span><span class="p">:]</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span><span class="p">[</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">memory_window</span><span class="p">:]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">inputs</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="n">data</span><span class="p">[</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">memory_window</span><span class="p">:])</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span></div>
<div class="viewcode-block" id="NonStationaryFTS.conditional_perturbation_factors"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.nsfts.NonStationaryFTS.conditional_perturbation_factors">[docs]</a> <span class="k">def</span> <span class="nf">conditional_perturbation_factors</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">npart</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">_max</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">_min</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">if</span> <span class="n">data</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_min</span><span class="p">:</span>
<span class="n">_min</span> <span class="o">=</span> <span class="n">data</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_min</span> <span class="k">if</span> <span class="n">data</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_min</span> <span class="o">-</span> <span class="n">data</span>
<span class="k">elif</span> <span class="n">data</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_max</span><span class="p">:</span>
<span class="n">_max</span> <span class="o">=</span> <span class="n">data</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_max</span> <span class="k">if</span> <span class="n">data</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_max</span> <span class="o">-</span> <span class="n">data</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_stack</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_stack</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">_min</span><span class="p">)</span>
<span class="n">_min</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">min_stack</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_stack</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max_stack</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">_max</span><span class="p">)</span>
<span class="n">_max</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">max_stack</span><span class="p">)</span>
<span class="n">_range</span> <span class="o">=</span> <span class="p">(</span><span class="n">_max</span> <span class="o">-</span> <span class="n">_min</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span>
<span class="n">translate</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="n">_min</span><span class="p">,</span> <span class="n">_max</span><span class="p">,</span> <span class="n">npart</span><span class="p">)</span>
<span class="n">var</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">std</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="p">)</span>
<span class="n">var</span> <span class="o">=</span> <span class="mi">0</span> <span class="k">if</span> <span class="n">var</span> <span class="o">&lt;</span> <span class="mi">1</span> <span class="k">else</span> <span class="n">var</span>
<span class="n">loc</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mean_residual</span> <span class="o">+</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="p">))</span>
<span class="n">location</span> <span class="o">=</span> <span class="p">[</span><span class="n">_range</span> <span class="o">+</span> <span class="n">w</span> <span class="o">+</span> <span class="n">loc</span> <span class="o">+</span> <span class="n">k</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">linspace</span><span class="p">(</span><span class="o">-</span><span class="n">var</span><span class="p">,</span><span class="n">var</span><span class="p">,</span> <span class="n">npart</span><span class="p">)</span> <span class="k">for</span> <span class="n">w</span> <span class="ow">in</span> <span class="n">translate</span><span class="p">]</span>
<span class="n">scale</span> <span class="o">=</span> <span class="p">[</span><span class="nb">abs</span><span class="p">(</span><span class="n">location</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">location</span><span class="p">[</span><span class="mi">2</span><span class="p">])]</span>
<span class="n">scale</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="nb">abs</span><span class="p">(</span><span class="n">location</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">location</span><span class="p">[</span><span class="n">k</span> <span class="o">+</span> <span class="mi">1</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">1</span><span class="p">,</span> <span class="n">npart</span><span class="p">)])</span>
<span class="n">scale</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">location</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">location</span><span class="p">[</span><span class="o">-</span><span class="mi">3</span><span class="p">]))</span>
<span class="n">perturb</span> <span class="o">=</span> <span class="p">[[</span><span class="n">location</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">scale</span><span class="p">[</span><span class="n">k</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="n">npart</span><span class="p">)]</span>
<span class="k">return</span> <span class="n">perturb</span></div>
<span class="k">def</span> <span class="nf">_affected_sets</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sample</span><span class="p">,</span> <span class="n">perturb</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;conditional&#39;</span><span class="p">:</span>
<span class="n">affected_sets</span> <span class="o">=</span> <span class="p">[[</span><span class="n">ct</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">perturb</span><span class="p">[</span><span class="n">ct</span><span class="p">])]</span>
<span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">perturb</span><span class="p">[</span><span class="n">ct</span><span class="p">])</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">]</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">affected_sets</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">if</span> <span class="n">sample</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">lower_set</span><span class="p">()</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="n">perturb</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
<span class="n">affected_sets</span><span class="o">.</span><span class="n">append</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="k">elif</span> <span class="n">sample</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">upper_set</span><span class="p">()</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="n">perturb</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]):</span>
<span class="n">affected_sets</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">affected_sets</span> <span class="o">=</span> <span class="p">[[</span><span class="n">ct</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">perturb</span><span class="p">)]</span>
<span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">perturb</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">]</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">affected_sets</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">if</span> <span class="n">sample</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">lower_set</span><span class="p">()</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="n">perturb</span><span class="p">):</span>
<span class="n">affected_sets</span><span class="o">.</span><span class="n">append</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="k">elif</span> <span class="n">sample</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">upper_set</span><span class="p">()</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="n">perturb</span><span class="p">):</span>
<span class="n">affected_sets</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="k">return</span> <span class="n">affected_sets</span>
<div class="viewcode-block" id="NonStationaryFTS.forecast"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.nsfts.NonStationaryFTS.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">time_displacement</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;time_displacement&quot;</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
<span class="n">window_size</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;window_size&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">no_update</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;no_update&quot;</span><span class="p">,</span> <span class="kc">False</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">ndata</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</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">sample</span> <span class="o">=</span> <span class="n">ndata</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;unconditional&#39;</span><span class="p">:</span>
<span class="n">perturb</span> <span class="o">=</span> <span class="n">common</span><span class="o">.</span><span class="n">window_index</span><span class="p">(</span><span class="n">k</span> <span class="o">+</span> <span class="n">time_displacement</span><span class="p">,</span> <span class="n">window_size</span><span class="p">)</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;conditional&#39;</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">no_update</span><span class="p">:</span>
<span class="n">perturb</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">conditional_perturbation_factors</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">perturb</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="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="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">))]</span>
<span class="n">affected_sets</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_affected_sets</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">perturb</span><span class="p">)</span>
<span class="n">numerator</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">denominator</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">affected_sets</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">ix</span> <span class="o">=</span> <span class="n">affected_sets</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="n">aset</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span>
<span class="k">if</span> <span class="n">aset</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">numerator</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">aset</span><span class="p">]</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">perturb</span><span class="p">[</span><span class="n">ix</span><span class="p">]))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">fuzzy_set</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">aset</span><span class="p">]</span>
<span class="n">numerator</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">fuzzy_set</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="n">perturb</span><span class="p">[</span><span class="n">ix</span><span class="p">]))</span>
<span class="n">denominator</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">for</span> <span class="n">aset</span> <span class="ow">in</span> <span class="n">affected_sets</span><span class="p">:</span>
<span class="n">ix</span> <span class="o">=</span> <span class="n">aset</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">fs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span>
<span class="n">tdisp</span> <span class="o">=</span> <span class="n">perturb</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span>
<span class="k">if</span> <span class="n">fs</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">numerator</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">fs</span><span class="p">]</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">tdisp</span><span class="p">)</span> <span class="o">*</span> <span class="n">aset</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">fuzzy_set</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">fs</span><span class="p">]</span>
<span class="n">numerator</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">fuzzy_set</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="n">tdisp</span><span class="p">)</span> <span class="o">*</span> <span class="n">aset</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="n">denominator</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">aset</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="k">if</span> <span class="nb">sum</span><span class="p">(</span><span class="n">denominator</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">pto</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">numerator</span><span class="p">)</span> <span class="o">/</span> <span class="nb">sum</span><span class="p">(</span><span class="n">denominator</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">pto</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">numerator</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">pto</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;conditional&#39;</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">no_update</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pto</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">inputs</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">inputs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">inputs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="NonStationaryFTS.forecast_interval"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.nsfts.NonStationaryFTS.forecast_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">time_displacement</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;time_displacement&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="n">window_size</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;window_size&quot;</span><span class="p">,</span> <span class="mi">1</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">ndata</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</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="c1"># print(&quot;input: &quot; + str(ndata[k]))</span>
<span class="n">tdisp</span> <span class="o">=</span> <span class="n">common</span><span class="o">.</span><span class="n">window_index</span><span class="p">(</span><span class="n">k</span> <span class="o">+</span> <span class="n">time_displacement</span><span class="p">,</span> <span class="n">window_size</span><span class="p">)</span>
<span class="n">affected_sets</span> <span class="o">=</span> <span class="p">[[</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">key</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">tdisp</span><span class="p">)]</span>
<span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">tdisp</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">]</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">affected_sets</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">affected_sets</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">common</span><span class="o">.</span><span class="n">check_bounds</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="p">,</span> <span class="n">tdisp</span><span class="p">),</span> <span class="mf">1.0</span><span class="p">])</span>
<span class="n">upper</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">lower</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">affected_sets</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">aset</span> <span class="o">=</span> <span class="n">affected_sets</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="k">if</span> <span class="n">aset</span><span class="o">.</span><span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">lower</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">aset</span><span class="o">.</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="n">tdisp</span><span class="p">))</span>
<span class="n">upper</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">aset</span><span class="o">.</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="n">tdisp</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">lower</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">aset</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="n">tdisp</span><span class="p">))</span>
<span class="n">upper</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">aset</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="n">tdisp</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">for</span> <span class="n">aset</span> <span class="ow">in</span> <span class="n">affected_sets</span><span class="p">:</span>
<span class="k">if</span> <span class="n">aset</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">lower</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">aset</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="n">tdisp</span><span class="p">)</span> <span class="o">*</span> <span class="n">aset</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="n">upper</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">aset</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="n">tdisp</span><span class="p">)</span> <span class="o">*</span> <span class="n">aset</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">lower</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">aset</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="n">tdisp</span><span class="p">)</span> <span class="o">*</span> <span class="n">aset</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="n">upper</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">aset</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="n">tdisp</span><span class="p">)</span> <span class="o">*</span> <span class="n">aset</span><span class="p">[</span><span class="mi">1</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="nb">sum</span><span class="p">(</span><span class="n">lower</span><span class="p">),</span> <span class="nb">sum</span><span class="p">(</span><span class="n">upper</span><span class="p">)])</span>
<span class="k">return</span> <span class="n">ret</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">+</span> <span class="s2">&quot;:</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="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{0}{1}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">r</span><span class="p">]))</span>
<span class="k">return</span> <span class="n">tmp</span></div>
<div class="viewcode-block" id="WeightedNonStationaryFTS"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFTS">[docs]</a><span class="k">class</span> <span class="nc">WeightedNonStationaryFTS</span><span class="p">(</span><span class="n">NonStationaryFTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Weighted NonStationaryFTS Fuzzy Time Series&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">WeightedNonStationaryFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Weighted Non Stationary FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;WNSFTS&quot;</span>
<div class="viewcode-block" id="WeightedNonStationaryFTS.train"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;unconditional&#39;</span><span class="p">:</span>
<span class="n">window_size</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;parameters&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">tmpdata</span> <span class="o">=</span> <span class="n">common</span><span class="o">.</span><span class="n">fuzzySeries</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">,</span>
<span class="n">window_size</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;fuzzy&#39;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">tmpdata</span> <span class="o">=</span> <span class="n">common</span><span class="o">.</span><span class="n">fuzzySeries</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">,</span>
<span class="n">method</span><span class="o">=</span><span class="s1">&#39;fuzzy&#39;</span><span class="p">,</span> <span class="n">const_t</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_recurrent_flrs</span><span class="p">(</span><span class="n">tmpdata</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg</span><span class="p">(</span><span class="n">flrs</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;conditional&#39;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span> <span class="o">=</span> <span class="bp">self</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">no_update</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">residuals</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="n">data</span><span class="p">[</span><span class="mi">1</span><span class="p">:])</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="bp">self</span><span class="o">.</span><span class="n">forecasts</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">variance_residual</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="p">)</span> <span class="c1"># np.max(self.residuals</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mean_residual</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">residuals</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">residuals</span><span class="p">[</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">memory_window</span><span class="p">:]</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecasts</span><span class="p">[</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">memory_window</span><span class="p">:]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">inputs</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="n">data</span><span class="p">[</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">memory_window</span><span class="p">:])</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span></div>
<div class="viewcode-block" id="WeightedNonStationaryFTS.generate_flrg"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFTS.generate_flrg">[docs]</a> <span class="k">def</span> <span class="nf">generate_flrg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrs</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">for</span> <span class="n">flr</span> <span class="ow">in</span> <span class="n">flrs</span><span class="p">:</span>
<span class="k">if</span> <span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</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="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">WeightedNonStationaryFLRG</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="o">.</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">name</span><span class="p">)</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.nonstationary.nsfts</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,194 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.nonstationary.util &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
<script src="../../../../_static/jquery.js"></script>
<script src="../../../../_static/underscore.js"></script>
<script src="../../../../_static/doctools.js"></script>
<script src="../../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.nonstationary.util</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.nonstationary.util</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</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.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">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">Membership</span><span class="p">,</span> <span class="n">Util</span>
<div class="viewcode-block" id="plot_sets"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.util.plot_sets">[docs]</a><span class="k">def</span> <span class="nf">plot_sets</span><span class="p">(</span><span class="n">partitioner</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">end</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">step</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">tam</span><span class="o">=</span><span class="p">[</span><span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">],</span> <span class="n">colors</span><span class="o">=</span><span class="kc">None</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">axes</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">window_size</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span> <span class="n">only_lines</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">legend</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="nb">range</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">start</span><span class="p">,</span><span class="n">end</span><span class="p">,</span><span class="n">step</span><span class="p">)</span>
<span class="n">ticks</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="n">axes</span> <span class="ow">is</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">1</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="n">tam</span><span class="p">)</span>
<span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">):</span>
<span class="n">fset</span> <span class="o">=</span> <span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">only_lines</span><span class="p">:</span>
<span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">:</span>
<span class="n">tdisp</span> <span class="o">=</span> <span class="n">t</span> <span class="o">-</span> <span class="p">(</span><span class="n">t</span> <span class="o">%</span> <span class="n">window_size</span><span class="p">)</span>
<span class="n">fset</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">tdisp</span><span class="p">)</span>
<span class="n">param</span> <span class="o">=</span> <span class="n">fset</span><span class="o">.</span><span class="n">perturbated_parameters</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">tdisp</span><span class="p">)]</span>
<span class="k">if</span> <span class="n">fset</span><span class="o">.</span><span class="n">mf</span> <span class="o">==</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trimf</span><span class="p">:</span>
<span class="k">if</span> <span class="n">t</span> <span class="o">==</span> <span class="n">start</span><span class="p">:</span>
<span class="n">line</span> <span class="o">=</span> <span class="n">axes</span><span class="o">.</span><span class="n">plot</span><span class="p">([</span><span class="n">t</span><span class="p">,</span> <span class="n">t</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="n">t</span><span class="p">],</span> <span class="n">param</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">fset</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="n">fset</span><span class="o">.</span><span class="n">metadata</span><span class="p">[</span><span class="s1">&#39;color&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">get_color</span><span class="p">()</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">axes</span><span class="o">.</span><span class="n">plot</span><span class="p">([</span><span class="n">t</span><span class="p">,</span> <span class="n">t</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">t</span><span class="p">],</span> <span class="n">param</span><span class="p">,</span><span class="n">c</span><span class="o">=</span><span class="n">fset</span><span class="o">.</span><span class="n">metadata</span><span class="p">[</span><span class="s1">&#39;color&#39;</span><span class="p">])</span>
<span class="n">ticks</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;t+&quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">t</span><span class="p">),</span><span class="s2">&quot;&quot;</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">:</span>
<span class="n">tdisp</span> <span class="o">=</span> <span class="n">t</span> <span class="o">-</span> <span class="p">(</span><span class="n">t</span> <span class="o">%</span> <span class="n">window_size</span><span class="p">)</span>
<span class="n">fset</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">tdisp</span><span class="p">)</span>
<span class="n">param</span> <span class="o">=</span> <span class="n">fset</span><span class="o">.</span><span class="n">perturbated_parameters</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">tdisp</span><span class="p">)]</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">polyval</span><span class="p">(</span><span class="n">param</span><span class="p">,</span> <span class="n">tdisp</span><span class="p">))</span>
<span class="n">axes</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="nb">range</span><span class="p">,</span> <span class="n">tmp</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">c</span><span class="o">=</span><span class="s2">&quot;blue&quot;</span><span class="p">)</span>
<span class="n">axes</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s2">&quot;Universe of Discourse&quot;</span><span class="p">)</span>
<span class="n">axes</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s2">&quot;Time&quot;</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">xticks</span><span class="p">([</span><span class="n">k</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="n">ticks</span><span class="p">,</span> <span class="n">rotation</span><span class="o">=</span><span class="s1">&#39;vertical&#39;</span><span class="p">)</span>
<span class="k">if</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="o">=</span> <span class="n">axes</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">axes</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="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">axes</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">start</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="mi">1</span><span class="p">),</span> <span class="n">data</span><span class="p">,</span><span class="n">c</span><span class="o">=</span><span class="s2">&quot;black&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">file</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</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">Util</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>
<div class="viewcode-block" id="plot_sets_conditional"><a class="viewcode-back" href="../../../../pyFTS.models.nonstationary.html#pyFTS.models.nonstationary.util.plot_sets_conditional">[docs]</a><span class="k">def</span> <span class="nf">plot_sets_conditional</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">step</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">[</span><span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">],</span> <span class="n">colors</span><span class="o">=</span><span class="kc">None</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">axes</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">fig</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="nb">range</span> <span class="o">=</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="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">),</span> <span class="n">step</span><span class="p">)</span>
<span class="n">ticks</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="n">axes</span> <span class="ow">is</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">1</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="n">size</span><span class="p">)</span>
<span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">:</span>
<span class="n">model</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">t</span><span class="p">]])</span>
<span class="n">perturb</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">conditional_perturbation_factors</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">t</span><span class="p">])</span>
<span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span><span class="p">):</span>
<span class="nb">set</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
<span class="nb">set</span><span class="o">.</span><span class="n">perturbate_parameters</span><span class="p">(</span><span class="n">perturb</span><span class="p">[</span><span class="n">ct</span><span class="p">])</span>
<span class="n">param</span> <span class="o">=</span> <span class="nb">set</span><span class="o">.</span><span class="n">perturbated_parameters</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">perturb</span><span class="p">[</span><span class="n">ct</span><span class="p">])]</span>
<span class="k">if</span> <span class="nb">set</span><span class="o">.</span><span class="n">mf</span> <span class="o">==</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trimf</span><span class="p">:</span>
<span class="k">if</span> <span class="n">t</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">line</span> <span class="o">=</span> <span class="n">axes</span><span class="o">.</span><span class="n">plot</span><span class="p">([</span><span class="n">t</span><span class="p">,</span> <span class="n">t</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="n">t</span><span class="p">],</span> <span class="n">param</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="nb">set</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="nb">set</span><span class="o">.</span><span class="n">metadata</span><span class="p">[</span><span class="s1">&#39;color&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">get_color</span><span class="p">()</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">axes</span><span class="o">.</span><span class="n">plot</span><span class="p">([</span><span class="n">t</span><span class="p">,</span> <span class="n">t</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">t</span><span class="p">],</span> <span class="n">param</span><span class="p">,</span><span class="n">c</span><span class="o">=</span><span class="nb">set</span><span class="o">.</span><span class="n">metadata</span><span class="p">[</span><span class="s1">&#39;color&#39;</span><span class="p">])</span>
<span class="c1">#ticks.extend([&quot;t+&quot;+str(t),&quot;&quot;])</span>
<span class="n">axes</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s2">&quot;Universe of Discourse&quot;</span><span class="p">)</span>
<span class="n">axes</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s2">&quot;Time&quot;</span><span class="p">)</span>
<span class="c1">#plt.xticks([k for k in range], ticks, rotation=&#39;vertical&#39;)</span>
<span class="n">handles0</span><span class="p">,</span> <span class="n">labels0</span> <span class="o">=</span> <span class="n">axes</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">axes</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="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">axes</span><span class="o">.</span><span class="n">plot</span><span class="p">(</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="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">),</span> <span class="mi">1</span><span class="p">),</span> <span class="n">data</span><span class="p">,</span><span class="n">c</span><span class="o">=</span><span class="s2">&quot;black&quot;</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">Util</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 class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.nonstationary.util</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,794 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.pwfts &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.pwfts</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.pwfts</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/python</span>
<span class="c1"># -*- coding: utf8 -*-</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">import</span> <span class="nn">math</span>
<span class="kn">from</span> <span class="nn">operator</span> <span class="kn">import</span> <span class="n">itemgetter</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">FLR</span><span class="p">,</span> <span class="n">FuzzySet</span>
<span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="kn">import</span> <span class="n">hofts</span><span class="p">,</span> <span class="n">ifts</span>
<span class="kn">from</span> <span class="nn">pyFTS.probabilistic</span> <span class="kn">import</span> <span class="n">ProbabilityDistribution</span>
<span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">product</span>
<div class="viewcode-block" id="ProbabilisticWeightedFLRG"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFLRG">[docs]</a><span class="k">class</span> <span class="nc">ProbabilisticWeightedFLRG</span><span class="p">(</span><span class="n">hofts</span><span class="o">.</span><span class="n">HighOrderFLRG</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;High Order Probabilistic Weighted Fuzzy Logical Relationship Group&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">order</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">ProbabilisticWeightedFLRG</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">order</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">frequency_count</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">Z</span> <span class="o">=</span> <span class="kc">None</span>
<div class="viewcode-block" id="ProbabilisticWeightedFLRG.get_membership"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFLRG.get_membership">[docs]</a> <span class="k">def</span> <span class="nf">get_membership</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">sets</span><span class="p">):</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</span><span class="p">,</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="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">,</span> <span class="nb">set</span><span class="p">)):</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nanprod</span><span class="p">([</span><span class="n">sets</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">count</span><span class="p">])</span>
<span class="k">for</span> <span class="n">count</span><span class="p">,</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">LHS</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">else</span><span class="p">:</span>
<span class="k">return</span> <span class="n">sets</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">data</span><span class="p">)</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFLRG.append_rhs"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFLRG.append_rhs">[docs]</a> <span class="k">def</span> <span class="nf">append_rhs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">count</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;count&#39;</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">frequency_count</span> <span class="o">+=</span> <span class="n">count</span>
<span class="k">if</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">+=</span> <span class="n">count</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">=</span> <span class="n">count</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFLRG.lhs_conditional_probability"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFLRG.lhs_conditional_probability">[docs]</a> <span class="k">def</span> <span class="nf">lhs_conditional_probability</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">sets</span><span class="p">,</span> <span class="n">norm</span><span class="p">,</span> <span class="n">uod</span><span class="p">,</span> <span class="n">nbins</span><span class="p">):</span>
<span class="n">pk</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">frequency_count</span> <span class="o">/</span> <span class="n">norm</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">pk</span> <span class="o">*</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_membership</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">sets</span><span class="p">)</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">partition_function</span><span class="p">(</span><span class="n">sets</span><span class="p">,</span> <span class="n">uod</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="n">nbins</span><span class="p">))</span>
<span class="k">return</span> <span class="n">tmp</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFLRG.lhs_conditional_probability_fuzzyfied"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFLRG.lhs_conditional_probability_fuzzyfied">[docs]</a> <span class="k">def</span> <span class="nf">lhs_conditional_probability_fuzzyfied</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lhs_mv</span><span class="p">,</span> <span class="n">sets</span><span class="p">,</span> <span class="n">norm</span><span class="p">,</span> <span class="n">uod</span><span class="p">,</span> <span class="n">nbins</span><span class="p">):</span>
<span class="n">pk</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">frequency_count</span> <span class="o">/</span> <span class="n">norm</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">pk</span> <span class="o">*</span> <span class="p">(</span><span class="n">lhs_mv</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">partition_function</span><span class="p">(</span><span class="n">sets</span><span class="p">,</span> <span class="n">uod</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="n">nbins</span><span class="p">))</span>
<span class="k">return</span> <span class="n">tmp</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFLRG.rhs_unconditional_probability"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFLRG.rhs_unconditional_probability">[docs]</a> <span class="k">def</span> <span class="nf">rhs_unconditional_probability</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">frequency_count</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFLRG.rhs_conditional_probability"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFLRG.rhs_conditional_probability">[docs]</a> <span class="k">def</span> <span class="nf">rhs_conditional_probability</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">sets</span><span class="p">,</span> <span class="n">uod</span><span class="p">,</span> <span class="n">nbins</span><span class="p">):</span>
<span class="n">total</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="k">for</span> <span class="n">rhs</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="nb">set</span> <span class="o">=</span> <span class="n">sets</span><span class="p">[</span><span class="n">rhs</span><span class="p">]</span>
<span class="n">wi</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">rhs_unconditional_probability</span><span class="p">(</span><span class="n">rhs</span><span class="p">)</span>
<span class="n">mv</span> <span class="o">=</span> <span class="nb">set</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">/</span> <span class="nb">set</span><span class="o">.</span><span class="n">partition_function</span><span class="p">(</span><span class="n">uod</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="n">nbins</span><span class="p">)</span>
<span class="n">total</span> <span class="o">+=</span> <span class="n">wi</span> <span class="o">*</span> <span class="n">mv</span>
<span class="k">return</span> <span class="n">total</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFLRG.partition_function"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFLRG.partition_function">[docs]</a> <span class="k">def</span> <span class="nf">partition_function</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sets</span><span class="p">,</span> <span class="n">uod</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">100</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">Z</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">Z</span> <span class="o">=</span> <span class="mf">0.0</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">linspace</span><span class="p">(</span><span class="n">uod</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">uod</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">nbins</span><span class="p">):</span>
<span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">LHS</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">Z</span> <span class="o">+=</span> <span class="n">sets</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">Z</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFLRG.get_midpoint"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFLRG.get_midpoint">[docs]</a> <span class="k">def</span> <span class="nf">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sets</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Return the expectation of the PWFLRG, the weighted sum&#39;&#39;&#39;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">midpoint</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">midpoint</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</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="bp">self</span><span class="o">.</span><span class="n">rhs_unconditional_probability</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="o">*</span> <span class="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span>
<span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()]))</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">midpoint</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFLRG.get_upper"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFLRG.get_upper">[docs]</a> <span class="k">def</span> <span class="nf">get_upper</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sets</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">upper</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">upper</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</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="bp">self</span><span class="o">.</span><span class="n">rhs_unconditional_probability</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="o">*</span> <span class="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span>
<span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()]))</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">upper</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFLRG.get_lower"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFLRG.get_lower">[docs]</a> <span class="k">def</span> <span class="nf">get_lower</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sets</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">lower</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">lower</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</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="bp">self</span><span class="o">.</span><span class="n">rhs_unconditional_probability</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="o">*</span> <span class="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span>
<span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()]))</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">lower</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">tmp2</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="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">()):</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">tmp2</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">tmp2</span> <span class="o">=</span> <span class="n">tmp2</span> <span class="o">+</span> <span class="s2">&quot;, &quot;</span>
<span class="n">tmp2</span> <span class="o">=</span> <span class="n">tmp2</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="nb">round</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">frequency_count</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span> <span class="o">+</span> <span class="s2">&quot;)&quot;</span> <span class="o">+</span> <span class="n">c</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="o">+</span> <span class="s2">&quot; -&gt; &quot;</span> <span class="o">+</span> <span class="n">tmp2</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS">[docs]</a><span class="k">class</span> <span class="nc">ProbabilisticWeightedFTS</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="sd">&quot;&quot;&quot;High Order Probabilistic Weighted Fuzzy Time Series&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">ProbabilisticWeightedFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;PWFTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Probabilistic FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;Silva, P.; Guimarães, F.; Sadaei, H.&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">global_frequency_count</span> <span class="o">=</span> <span class="mi">0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_point_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_interval_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_probability_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_order</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">auto_update</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;update&#39;</span><span class="p">,</span><span class="kc">False</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">configure_lags</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.train"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">configure_lags</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="ow">not</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;fuzzyfied&#39;</span><span class="p">,</span><span class="kc">False</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg2</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg_fuzzyfied</span><span class="p">(</span><span class="n">data</span><span class="p">)</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.generate_flrg2"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.generate_flrg2">[docs]</a> <span class="k">def</span> <span class="nf">generate_flrg2</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="n">fuzz</span> <span class="o">=</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">data</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">fuzz</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">fuzzyfy</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;both&#39;</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;fuzzy&#39;</span><span class="p">,</span>
<span class="n">alpha_cut</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">alpha_cut</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg_fuzzyfied</span><span class="p">(</span><span class="n">fuzz</span><span class="p">)</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.generate_flrg_fuzzyfied"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.generate_flrg_fuzzyfied">[docs]</a> <span class="k">def</span> <span class="nf">generate_flrg_fuzzyfied</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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">data</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="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">set_sample</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">instance</span> <span class="ow">in</span> <span class="n">sample</span><span class="p">:</span>
<span class="n">set_sample</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">k</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">instance</span><span class="p">])</span>
<span class="n">flrgs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_lhs_flrg_fuzzyfied</span><span class="p">(</span><span class="n">set_sample</span><span class="p">)</span>
<span class="k">for</span> <span class="n">flrg</span> <span class="ow">in</span> <span class="n">flrgs</span><span class="p">:</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span> <span class="o">=</span> <span class="n">flrg</span><span class="p">;</span>
<span class="n">lhs_mv</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pwflrg_lhs_memberhip_fuzzyfied</span><span class="p">(</span><span class="n">flrg</span><span class="p">,</span> <span class="n">sample</span><span class="p">)</span>
<span class="n">mvs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">inst</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>
<span class="k">for</span> <span class="nb">set</span><span class="p">,</span> <span class="n">mv</span> <span class="ow">in</span> <span class="n">inst</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="nb">set</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="n">lhs_mv</span> <span class="o">*</span> <span class="n">mv</span><span class="p">)</span>
<span class="n">mvs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mv</span><span class="p">)</span>
<span class="n">tmp_fq</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">([</span><span class="n">lhs_mv</span> <span class="o">*</span> <span class="n">kk</span> <span class="k">for</span> <span class="n">kk</span> <span class="ow">in</span> <span class="n">mvs</span> <span class="k">if</span> <span class="n">kk</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">global_frequency_count</span> <span class="o">+=</span> <span class="n">tmp_fq</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.pwflrg_lhs_memberhip_fuzzyfied"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.pwflrg_lhs_memberhip_fuzzyfied">[docs]</a> <span class="k">def</span> <span class="nf">pwflrg_lhs_memberhip_fuzzyfied</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrg</span><span class="p">,</span> <span class="n">sample</span><span class="p">):</span>
<span class="n">vals</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">ct</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">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">)):</span> <span class="c1"># fuzz in enumerate(sample):</span>
<span class="n">vals</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">mv</span> <span class="k">for</span> <span class="n">fset</span><span class="p">,</span> <span class="n">mv</span> <span class="ow">in</span> <span class="n">sample</span><span class="p">[</span><span class="n">ct</span><span class="p">]</span> <span class="k">if</span> <span class="n">fset</span> <span class="o">==</span> <span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="n">ct</span><span class="p">]])</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nanprod</span><span class="p">(</span><span class="n">vals</span><span class="p">)</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.generate_lhs_flrg"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.generate_lhs_flrg">[docs]</a> <span class="k">def</span> <span class="nf">generate_lhs_flrg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sample</span><span class="p">,</span> <span class="n">explain</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="p">(</span><span class="nb">tuple</span><span class="p">,</span> <span class="nb">list</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">sample</span> <span class="o">=</span> <span class="p">[</span><span class="n">sample</span><span class="p">]</span>
<span class="n">nsample</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">fuzzyfy</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s2">&quot;sets&quot;</span><span class="p">,</span> <span class="n">alpha_cut</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">alpha_cut</span><span class="p">)</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">sample</span><span class="p">]</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_lhs_flrg_fuzzyfied</span><span class="p">(</span><span class="n">nsample</span><span class="p">,</span> <span class="n">explain</span><span class="p">)</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.generate_lhs_flrg_fuzzyfied"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.generate_lhs_flrg_fuzzyfied">[docs]</a> <span class="k">def</span> <span class="nf">generate_lhs_flrg_fuzzyfied</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sample</span><span class="p">,</span> <span class="n">explain</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="n">lags</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">flrgs</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">o</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lags</span><span class="p">):</span>
<span class="n">lhs</span> <span class="o">=</span> <span class="n">sample</span><span class="p">[</span><span class="n">o</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span>
<span class="n">lags</span><span class="o">.</span><span class="n">append</span><span class="p">(</span> <span class="n">lhs</span> <span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\t</span><span class="s2"> (Lag </span><span class="si">{}</span><span class="s2">) </span><span class="si">{}</span><span class="s2"> -&gt; </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">o</span><span class="p">,</span> <span class="n">sample</span><span class="p">[</span><span class="n">o</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="n">lhs</span><span class="p">))</span>
<span class="c1"># Trace the possible paths</span>
<span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">lags</span><span class="p">):</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="n">ProbabilisticWeightedFLRG</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">)</span>
<span class="k">for</span> <span class="n">lhs</span> <span class="ow">in</span> <span class="n">path</span><span class="p">:</span>
<span class="n">flrg</span><span class="o">.</span><span class="n">append_lhs</span><span class="p">(</span><span class="n">lhs</span><span class="p">)</span>
<span class="n">flrgs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">flrg</span><span class="p">)</span>
<span class="k">return</span> <span class="n">flrgs</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.generate_flrg"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.generate_flrg">[docs]</a> <span class="k">def</span> <span class="nf">generate_flrg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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">data</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="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dump</span><span class="p">:</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;FLR: &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">k</span><span class="p">))</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">flrgs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_lhs_flrg</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="k">for</span> <span class="n">flrg</span> <span class="ow">in</span> <span class="n">flrgs</span><span class="p">:</span>
<span class="n">lhs_mv</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_membership</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span> <span class="o">=</span> <span class="n">flrg</span><span class="p">;</span>
<span class="n">fuzzyfied</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">fuzzyfy</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;both&#39;</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;fuzzy&#39;</span><span class="p">,</span>
<span class="n">alpha_cut</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">alpha_cut</span><span class="p">)</span>
<span class="n">mvs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="nb">set</span><span class="p">,</span> <span class="n">mv</span> <span class="ow">in</span> <span class="n">fuzzyfied</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="nb">set</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="n">lhs_mv</span> <span class="o">*</span> <span class="n">mv</span><span class="p">)</span>
<span class="n">mvs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mv</span><span class="p">)</span>
<span class="n">tmp_fq</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">([</span><span class="n">lhs_mv</span><span class="o">*</span><span class="n">kk</span> <span class="k">for</span> <span class="n">kk</span> <span class="ow">in</span> <span class="n">mvs</span> <span class="k">if</span> <span class="n">kk</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">global_frequency_count</span> <span class="o">+=</span> <span class="n">tmp_fq</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.update_model"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.update_model">[docs]</a> <span class="k">def</span> <span class="nf">update_model</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">data</span><span class="p">):</span>
<span class="k">pass</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.add_new_PWFLGR"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.add_new_PWFLGR">[docs]</a> <span class="k">def</span> <span class="nf">add_new_PWFLGR</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrg</span><span class="p">):</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">ProbabilisticWeightedFLRG</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="p">)</span>
<span class="k">for</span> <span class="n">fs</span> <span class="ow">in</span> <span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">:</span> <span class="n">tmp</span><span class="o">.</span><span class="n">append_lhs</span><span class="p">(</span><span class="n">fs</span><span class="p">)</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">tmp</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span> <span class="o">=</span> <span class="n">tmp</span><span class="p">;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">global_frequency_count</span> <span class="o">+=</span> <span class="mi">1</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.flrg_lhs_unconditional_probability"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.flrg_lhs_unconditional_probability">[docs]</a> <span class="k">def</span> <span class="nf">flrg_lhs_unconditional_probability</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrg</span><span class="p">):</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span><span class="o">.</span><span class="n">frequency_count</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">global_frequency_count</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="mf">1.0</span></div>
<span class="c1">#self.add_new_PWFLGR(flrg)</span>
<span class="c1">#return self.flrg_lhs_unconditional_probability(flrg)</span>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.flrg_lhs_conditional_probability"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.flrg_lhs_conditional_probability">[docs]</a> <span class="k">def</span> <span class="nf">flrg_lhs_conditional_probability</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">flrg</span><span class="p">):</span>
<span class="n">mv</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_membership</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">pb</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrg_lhs_unconditional_probability</span><span class="p">(</span><span class="n">flrg</span><span class="p">)</span>
<span class="k">return</span> <span class="n">mv</span> <span class="o">*</span> <span class="n">pb</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.flrg_lhs_conditional_probability_fuzzyfied"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.flrg_lhs_conditional_probability_fuzzyfied">[docs]</a> <span class="k">def</span> <span class="nf">flrg_lhs_conditional_probability_fuzzyfied</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">flrg</span><span class="p">):</span>
<span class="n">mv</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pwflrg_lhs_memberhip_fuzzyfied</span><span class="p">(</span><span class="n">flrg</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="n">pb</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrg_lhs_unconditional_probability</span><span class="p">(</span><span class="n">flrg</span><span class="p">)</span>
<span class="k">return</span> <span class="n">mv</span> <span class="o">*</span> <span class="n">pb</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.get_midpoint"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.get_midpoint">[docs]</a> <span class="k">def</span> <span class="nf">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrg</span><span class="p">):</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">tmp</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span> <span class="c1">#sum(np.array([tmp.rhs_unconditional_probability(s) * self.setsDict[s].centroid for s in tmp.RHS]))</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">pi</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</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">pi</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">]))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.flrg_rhs_conditional_probability"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.flrg_rhs_conditional_probability">[docs]</a> <span class="k">def</span> <span class="nf">flrg_rhs_conditional_probability</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">flrg</span><span class="p">):</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">_flrg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span>
<span class="n">cond</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">_flrg</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="n">_set</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">_flrg</span><span class="o">.</span><span class="n">rhs_unconditional_probability</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">_set</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">/</span> <span class="n">_set</span><span class="o">.</span><span class="n">partition_function</span><span class="p">(</span><span class="n">uod</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">get_UoD</span><span class="p">()))</span>
<span class="n">cond</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</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">cond</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">pi</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</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">pi</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">]))</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.get_upper"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.get_upper">[docs]</a> <span class="k">def</span> <span class="nf">get_upper</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrg</span><span class="p">):</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">tmp</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.get_lower"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.get_lower">[docs]</a> <span class="k">def</span> <span class="nf">get_lower</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrg</span><span class="p">):</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">tmp</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.forecast"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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="s1">&#39;heuristic&#39;</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">data</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span>
<span class="n">ret</span> <span class="o">=</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="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="k">if</span> <span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;heuristic&#39;</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="bp">self</span><span class="o">.</span><span class="n">point_heuristic</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">))</span>
<span class="k">elif</span> <span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;expected_value&#39;</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="bp">self</span><span class="o">.</span><span class="n">point_expected_value</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">))</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;Unknown point forecasting method!&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">auto_update</span> <span class="ow">and</span> <span class="n">k</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span><span class="o">+</span><span class="mi">1</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">update_model</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="o">-</span> <span class="mi">1</span> <span class="p">:</span> <span class="n">k</span><span class="p">])</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.point_heuristic"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.point_heuristic">[docs]</a> <span class="k">def</span> <span class="nf">point_heuristic</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sample</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">explain</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;explain&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="n">fuzzyfied</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;fuzzyfied&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Fuzzyfication </span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">fuzzyfied</span><span class="p">:</span>
<span class="n">flrgs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_lhs_flrg</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">explain</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">fsets</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_sets_from_both_fuzzyfication</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="n">flrgs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_lhs_flrg_fuzzyfied</span><span class="p">(</span><span class="n">fsets</span><span class="p">,</span> <span class="n">explain</span><span class="p">)</span>
<span class="n">mp</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">norms</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Rules:</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">flrg</span> <span class="ow">in</span> <span class="n">flrgs</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">fuzzyfied</span><span class="p">:</span>
<span class="n">norm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrg_lhs_conditional_probability</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">flrg</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">norm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrg_lhs_conditional_probability_fuzzyfied</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">flrg</span><span class="p">)</span>
<span class="k">if</span> <span class="n">norm</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">norm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrg_lhs_unconditional_probability</span><span class="p">(</span><span class="n">flrg</span><span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\t</span><span class="s2"> </span><span class="si">{}</span><span class="s2"> </span><span class="se">\t</span><span class="s2"> Midpoint: </span><span class="si">{}</span><span class="se">\t</span><span class="s2"> Norm: </span><span class="si">{}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]),</span>
<span class="bp">self</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="n">flrg</span><span class="p">),</span> <span class="n">norm</span><span class="p">))</span>
<span class="n">mp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">norm</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="n">flrg</span><span class="p">))</span>
<span class="n">norms</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">norm</span><span class="p">)</span>
<span class="n">norm</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">norms</span><span class="p">)</span>
<span class="n">final</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">mp</span><span class="p">)</span> <span class="o">/</span> <span class="n">norm</span> <span class="k">if</span> <span class="n">norm</span> <span class="o">!=</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Deffuzyfied value: </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">final</span><span class="p">))</span>
<span class="k">return</span> <span class="n">final</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.get_sets_from_both_fuzzyfication"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.get_sets_from_both_fuzzyfication">[docs]</a> <span class="k">def</span> <span class="nf">get_sets_from_both_fuzzyfication</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sample</span><span class="p">):</span>
<span class="k">return</span> <span class="p">[[</span><span class="n">k</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">inst</span><span class="p">]</span> <span class="k">for</span> <span class="n">inst</span> <span class="ow">in</span> <span class="n">sample</span><span class="p">]</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.point_expected_value"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.point_expected_value">[docs]</a> <span class="k">def</span> <span class="nf">point_expected_value</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sample</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">explain</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;explain&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="n">dist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_distribution</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">final</span> <span class="o">=</span> <span class="n">dist</span><span class="o">.</span><span class="n">expected_value</span><span class="p">()</span>
<span class="k">return</span> <span class="n">final</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.forecast_interval"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.forecast_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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="s1">&#39;heuristic&#39;</span><span class="p">)</span>
<span class="n">alpha</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;alpha&#39;</span><span class="p">,</span> <span class="mf">0.05</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">ndata</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</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="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">ndata</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">-</span> <span class="mi">1</span><span class="p">):</span> <span class="n">k</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span>
<span class="k">if</span> <span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;heuristic&#39;</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="bp">self</span><span class="o">.</span><span class="n">interval_heuristic</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">))</span>
<span class="k">elif</span> <span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;quantile&#39;</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="bp">self</span><span class="o">.</span><span class="n">interval_quantile</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">alpha</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">))</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;Unknown interval forecasting method!&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.interval_quantile"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.interval_quantile">[docs]</a> <span class="k">def</span> <span class="nf">interval_quantile</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="n">alpha</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">dist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_distribution</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">itvl</span> <span class="o">=</span> <span class="n">dist</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">quantile</span><span class="p">([</span><span class="n">alpha</span><span class="p">,</span> <span class="mf">1.0</span> <span class="o">-</span> <span class="n">alpha</span><span class="p">])</span>
<span class="k">return</span> <span class="n">itvl</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.interval_heuristic"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.interval_heuristic">[docs]</a> <span class="k">def</span> <span class="nf">interval_heuristic</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sample</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">fuzzyfied</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;fuzzyfied&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">fuzzyfied</span><span class="p">:</span>
<span class="n">flrgs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_lhs_flrg</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">fsets</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_sets_from_both_fuzzyfication</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="n">flrgs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_lhs_flrg_fuzzyfied</span><span class="p">(</span><span class="n">fsets</span><span class="p">)</span>
<span class="n">up</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">lo</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">norms</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">flrg</span> <span class="ow">in</span> <span class="n">flrgs</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">fuzzyfied</span><span class="p">:</span>
<span class="n">norm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrg_lhs_conditional_probability</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">flrg</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">norm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrg_lhs_conditional_probability_fuzzyfied</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">flrg</span><span class="p">)</span>
<span class="k">if</span> <span class="n">norm</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">norm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrg_lhs_unconditional_probability</span><span class="p">(</span><span class="n">flrg</span><span class="p">)</span>
<span class="n">up</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">norm</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="n">flrg</span><span class="p">))</span>
<span class="n">lo</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">norm</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="n">flrg</span><span class="p">))</span>
<span class="n">norms</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">norm</span><span class="p">)</span>
<span class="c1"># gerar o intervalo</span>
<span class="n">norm</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">norms</span><span class="p">)</span>
<span class="k">if</span> <span class="n">norm</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">return</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="k">else</span><span class="p">:</span>
<span class="n">lo_</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">lo</span><span class="p">)</span> <span class="o">/</span> <span class="n">norm</span>
<span class="n">up_</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">up</span><span class="p">)</span> <span class="o">/</span> <span class="n">norm</span>
<span class="k">return</span> <span class="p">[</span><span class="n">lo_</span><span class="p">,</span> <span class="n">up_</span><span class="p">]</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.forecast_distribution"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.forecast_distribution">[docs]</a> <span class="k">def</span> <span class="nf">forecast_distribution</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">smooth</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;smooth&quot;</span><span class="p">,</span> <span class="s2">&quot;none&quot;</span><span class="p">)</span>
<span class="n">from_distribution</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;from_distribution&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="n">fuzzyfied</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;fuzzyfied&#39;</span><span class="p">,</span> <span class="kc">False</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">ndata</span><span class="p">)</span>
<span class="n">uod</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_UoD</span><span class="p">()</span>
<span class="k">if</span> <span class="s1">&#39;bins&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="n">_bins</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;bins&#39;</span><span class="p">)</span>
<span class="n">nbins</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">_bins</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">nbins</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;num_bins&quot;</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
<span class="n">_bins</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="n">uod</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">uod</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">nbins</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</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="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">ndata</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">-</span> <span class="mi">1</span><span class="p">):</span> <span class="n">k</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span>
<span class="k">if</span> <span class="n">from_distribution</span><span class="p">:</span>
<span class="n">dist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_distribution_from_distribution</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span><span class="n">smooth</span><span class="p">,</span><span class="n">uod</span><span class="p">,</span><span class="n">_bins</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">fuzzyfied</span><span class="p">:</span>
<span class="n">flrgs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_lhs_flrg</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">fsets</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_sets_from_both_fuzzyfication</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="n">flrgs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_lhs_flrg_fuzzyfied</span><span class="p">(</span><span class="n">fsets</span><span class="p">)</span>
<span class="k">if</span> <span class="s1">&#39;type&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;type&#39;</span><span class="p">)</span>
<span class="n">dist</span> <span class="o">=</span> <span class="n">ProbabilityDistribution</span><span class="o">.</span><span class="n">ProbabilityDistribution</span><span class="p">(</span><span class="n">smooth</span><span class="p">,</span> <span class="n">uod</span><span class="o">=</span><span class="n">uod</span><span class="p">,</span> <span class="n">bins</span><span class="o">=</span><span class="n">_bins</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="k">for</span> <span class="nb">bin</span> <span class="ow">in</span> <span class="n">_bins</span><span class="p">:</span>
<span class="n">num</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">den</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">flrgs</span><span class="p">:</span>
<span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span>
<span class="n">wi</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">rhs_conditional_probability</span><span class="p">(</span><span class="nb">bin</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">uod</span><span class="p">,</span> <span class="n">nbins</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">fuzzyfied</span><span class="p">:</span>
<span class="n">pk</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">lhs_conditional_probability</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">global_frequency_count</span><span class="p">,</span> <span class="n">uod</span><span class="p">,</span> <span class="n">nbins</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">lhs_mv</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pwflrg_lhs_memberhip_fuzzyfied</span><span class="p">(</span><span class="n">flrg</span><span class="p">,</span> <span class="n">sample</span><span class="p">)</span>
<span class="n">pk</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">lhs_conditional_probability_fuzzyfied</span><span class="p">(</span><span class="n">lhs_mv</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">global_frequency_count</span><span class="p">,</span> <span class="n">uod</span><span class="p">,</span> <span class="n">nbins</span><span class="p">)</span>
<span class="n">num</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">wi</span> <span class="o">*</span> <span class="n">pk</span><span class="p">)</span>
<span class="n">den</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pk</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">num</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
<span class="n">den</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.000000001</span><span class="p">)</span>
<span class="n">pf</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">num</span><span class="p">)</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">den</span><span class="p">)</span>
<span class="n">dist</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="nb">bin</span><span class="p">,</span> <span class="n">pf</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">dist</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<span class="k">def</span> <span class="nf">__check_point_bounds</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">point</span><span class="p">):</span>
<span class="n">lower_set</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">lower_set</span><span class="p">()</span>
<span class="n">upper_set</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">upper_set</span><span class="p">()</span>
<span class="k">return</span> <span class="n">point</span> <span class="o">&lt;=</span> <span class="n">lower_set</span><span class="o">.</span><span class="n">lower</span> <span class="ow">or</span> <span class="n">point</span> <span class="o">&gt;=</span> <span class="n">upper_set</span><span class="o">.</span><span class="n">upper</span>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.forecast_ahead"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.forecast_ahead">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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">data</span><span class="p">)</span>
<span class="n">fuzzyfied</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;fuzzyfied&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="n">start</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;start_at&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</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">data</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">start</span><span class="p">:</span> <span class="n">start</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">max_lag</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="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="n">steps</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__check_point_bounds</span><span class="p">(</span><span class="n">ret</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">fuzzyfied</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">ret</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">mp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">ret</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:</span> <span class="n">k</span><span class="p">],</span> <span class="o">**</span><span class="n">kwargs</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">mp</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="k">return</span> <span class="n">ret</span><span class="p">[</span><span class="o">-</span><span class="n">steps</span><span class="p">:]</span></div>
<span class="k">def</span> <span class="nf">__check_interval_bounds</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">interval</span><span class="p">):</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transformations</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">lower_set</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">lower_set</span><span class="p">()</span>
<span class="n">upper_set</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">upper_set</span><span class="p">()</span>
<span class="k">return</span> <span class="n">interval</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">lower_set</span><span class="o">.</span><span class="n">lower</span> <span class="ow">and</span> <span class="n">interval</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">&gt;=</span> <span class="n">upper_set</span><span class="o">.</span><span class="n">upper</span>
<span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transformations</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">return</span> <span class="n">interval</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_min</span> <span class="ow">and</span> <span class="n">interval</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">&gt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">original_max</span>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.forecast_ahead_interval"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.forecast_ahead_interval">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">start</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;start_at&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="k">if</span> <span class="s1">&#39;fuzzyfied&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="n">fuzzyfied</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;fuzzyfied&#39;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">fuzzyfied</span> <span class="o">=</span> <span class="kc">False</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">start</span><span class="p">:</span> <span class="n">start</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">fuzzyfied</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[[</span><span class="n">k</span><span class="p">,</span> <span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">sample</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">sample</span><span class="p">:</span>
<span class="n">kv</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">defuzzyfy</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;both&#39;</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">kv</span><span class="p">,</span> <span class="n">kv</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="bp">self</span><span class="o">.</span><span class="n">forecast_interval</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)[</span><span class="mi">0</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="n">start</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="n">steps</span> <span class="o">+</span> <span class="n">start</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">):</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">__check_interval_bounds</span><span class="p">(</span><span class="n">ret</span><span class="p">[</span><span class="o">-</span><span class="mi">1</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">ret</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">lower</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_interval</span><span class="p">([</span><span class="n">ret</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</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="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="n">k</span><span class="p">)],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">upper</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_interval</span><span class="p">([</span><span class="n">ret</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</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="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="n">k</span><span class="p">)],</span> <span class="o">**</span><span class="n">kwargs</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">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">lower</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">upper</span><span class="p">)])</span>
<span class="k">return</span> <span class="n">ret</span><span class="p">[</span><span class="o">-</span><span class="n">steps</span><span class="p">:]</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.forecast_ahead_distribution"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.forecast_ahead_distribution">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead_distribution</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="s1">&#39;type&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;type&#39;</span><span class="p">)</span>
<span class="n">smooth</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;smooth&quot;</span><span class="p">,</span> <span class="s2">&quot;none&quot;</span><span class="p">)</span>
<span class="n">uod</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_UoD</span><span class="p">()</span>
<span class="k">if</span> <span class="s1">&#39;bins&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="n">_bins</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;bins&#39;</span><span class="p">)</span>
<span class="n">nbins</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">_bins</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">nbins</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;num_bins&quot;</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
<span class="n">_bins</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="n">uod</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">uod</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">nbins</span><span class="p">)</span>
<span class="n">start</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;start_at&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="k">if</span> <span class="s1">&#39;fuzzyfied&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="n">fuzzyfied</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;fuzzyfied&#39;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">fuzzyfied</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">fuzzyfied</span><span class="p">:</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">ndata</span><span class="p">[</span><span class="n">start</span><span class="p">:</span> <span class="n">start</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">sample</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">ndata</span><span class="p">[</span><span class="n">start</span><span class="p">:</span> <span class="n">start</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">]:</span>
<span class="n">kv</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">defuzzyfy</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;both&#39;</span><span class="p">)</span>
<span class="n">sample</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">kv</span><span class="p">)</span>
<span class="k">for</span> <span class="n">dat</span> <span class="ow">in</span> <span class="n">sample</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dat</span><span class="p">,</span> <span class="n">ProbabilityDistribution</span><span class="o">.</span><span class="n">ProbabilityDistribution</span><span class="p">):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">ProbabilityDistribution</span><span class="o">.</span><span class="n">ProbabilityDistribution</span><span class="p">(</span><span class="n">smooth</span><span class="p">,</span> <span class="n">uod</span><span class="o">=</span><span class="n">uod</span><span class="p">,</span> <span class="n">bins</span><span class="o">=</span><span class="n">_bins</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">dat</span><span class="p">,</span> <span class="mf">1.0</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">tmp</span><span class="p">)</span>
<span class="k">else</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">dat</span><span class="p">)</span>
<span class="n">dist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_distribution_from_distribution</span><span class="p">(</span><span class="n">ret</span><span class="p">,</span> <span class="n">smooth</span><span class="p">,</span><span class="n">uod</span><span class="p">,</span><span class="n">_bins</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</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">dist</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="n">start</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">,</span> <span class="n">steps</span> <span class="o">+</span> <span class="n">start</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">):</span>
<span class="n">dist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_distribution_from_distribution</span><span class="p">(</span><span class="n">ret</span><span class="p">[</span><span class="n">k</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="n">smooth</span><span class="p">,</span> <span class="n">uod</span><span class="p">,</span> <span class="n">_bins</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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">dist</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span><span class="p">[</span><span class="o">-</span><span class="n">steps</span><span class="p">:]</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.forecast_distribution_from_distribution"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.forecast_distribution_from_distribution">[docs]</a> <span class="k">def</span> <span class="nf">forecast_distribution_from_distribution</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">previous_dist</span><span class="p">,</span> <span class="n">smooth</span><span class="p">,</span> <span class="n">uod</span><span class="p">,</span> <span class="n">bins</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">dist</span> <span class="o">=</span> <span class="n">ProbabilityDistribution</span><span class="o">.</span><span class="n">ProbabilityDistribution</span><span class="p">(</span><span class="n">smooth</span><span class="p">,</span> <span class="n">uod</span><span class="o">=</span><span class="n">uod</span><span class="p">,</span> <span class="n">bins</span><span class="o">=</span><span class="n">bins</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">lags</span> <span class="o">=</span> <span class="p">[]</span>
<span class="c1"># Find all bins of past distributions with probability greater than zero</span>
<span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">lag</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lags</span><span class="p">):</span>
<span class="n">dd</span> <span class="o">=</span> <span class="n">previous_dist</span><span class="p">[</span><span class="o">-</span><span class="n">lag</span><span class="p">]</span>
<span class="n">vals</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">dd</span><span class="o">.</span><span class="n">bins</span> <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">dd</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">v</span><span class="p">),</span> <span class="mi">4</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">]</span>
<span class="n">lags</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="n">vals</span><span class="p">))</span>
<span class="c1"># Trace all possible combinations between the bins of past distributions</span>
<span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">lags</span><span class="p">):</span>
<span class="c1"># get the combined probabilities for this path</span>
<span class="n">pk</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">prod</span><span class="p">([</span><span class="n">previous_dist</span><span class="p">[</span><span class="o">-</span><span class="n">lag</span><span class="p">]</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">path</span><span class="p">[</span><span class="n">ct</span><span class="p">])</span>
<span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">lag</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lags</span><span class="p">)])</span>
<span class="n">d</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">forecast_distribution</span><span class="p">(</span><span class="n">path</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">for</span> <span class="nb">bin</span> <span class="ow">in</span> <span class="n">bins</span><span class="p">:</span>
<span class="n">dist</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="nb">bin</span><span class="p">,</span> <span class="n">dist</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="nb">bin</span><span class="p">)</span> <span class="o">+</span> <span class="n">pk</span> <span class="o">*</span> <span class="n">d</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="nb">bin</span><span class="p">))</span>
<span class="k">return</span> <span class="n">dist</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">+</span> <span class="s2">&quot;:</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="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="o">.</span><span class="n">keys</span><span class="p">()):</span>
<span class="n">p</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">r</span><span class="p">]</span><span class="o">.</span><span class="n">frequency_count</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">global_frequency_count</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">tmp</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">p</span><span class="p">)</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="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">r</span><span class="p">])</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>
<span class="k">return</span> <span class="n">tmp</span></div>
<div class="viewcode-block" id="visualize_distributions"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.visualize_distributions">[docs]</a><span class="k">def</span> <span class="nf">visualize_distributions</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</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">from</span> <span class="nn">matplotlib</span> <span class="kn">import</span> <span class="n">gridspec</span>
<span class="kn">import</span> <span class="nn">seaborn</span> <span class="k">as</span> <span class="nn">sns</span>
<span class="n">ordered_sets</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span>
<span class="n">ftpg_keys</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">flrgs</span><span class="o">.</span><span class="n">keys</span><span class="p">(),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">model</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">x</span><span class="p">]</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">sets</span><span class="p">))</span>
<span class="n">lhs_probs</span> <span class="o">=</span> <span class="p">[</span><span class="n">model</span><span class="o">.</span><span class="n">flrg_lhs_unconditional_probability</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">ftpg_keys</span><span class="p">]</span>
<span class="n">mat</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="n">ftpg_keys</span><span class="p">),</span> <span class="nb">len</span><span class="p">(</span><span class="n">ordered_sets</span><span class="p">)))</span>
<span class="k">for</span> <span class="n">row</span><span class="p">,</span> <span class="n">w</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">ftpg_keys</span><span class="p">):</span>
<span class="k">for</span> <span class="n">col</span><span class="p">,</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">ordered_sets</span><span class="p">):</span>
<span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">model</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">w</span><span class="p">]</span><span class="o">.</span><span class="n">RHS</span><span class="p">:</span>
<span class="n">mat</span><span class="p">[</span><span class="n">row</span><span class="p">,</span> <span class="n">col</span><span class="p">]</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">w</span><span class="p">]</span><span class="o">.</span><span class="n">rhs_unconditional_probability</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
<span class="n">size</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;size&#39;</span><span class="p">,</span> <span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">10</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">size</span><span class="p">)</span>
<span class="n">gs</span> <span class="o">=</span> <span class="n">gridspec</span><span class="o">.</span><span class="n">GridSpec</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="n">width_ratios</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span>
<span class="n">ax1</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="n">gs</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">sns</span><span class="o">.</span><span class="n">barplot</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&#39;darkblue&#39;</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;x&#39;</span><span class="p">:</span> <span class="n">ftpg_keys</span><span class="p">,</span> <span class="s1">&#39;y&#39;</span><span class="p">:</span> <span class="n">lhs_probs</span><span class="p">},</span> <span class="n">ax</span><span class="o">=</span><span class="n">ax1</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="s2">&quot;LHS Probabilities&quot;</span><span class="p">)</span>
<span class="n">ind_sets</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">ordered_sets</span><span class="p">))</span>
<span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="n">gs</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="n">sns</span><span class="o">.</span><span class="n">heatmap</span><span class="p">(</span><span class="n">mat</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">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span> <span class="n">yticklabels</span><span class="o">=</span><span class="kc">False</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="s2">&quot;RHS probabilities&quot;</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_xticks</span><span class="p">(</span><span class="n">ind_sets</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_xticklabels</span><span class="p">(</span><span class="n">ordered_sets</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">xaxis</span><span class="o">.</span><span class="n">set_tick_params</span><span class="p">(</span><span class="n">rotation</span><span class="o">=</span><span class="mi">90</span><span class="p">)</span></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.pwfts</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,215 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.sadaei &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.sadaei</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.sadaei</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">First Order Exponentialy Weighted Fuzzy Time Series by Sadaei et al. (2013)</span>
<span class="sd">H. J. Sadaei, R. Enayatifar, A. H. Abdullah, and A. Gani, “Short-term load forecasting using a hybrid model with a </span>
<span class="sd">refined exponentially weighted fuzzy time series and an improved harmony search,” Int. J. Electr. Power Energy Syst., vol. 62, no. from 2005, pp. 118129, 2014.</span>
<span class="sd">&quot;&quot;&quot;</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.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span><span class="n">FLR</span><span class="p">,</span><span class="n">fts</span><span class="p">,</span> <span class="n">flrg</span>
<span class="n">default_c</span> <span class="o">=</span> <span class="mf">1.1</span>
<div class="viewcode-block" id="ExponentialyWeightedFLRG"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.sadaei.ExponentialyWeightedFLRG">[docs]</a><span class="k">class</span> <span class="nc">ExponentialyWeightedFLRG</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">FLRG</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;First Order Exponentialy Weighted Fuzzy Logical Relationship Group&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">LHS</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">ExponentialyWeightedFLRG</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">LHS</span> <span class="o">=</span> <span class="n">LHS</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">c</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;c&quot;</span><span class="p">,</span><span class="n">default_c</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">w</span> <span class="o">=</span> <span class="kc">None</span>
<div class="viewcode-block" id="ExponentialyWeightedFLRG.append_rhs"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.sadaei.ExponentialyWeightedFLRG.append_rhs">[docs]</a> <span class="k">def</span> <span class="nf">append_rhs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">count</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;count&#39;</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">+=</span> <span class="n">count</span></div>
<div class="viewcode-block" id="ExponentialyWeightedFLRG.weights"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.sadaei.ExponentialyWeightedFLRG.weights">[docs]</a> <span class="k">def</span> <span class="nf">weights</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">wei</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">c</span> <span class="o">**</span> <span class="n">k</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="mf">0.0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)]</span>
<span class="n">tot</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">wei</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">w</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="n">k</span> <span class="o">/</span> <span class="n">tot</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">wei</span><span class="p">])</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">LHS</span> <span class="o">+</span> <span class="s2">&quot; -&gt; &quot;</span>
<span class="n">tmp2</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="n">cc</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">wei</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">c</span> <span class="o">**</span> <span class="n">k</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="mf">0.0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)]</span>
<span class="n">tot</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">wei</span><span class="p">)</span>
<span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">):</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">tmp2</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">tmp2</span> <span class="o">=</span> <span class="n">tmp2</span> <span class="o">+</span> <span class="s2">&quot;,&quot;</span>
<span class="n">tmp2</span> <span class="o">=</span> <span class="n">tmp2</span> <span class="o">+</span> <span class="n">c</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">wei</span><span class="p">[</span><span class="n">cc</span><span class="p">]</span> <span class="o">/</span> <span class="n">tot</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;)&quot;</span>
<span class="n">cc</span> <span class="o">=</span> <span class="n">cc</span> <span class="o">+</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">tmp</span> <span class="o">+</span> <span class="n">tmp2</span>
<span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div>
<div class="viewcode-block" id="ExponentialyWeightedFTS"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.sadaei.ExponentialyWeightedFTS">[docs]</a><span class="k">class</span> <span class="nc">ExponentialyWeightedFTS</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;First Order Exponentialy Weighted Fuzzy Time Series&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">ExponentialyWeightedFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</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">name</span><span class="o">=</span><span class="s2">&quot;EWFTS&quot;</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Exponentialy Weighted FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;Sadaei&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">c</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;c&#39;</span><span class="p">,</span> <span class="n">default_c</span><span class="p">)</span>
<div class="viewcode-block" id="ExponentialyWeightedFTS.generate_flrg"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.sadaei.ExponentialyWeightedFTS.generate_flrg">[docs]</a> <span class="k">def</span> <span class="nf">generate_flrg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrs</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
<span class="k">for</span> <span class="n">flr</span> <span class="ow">in</span> <span class="n">flrs</span><span class="p">:</span>
<span class="k">if</span> <span class="n">flr</span><span class="o">.</span><span class="n">LHS</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span> <span class="o">=</span> <span class="n">ExponentialyWeightedFLRG</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="n">c</span><span class="p">);</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div>
<div class="viewcode-block" id="ExponentialyWeightedFTS.train"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.sadaei.ExponentialyWeightedFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">tmpdata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">fuzzyfy</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;maximum&#39;</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;sets&#39;</span><span class="p">)</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_recurrent_flrs</span><span class="p">(</span><span class="n">tmpdata</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg</span><span class="p">(</span><span class="n">flrs</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">c</span><span class="p">)</span></div>
<div class="viewcode-block" id="ExponentialyWeightedFTS.forecast"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.sadaei.ExponentialyWeightedFTS.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">explain</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;explain&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">ordered_sets</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ordered_sets</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">set_ordered</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">data</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="n">ndata</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">ndata</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</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">actual</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">get_maximum_membership_fuzzyset</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">ordered_sets</span><span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Fuzzyfication:</span><span class="se">\n\n</span><span class="s2"> </span><span class="si">{}</span><span class="s2"> -&gt; </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">actual</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
<span class="k">if</span> <span class="n">actual</span><span class="o">.</span><span class="n">name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</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">actual</span><span class="o">.</span><span class="n">centroid</span><span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Rules:</span><span class="se">\n\n</span><span class="s2"> </span><span class="si">{}</span><span class="s2"> -&gt; </span><span class="si">{}</span><span class="s2"> (Naïve)</span><span class="se">\t</span><span class="s2"> Midpoint: </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">actual</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">actual</span><span class="o">.</span><span class="n">name</span><span class="p">,</span><span class="n">actual</span><span class="o">.</span><span class="n">centroid</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">actual</span><span class="o">.</span><span class="n">name</span><span class="p">]</span>
<span class="n">mp</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_midpoints</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">final</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">weights</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">final</span><span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Rules:</span><span class="se">\n\n</span><span class="s2"> </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n\n</span><span class="s2"> &quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">flrg</span><span class="p">)))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Midpoints: </span><span class="se">\n\n</span><span class="s2"> </span><span class="si">{}</span><span class="se">\n\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">mp</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Deffuzyfied value: </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">final</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ret</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.sadaei</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,209 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.seasonal.cmsfts &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
<script src="../../../../_static/jquery.js"></script>
<script src="../../../../_static/underscore.js"></script>
<script src="../../../../_static/doctools.js"></script>
<script src="../../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.seasonal.cmsfts</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.seasonal.cmsfts</h1><div class="highlight"><pre>
<span></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.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">FLR</span>
<span class="kn">from</span> <span class="nn">pyFTS.models.seasonal</span> <span class="kn">import</span> <span class="n">sfts</span>
<span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="kn">import</span> <span class="n">chen</span>
<div class="viewcode-block" id="ContextualSeasonalFLRG"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.cmsfts.ContextualSeasonalFLRG">[docs]</a><span class="k">class</span> <span class="nc">ContextualSeasonalFLRG</span><span class="p">(</span><span class="n">sfts</span><span class="o">.</span><span class="n">SeasonalFLRG</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Contextual Seasonal Fuzzy Logical Relationship Group</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">seasonality</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">ContextualSeasonalFLRG</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">seasonality</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span> <span class="o">=</span> <span class="p">{}</span>
<div class="viewcode-block" id="ContextualSeasonalFLRG.append_rhs"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.cmsfts.ContextualSeasonalFLRG.append_rhs">[docs]</a> <span class="k">def</span> <span class="nf">append_rhs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flr</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">flr</span><span class="o">.</span><span class="n">LHS</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span> <span class="o">=</span> <span class="n">chen</span><span class="o">.</span><span class="n">ConventionalFLRG</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;: </span><span class="se">\n</span><span class="s2"> &quot;</span>
<span class="n">tmp2</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="se">\t</span><span class="s2">&quot;</span>
<span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">):</span>
<span class="n">tmp2</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">r</span><span class="p">])</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n\t</span><span class="s2">&quot;</span>
<span class="k">return</span> <span class="n">tmp</span> <span class="o">+</span> <span class="n">tmp2</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span></div>
<div class="viewcode-block" id="ContextualMultiSeasonalFTS"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.cmsfts.ContextualMultiSeasonalFTS">[docs]</a><span class="k">class</span> <span class="nc">ContextualMultiSeasonalFTS</span><span class="p">(</span><span class="n">sfts</span><span class="o">.</span><span class="n">SeasonalFTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Contextual Multi-Seasonal Fuzzy Time Series</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">ContextualMultiSeasonalFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Contextual Multi Seasonal FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;CMSFTS &quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">seasonality</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_seasonality</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_point_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_multivariate</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span> <span class="o">=</span> <span class="p">{}</span>
<div class="viewcode-block" id="ContextualMultiSeasonalFTS.generate_flrg"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.cmsfts.ContextualMultiSeasonalFTS.generate_flrg">[docs]</a> <span class="k">def</span> <span class="nf">generate_flrg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrs</span><span class="p">):</span>
<span class="k">for</span> <span class="n">flr</span> <span class="ow">in</span> <span class="n">flrs</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">str</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">index</span><span class="p">)</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">index</span><span class="p">)]</span> <span class="o">=</span> <span class="n">ContextualSeasonalFLRG</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">index</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">index</span><span class="p">)]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="p">)</span></div>
<div class="viewcode-block" id="ContextualMultiSeasonalFTS.train"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.cmsfts.ContextualMultiSeasonalFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;sets&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">sets</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;sets&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;parameters&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">seasonality</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;parameters&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_indexed_flrs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">indexer</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span>
<span class="n">transformation</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">transformation</span><span class="p">,</span>
<span class="n">alpha_cut</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">alpha_cut</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg</span><span class="p">(</span><span class="n">flrs</span><span class="p">)</span></div>
<div class="viewcode-block" id="ContextualMultiSeasonalFTS.get_midpoints"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.cmsfts.ContextualMultiSeasonalFTS.get_midpoints">[docs]</a> <span class="k">def</span> <span class="nf">get_midpoints</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrg</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">:</span>
<span class="k">if</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">flrg</span><span class="o">.</span><span class="n">RHS</span><span class="p">:</span>
<span class="n">ret</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">flrg</span><span class="o">.</span><span class="n">RHS</span><span class="p">[</span><span class="n">d</span><span class="p">]</span><span class="o">.</span><span class="n">RHS</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ret</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">d</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span><span class="p">])</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span></div>
<div class="viewcode-block" id="ContextualMultiSeasonalFTS.forecast"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.cmsfts.ContextualMultiSeasonalFTS.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">ordered_sets</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">set_ordered</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">index</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">indexer</span><span class="o">.</span><span class="n">get_season_of_data</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">indexer</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">data</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="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)):</span>
<span class="k">if</span> <span class="nb">str</span><span class="p">(</span><span class="n">index</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">index</span><span class="p">[</span><span class="n">k</span><span class="p">])]</span>
<span class="n">d</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">get_fuzzysets</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">ordered_sets</span><span class="p">,</span> <span class="n">alpha_cut</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">alpha_cut</span><span class="p">)</span>
<span class="n">mp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_midpoints</span><span class="p">(</span><span class="n">flrg</span><span class="p">,</span> <span class="n">d</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="nb">sum</span><span class="p">(</span><span class="n">mp</span><span class="p">)</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">mp</span><span class="p">))</span>
<span class="k">else</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">np</span><span class="o">.</span><span class="n">nan</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="ContextualMultiSeasonalFTS.forecast_ahead"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.cmsfts.ContextualMultiSeasonalFTS.forecast_ahead">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">steps</span><span class="p">:</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)]</span>
<span class="n">mp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_midpoints</span><span class="p">(</span><span class="n">flrg</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="nb">sum</span><span class="p">(</span><span class="n">mp</span><span class="p">)</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">mp</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ret</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.seasonal.cmsfts</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,165 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.seasonal.msfts &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
<script src="../../../../_static/jquery.js"></script>
<script src="../../../../_static/underscore.js"></script>
<script src="../../../../_static/doctools.js"></script>
<script src="../../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.seasonal.msfts</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.seasonal.msfts</h1><div class="highlight"><pre>
<span></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.common</span> <span class="kn">import</span> <span class="n">FLR</span>
<span class="kn">from</span> <span class="nn">pyFTS.models.seasonal</span> <span class="kn">import</span> <span class="n">sfts</span>
<div class="viewcode-block" id="MultiSeasonalFTS"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.msfts.MultiSeasonalFTS">[docs]</a><span class="k">class</span> <span class="nc">MultiSeasonalFTS</span><span class="p">(</span><span class="n">sfts</span><span class="o">.</span><span class="n">SeasonalFTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Multi-Seasonal Fuzzy Time Series</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">indexer</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">MultiSeasonalFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="s2">&quot;MSFTS&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Multi Seasonal FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;MSFTS &quot;</span> <span class="o">+</span> <span class="n">name</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">seasonality</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_seasonality</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_point_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_multivariate</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">indexer</span> <span class="o">=</span> <span class="n">indexer</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span> <span class="o">=</span> <span class="p">{}</span>
<div class="viewcode-block" id="MultiSeasonalFTS.generate_flrg"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.msfts.MultiSeasonalFTS.generate_flrg">[docs]</a> <span class="k">def</span> <span class="nf">generate_flrg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrs</span><span class="p">):</span>
<span class="k">for</span> <span class="n">flr</span> <span class="ow">in</span> <span class="n">flrs</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">str</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">index</span><span class="p">)</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">index</span><span class="p">)]</span> <span class="o">=</span> <span class="n">sfts</span><span class="o">.</span><span class="n">SeasonalFLRG</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">index</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">index</span><span class="p">)]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div>
<div class="viewcode-block" id="MultiSeasonalFTS.train"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.msfts.MultiSeasonalFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;sets&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">sets</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;sets&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;parameters&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">seasonality</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;parameters&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="c1">#ndata = self.indexer.set_data(data,self.doTransformations(self.indexer.get_data(data)))</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_indexed_flrs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">indexer</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg</span><span class="p">(</span><span class="n">flrs</span><span class="p">)</span></div>
<div class="viewcode-block" id="MultiSeasonalFTS.forecast"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.msfts.MultiSeasonalFTS.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">index</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">indexer</span><span class="o">.</span><span class="n">get_season_of_data</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">indexer</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">data</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="nb">len</span><span class="p">(</span><span class="n">index</span><span class="p">)):</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">index</span><span class="p">[</span><span class="n">k</span><span class="p">])]</span>
<span class="n">mp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">getMidpoints</span><span class="p">(</span><span class="n">flrg</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="nb">sum</span><span class="p">(</span><span class="n">mp</span><span class="p">)</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">mp</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="MultiSeasonalFTS.forecast_ahead"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.msfts.MultiSeasonalFTS.forecast_ahead">[docs]</a> <span class="k">def</span> <span class="nf">forecast_ahead</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">steps</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">steps</span><span class="p">:</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)]</span>
<span class="n">mp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">getMidpoints</span><span class="p">(</span><span class="n">flrg</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="nb">sum</span><span class="p">(</span><span class="n">mp</span><span class="p">)</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">mp</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ret</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.seasonal.msfts</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,200 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.seasonal.sfts &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
<script src="../../../../_static/jquery.js"></script>
<script src="../../../../_static/underscore.js"></script>
<script src="../../../../_static/doctools.js"></script>
<script src="../../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.seasonal.sfts</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.seasonal.sfts</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Simple First Order Seasonal Fuzzy Time Series implementation of Song (1999) based of Conventional FTS by Chen (1996)</span>
<span class="sd">Q. Song, “Seasonal forecasting in fuzzy time series,” Fuzzy sets Syst., vol. 107, pp. 235236, 1999.</span>
<span class="sd">S.-M. Chen, “Forecasting enrollments based on fuzzy time series,” Fuzzy Sets Syst., vol. 81, no. 3, pp. 311319, 1996.</span>
<span class="sd">&quot;&quot;&quot;</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.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">FLR</span><span class="p">,</span> <span class="n">flrg</span><span class="p">,</span> <span class="n">fts</span>
<div class="viewcode-block" id="SeasonalFLRG"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.sfts.SeasonalFLRG">[docs]</a><span class="k">class</span> <span class="nc">SeasonalFLRG</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">FLRG</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;First Order Seasonal Fuzzy Logical Relationship Group&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">seasonality</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">SeasonalFLRG</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">LHS</span> <span class="o">=</span> <span class="n">seasonality</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span> <span class="o">=</span> <span class="p">[]</span>
<div class="viewcode-block" id="SeasonalFLRG.get_key"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.sfts.SeasonalFLRG.get_key">[docs]</a> <span class="k">def</span> <span class="nf">get_key</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">LHS</span></div>
<div class="viewcode-block" id="SeasonalFLRG.append_rhs"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.sfts.SeasonalFLRG.append_rhs">[docs]</a> <span class="k">def</span> <span class="nf">append_rhs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">c</span><span class="p">)</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; -&gt; &quot;</span>
<span class="n">tmp2</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="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">s</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">s</span><span class="p">)):</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">tmp2</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">tmp2</span> <span class="o">=</span> <span class="n">tmp2</span> <span class="o">+</span> <span class="s2">&quot;,&quot;</span>
<span class="n">tmp2</span> <span class="o">=</span> <span class="n">tmp2</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="k">return</span> <span class="n">tmp</span> <span class="o">+</span> <span class="n">tmp2</span>
<span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div>
<div class="viewcode-block" id="SeasonalFTS"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.sfts.SeasonalFTS">[docs]</a><span class="k">class</span> <span class="nc">SeasonalFTS</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;First Order Seasonal Fuzzy Time Series&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">SeasonalFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Seasonal FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">shortname</span> <span class="o">=</span> <span class="s2">&quot;SFTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">order</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">seasonality</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_seasonality</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_point_forecasting</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">is_high_order</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span> <span class="o">=</span> <span class="p">{}</span>
<div class="viewcode-block" id="SeasonalFTS.generate_flrg"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.sfts.SeasonalFTS.generate_flrg">[docs]</a> <span class="k">def</span> <span class="nf">generate_flrg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrs</span><span class="p">):</span>
<span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">flr</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">flrs</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
<span class="n">season</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">indexer</span><span class="o">.</span><span class="n">get_season_by_index</span><span class="p">(</span><span class="n">ct</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">ss</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">season</span><span class="p">)</span>
<span class="k">if</span> <span class="n">ss</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">ss</span><span class="p">]</span> <span class="o">=</span> <span class="n">SeasonalFLRG</span><span class="p">(</span><span class="n">season</span><span class="p">)</span>
<span class="c1">#print(season)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">ss</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div>
<div class="viewcode-block" id="SeasonalFTS.get_midpoints"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.sfts.SeasonalFTS.get_midpoints">[docs]</a> <span class="k">def</span> <span class="nf">get_midpoints</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrg</span><span class="p">):</span>
<span class="n">ret</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="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">flrg</span><span class="o">.</span><span class="n">RHS</span><span class="p">])</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="SeasonalFTS.train"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.sfts.SeasonalFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</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">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;sets&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">sets</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;sets&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="n">tmpdata</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">fuzzyfy_series_old</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_non_recurrent_flrs</span><span class="p">(</span><span class="n">tmpdata</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg</span><span class="p">(</span><span class="n">flrs</span><span class="p">)</span></div>
<div class="viewcode-block" id="SeasonalFTS.forecast"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.sfts.SeasonalFTS.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</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">data</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</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">season</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">indexer</span><span class="o">.</span><span class="n">get_season_by_index</span><span class="p">(</span><span class="n">k</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">season</span><span class="p">)]</span>
<span class="n">mp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_midpoints</span><span class="p">(</span><span class="n">flrg</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">np</span><span class="o">.</span><span class="n">percentile</span><span class="p">(</span><span class="n">mp</span><span class="p">,</span> <span class="mi">50</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ret</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;String representation of the model&quot;&quot;&quot;</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">+</span> <span class="s2">&quot;:</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="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">tmp</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">r</span><span class="p">])</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>
<span class="k">return</span> <span class="n">tmp</span></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.seasonal.sfts</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,186 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.song &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.song</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.song</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">First Order Traditional Fuzzy Time Series method by Song &amp; Chissom (1993)</span>
<span class="sd">Q. Song and B. S. Chissom, “Fuzzy time series and its models,” Fuzzy Sets Syst., vol. 54, no. 3, pp. 269277, 1993.</span>
<span class="sd">&quot;&quot;&quot;</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.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">FLR</span><span class="p">,</span> <span class="n">fts</span>
<div class="viewcode-block" id="ConventionalFTS"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.song.ConventionalFTS">[docs]</a><span class="k">class</span> <span class="nc">ConventionalFTS</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Traditional Fuzzy Time Series&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">ConventionalFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</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">name</span><span class="o">=</span><span class="s2">&quot;FTS&quot;</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Traditional FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;Song &amp; Chissom&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">sets</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span>
<span class="bp">self</span><span class="o">.</span><span class="n">R</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</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="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">R</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">l</span><span class="p">,</span><span class="n">l</span><span class="p">))</span>
<div class="viewcode-block" id="ConventionalFTS.flr_membership_matrix"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.song.ConventionalFTS.flr_membership_matrix">[docs]</a> <span class="k">def</span> <span class="nf">flr_membership_matrix</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flr</span><span class="p">):</span>
<span class="n">ordered_set</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">set_ordered</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">centroids</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">ordered_set</span><span class="p">]</span>
<span class="n">lm</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">centroids</span><span class="p">]</span>
<span class="n">rm</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">centroids</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">ordered_set</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">l</span><span class="p">,</span> <span class="n">l</span><span class="p">))</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="mi">0</span><span class="p">,</span><span class="n">l</span><span class="p">):</span>
<span class="k">for</span> <span class="n">l</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="n">l</span><span class="p">):</span>
<span class="n">r</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">l</span><span class="p">]</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">lm</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">rm</span><span class="p">[</span><span class="n">l</span><span class="p">])</span>
<span class="k">return</span> <span class="n">r</span></div>
<div class="viewcode-block" id="ConventionalFTS.operation_matrix"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.song.ConventionalFTS.operation_matrix">[docs]</a> <span class="k">def</span> <span class="nf">operation_matrix</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrs</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="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">R</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">R</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span> <span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">R</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">l</span><span class="p">,</span> <span class="n">l</span><span class="p">))</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">flrs</span><span class="p">:</span>
<span class="n">mm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flr_membership_matrix</span><span class="p">(</span><span class="n">k</span><span class="p">)</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="mi">0</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>
<span class="k">for</span> <span class="n">l</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="n">l</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">R</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">l</span><span class="p">]</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">R</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">l</span><span class="p">],</span> <span class="n">mm</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">l</span><span class="p">])</span></div>
<div class="viewcode-block" id="ConventionalFTS.train"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.song.ConventionalFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">tmpdata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">fuzzyfy</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;maximum&#39;</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;sets&#39;</span><span class="p">)</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_non_recurrent_flrs</span><span class="p">(</span><span class="n">tmpdata</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">operation_matrix</span><span class="p">(</span><span class="n">flrs</span><span class="p">)</span></div>
<div class="viewcode-block" id="ConventionalFTS.forecast"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.song.ConventionalFTS.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</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="bp">self</span><span class="o">.</span><span class="n">partitioner</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">ordered_sets</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ordered_sets</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">set_ordered</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</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">ndata</span><span class="p">)</span>
<span class="n">npart</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</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">mv</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">fuzzyfy_instance</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="p">[</span><span class="nb">max</span><span class="p">([</span> <span class="nb">min</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">R</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">],</span> <span class="n">mv</span><span class="p">[</span><span class="n">j</span><span class="p">])</span> <span class="k">for</span> <span class="n">j</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">npart</span><span class="p">)</span> <span class="p">])</span> <span class="k">for</span> <span class="n">i</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">npart</span><span class="p">)]</span>
<span class="n">fs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ravel</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">argwhere</span><span class="p">(</span><span class="n">r</span> <span class="o">==</span> <span class="nb">max</span><span class="p">(</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">fs</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</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="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">ordered_sets</span><span class="p">[</span><span class="n">fs</span><span class="p">[</span><span class="mi">0</span><span class="p">]]]</span><span class="o">.</span><span class="n">centroid</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">mp</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">ordered_sets</span><span class="p">[</span><span class="n">s</span><span class="p">]]</span><span class="o">.</span><span class="n">centroid</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">fs</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="nb">sum</span><span class="p">(</span><span class="n">mp</span><span class="p">)</span><span class="o">/</span><span class="nb">len</span><span class="p">(</span><span class="n">mp</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ret</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">+</span> <span class="s2">&quot;:</span><span class="se">\n</span><span class="s2">&quot;</span>
<span class="k">return</span> <span class="n">tmp</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">R</span><span class="p">)</span></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.song</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,207 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.models.yu &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.yu</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.models.yu</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">First Order Weighted Fuzzy Time Series by Yu(2005)</span>
<span class="sd">H.-K. Yu, “Weighted fuzzy time series models for TAIEX forecasting,” </span>
<span class="sd">Phys. A Stat. Mech. its Appl., vol. 349, no. 3, pp. 609624, 2005.</span>
<span class="sd">&quot;&quot;&quot;</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.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">FLR</span><span class="p">,</span> <span class="n">fts</span><span class="p">,</span> <span class="n">flrg</span>
<span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="kn">import</span> <span class="n">chen</span>
<div class="viewcode-block" id="WeightedFLRG"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.yu.WeightedFLRG">[docs]</a><span class="k">class</span> <span class="nc">WeightedFLRG</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">FLRG</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;First Order Weighted Fuzzy Logical Relationship Group&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">LHS</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">WeightedFLRG</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">LHS</span> <span class="o">=</span> <span class="n">LHS</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">=</span> <span class="mf">1.0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">w</span> <span class="o">=</span> <span class="kc">None</span>
<div class="viewcode-block" id="WeightedFLRG.append_rhs"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.yu.WeightedFLRG.append_rhs">[docs]</a> <span class="k">def</span> <span class="nf">append_rhs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">count</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;count&#39;</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">+=</span> <span class="n">count</span></div>
<div class="viewcode-block" id="WeightedFLRG.weights"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.yu.WeightedFLRG.weights">[docs]</a> <span class="k">def</span> <span class="nf">weights</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sets</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">tot</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">w</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="n">k</span> <span class="o">/</span> <span class="n">tot</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="mf">1.0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)])</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">LHS</span> <span class="o">+</span> <span class="s2">&quot; -&gt; &quot;</span>
<span class="n">tmp2</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="n">cc</span> <span class="o">=</span> <span class="mf">1.0</span>
<span class="n">tot</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">))</span>
<span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">):</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">tmp2</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">tmp2</span> <span class="o">=</span> <span class="n">tmp2</span> <span class="o">+</span> <span class="s2">&quot;,&quot;</span>
<span class="n">tmp2</span> <span class="o">=</span> <span class="n">tmp2</span> <span class="o">+</span> <span class="n">c</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="nb">round</span><span class="p">(</span><span class="n">cc</span> <span class="o">/</span> <span class="n">tot</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span> <span class="o">+</span> <span class="s2">&quot;)&quot;</span>
<span class="n">cc</span> <span class="o">=</span> <span class="n">cc</span> <span class="o">+</span> <span class="mf">1.0</span>
<span class="k">return</span> <span class="n">tmp</span> <span class="o">+</span> <span class="n">tmp2</span></div>
<div class="viewcode-block" id="WeightedFTS"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.yu.WeightedFTS">[docs]</a><span class="k">class</span> <span class="nc">WeightedFTS</span><span class="p">(</span><span class="n">fts</span><span class="o">.</span><span class="n">FTS</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;First Order Weighted Fuzzy Time Series&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">WeightedFTS</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</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">name</span><span class="o">=</span><span class="s2">&quot;WFTS&quot;</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Weighted FTS&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">detail</span> <span class="o">=</span> <span class="s2">&quot;Yu&quot;</span>
<div class="viewcode-block" id="WeightedFTS.generate_FLRG"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.yu.WeightedFTS.generate_FLRG">[docs]</a> <span class="k">def</span> <span class="nf">generate_FLRG</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrs</span><span class="p">):</span>
<span class="k">for</span> <span class="n">flr</span> <span class="ow">in</span> <span class="n">flrs</span><span class="p">:</span>
<span class="k">if</span> <span class="n">flr</span><span class="o">.</span><span class="n">LHS</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span> <span class="o">=</span> <span class="n">WeightedFLRG</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">);</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div>
<div class="viewcode-block" id="WeightedFTS.train"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.yu.WeightedFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">tmpdata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">fuzzyfy</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;maximum&#39;</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;sets&#39;</span><span class="p">)</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_recurrent_flrs</span><span class="p">(</span><span class="n">tmpdata</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_FLRG</span><span class="p">(</span><span class="n">flrs</span><span class="p">)</span></div>
<div class="viewcode-block" id="WeightedFTS.forecast"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.yu.WeightedFTS.forecast">[docs]</a> <span class="k">def</span> <span class="nf">forecast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">explain</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;explain&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">ordered_sets</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">ordered_sets</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ordered_sets</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">set_ordered</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">ndata</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="n">ndata</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">ndata</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">explain</span> <span class="k">else</span> <span class="mi">1</span>
<span class="n">ret</span> <span class="o">=</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">actual</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">get_maximum_membership_fuzzyset</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">ordered_sets</span><span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Fuzzyfication:</span><span class="se">\n\n</span><span class="s2"> </span><span class="si">{}</span><span class="s2"> -&gt; </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">actual</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
<span class="k">if</span> <span class="n">actual</span><span class="o">.</span><span class="n">name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</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">actual</span><span class="o">.</span><span class="n">centroid</span><span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Rules:</span><span class="se">\n\n</span><span class="s2"> </span><span class="si">{}</span><span class="s2"> -&gt; </span><span class="si">{}</span><span class="s2"> (Naïve)</span><span class="se">\t</span><span class="s2"> Midpoint: </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">actual</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">actual</span><span class="o">.</span><span class="n">name</span><span class="p">,</span><span class="n">actual</span><span class="o">.</span><span class="n">centroid</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">actual</span><span class="o">.</span><span class="n">name</span><span class="p">]</span>
<span class="n">mp</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_midpoints</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">final</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">weights</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</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">final</span><span class="p">)</span>
<span class="k">if</span> <span class="n">explain</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Rules:</span><span class="se">\n\n</span><span class="s2"> </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n\n</span><span class="s2"> &quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">flrg</span><span class="p">)))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Midpoints: </span><span class="se">\n\n</span><span class="s2"> </span><span class="si">{}</span><span class="se">\n\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">mp</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Deffuzyfied value: </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">final</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ret</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.models.yu</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,154 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.partitioners.Huarng &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.partitioners.Huarng</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.partitioners.Huarng</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">K. H. Huarng, “Effective lengths of intervals to improve forecasting in fuzzy time series,”</span>
<span class="sd">Fuzzy Sets Syst., vol. 123, no. 3, pp. 387394, Nov. 2001.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">math</span>
<span class="kn">import</span> <span class="nn">random</span> <span class="k">as</span> <span class="nn">rnd</span>
<span class="kn">import</span> <span class="nn">functools</span><span class="o">,</span> <span class="nn">operator</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">Membership</span><span class="p">,</span> <span class="n">Transformations</span>
<span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="kn">import</span> <span class="n">partitioner</span>
<div class="viewcode-block" id="HuarngPartitioner"><a class="viewcode-back" href="../../../pyFTS.partitioners.html#pyFTS.partitioners.Huarng.HuarngPartitioner">[docs]</a><span class="k">class</span> <span class="nc">HuarngPartitioner</span><span class="p">(</span><span class="n">partitioner</span><span class="o">.</span><span class="n">Partitioner</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Huarng Empirical Partitioner&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">HuarngPartitioner</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;Huarng&quot;</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<div class="viewcode-block" id="HuarngPartitioner.build"><a class="viewcode-back" href="../../../pyFTS.partitioners.html#pyFTS.partitioners.Huarng.HuarngPartitioner.build">[docs]</a> <span class="k">def</span> <span class="nf">build</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="n">diff</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="mi">1</span><span class="p">)</span>
<span class="n">data2</span> <span class="o">=</span> <span class="n">diff</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">davg</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">data2</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span> <span class="p">)</span>
<span class="k">if</span> <span class="n">davg</span> <span class="o">&lt;=</span> <span class="mf">1.0</span><span class="p">:</span>
<span class="n">base</span> <span class="o">=</span> <span class="mf">0.1</span>
<span class="k">elif</span> <span class="mi">1</span> <span class="o">&lt;</span> <span class="n">davg</span> <span class="o">&lt;=</span> <span class="mi">10</span><span class="p">:</span>
<span class="n">base</span> <span class="o">=</span> <span class="mf">1.0</span>
<span class="k">elif</span> <span class="mi">10</span> <span class="o">&lt;</span> <span class="n">davg</span> <span class="o">&lt;=</span> <span class="mi">100</span><span class="p">:</span>
<span class="n">base</span> <span class="o">=</span> <span class="mi">10</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">base</span> <span class="o">=</span> <span class="mi">100</span>
<span class="n">sets</span> <span class="o">=</span> <span class="p">{}</span>
<span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;type&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="s1">&#39;variable&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">variable</span><span class="p">}</span>
<span class="n">dlen</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">max</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">min</span>
<span class="n">npart</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">dlen</span> <span class="o">/</span> <span class="n">base</span><span class="p">)</span>
<span class="n">partition</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">min</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="n">npart</span><span class="p">):</span>
<span class="n">_name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_name</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">membership_function</span> <span class="o">==</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trimf</span><span class="p">:</span>
<span class="n">sets</span><span class="p">[</span><span class="n">_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">FuzzySet</span><span class="p">(</span><span class="n">_name</span><span class="p">,</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trimf</span><span class="p">,</span>
<span class="p">[</span><span class="n">partition</span> <span class="o">-</span> <span class="n">base</span><span class="p">,</span> <span class="n">partition</span><span class="p">,</span> <span class="n">partition</span> <span class="o">+</span> <span class="n">base</span><span class="p">],</span> <span class="n">partition</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">membership_function</span> <span class="o">==</span> <span class="n">Membership</span><span class="o">.</span><span class="n">gaussmf</span><span class="p">:</span>
<span class="n">sets</span><span class="p">[</span><span class="n">_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">FuzzySet</span><span class="p">(</span><span class="n">_name</span><span class="p">,</span> <span class="n">Membership</span><span class="o">.</span><span class="n">gaussmf</span><span class="p">,</span>
<span class="p">[</span><span class="n">partition</span><span class="p">,</span> <span class="n">base</span><span class="o">/</span><span class="mi">2</span><span class="p">],</span> <span class="n">partition</span><span class="p">)</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">membership_function</span> <span class="o">==</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trapmf</span><span class="p">:</span>
<span class="n">sets</span><span class="p">[</span><span class="n">_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">FuzzySet</span><span class="p">(</span><span class="n">_name</span><span class="p">,</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trapmf</span><span class="p">,</span>
<span class="p">[</span><span class="n">partition</span> <span class="o">-</span> <span class="n">base</span><span class="p">,</span> <span class="n">partition</span> <span class="o">-</span> <span class="p">(</span><span class="n">base</span><span class="o">/</span><span class="mi">2</span><span class="p">),</span>
<span class="n">partition</span> <span class="o">+</span> <span class="p">(</span><span class="n">base</span> <span class="o">/</span> <span class="mi">2</span><span class="p">),</span> <span class="n">partition</span> <span class="o">+</span> <span class="n">base</span><span class="p">],</span> <span class="n">partition</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">partition</span> <span class="o">+=</span> <span class="n">base</span>
<span class="k">return</span> <span class="n">sets</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.partitioners.Huarng</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,188 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.partitioners.Util &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.partitioners.Util</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.partitioners.Util</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Facility methods for pyFTS partitioners module</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</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.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="c1">#from mpl_toolkits.mplot3d import Axes3D</span>
<span class="kn">from</span> <span class="nn">pyFTS.benchmarks</span> <span class="kn">import</span> <span class="n">Measures</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">Membership</span><span class="p">,</span> <span class="n">Util</span>
<span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="kn">import</span> <span class="n">Grid</span><span class="p">,</span><span class="n">Huarng</span><span class="p">,</span><span class="n">FCM</span><span class="p">,</span><span class="n">Entropy</span>
<span class="n">all_methods</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">Huarng</span><span class="o">.</span><span class="n">HuarngPartitioner</span><span class="p">]</span>
<span class="n">mfs</span> <span class="o">=</span> <span class="p">[</span><span class="n">Membership</span><span class="o">.</span><span class="n">trimf</span><span class="p">,</span> <span class="n">Membership</span><span class="o">.</span><span class="n">gaussmf</span><span class="p">,</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trapmf</span><span class="p">]</span>
<div class="viewcode-block" id="plot_sets"><a class="viewcode-back" href="../../../pyFTS.partitioners.html#pyFTS.partitioners.Util.plot_sets">[docs]</a><span class="k">def</span> <span class="nf">plot_sets</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">sets</span><span class="p">,</span> <span class="n">titles</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">[</span><span class="mi">12</span><span class="p">,</span> <span class="mi">10</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">axis</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="n">num</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">sets</span><span class="p">)</span>
<span class="k">if</span> <span class="n">axis</span> <span class="ow">is</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="n">num</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="n">size</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">num</span><span class="p">):</span>
<span class="n">ticks</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">x</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">ax</span> <span class="o">=</span> <span class="n">axes</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="k">if</span> <span class="n">axis</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">axis</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="n">titles</span><span class="p">[</span><span class="n">k</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="mi">0</span><span class="p">,</span> <span class="mf">1.1</span><span class="p">])</span>
<span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">sets</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="n">s</span> <span class="o">=</span> <span class="n">sets</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">key</span><span class="p">]</span>
<span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">mf</span> <span class="o">==</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trimf</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">s</span><span class="o">.</span><span class="n">parameters</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">0</span><span class="p">])</span>
<span class="k">elif</span> <span class="n">s</span><span class="o">.</span><span class="n">mf</span> <span class="o">==</span> <span class="n">Membership</span><span class="o">.</span><span class="n">gaussmf</span><span class="p">:</span>
<span class="n">tmpx</span> <span class="o">=</span> <span class="p">[</span> <span class="n">kk</span> <span class="k">for</span> <span class="n">kk</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="n">s</span><span class="o">.</span><span class="n">lower</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">upper</span><span class="p">)]</span>
<span class="n">tmpy</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">kk</span><span class="p">)</span> <span class="k">for</span> <span class="n">kk</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="n">s</span><span class="o">.</span><span class="n">lower</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">upper</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">tmpx</span><span class="p">,</span> <span class="n">tmpy</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">s</span><span class="o">.</span><span class="n">mf</span> <span class="o">==</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trapmf</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">s</span><span class="o">.</span><span class="n">parameters</span><span class="p">,</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="mi">0</span><span class="p">])</span>
<span class="n">ticks</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">centroid</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">+</span> <span class="n">s</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">centroid</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">xaxis</span><span class="o">.</span><span class="n">set_ticklabels</span><span class="p">(</span><span class="n">ticks</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">xaxis</span><span class="o">.</span><span class="n">set_ticks</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="k">if</span> <span class="n">axis</span> <span class="ow">is</span> <span class="kc">None</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">Util</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>
<div class="viewcode-block" id="plot_partitioners"><a class="viewcode-back" href="../../../pyFTS.partitioners.html#pyFTS.partitioners.Util.plot_partitioners">[docs]</a><span class="k">def</span> <span class="nf">plot_partitioners</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">objs</span><span class="p">,</span> <span class="n">tam</span><span class="o">=</span><span class="p">[</span><span class="mi">12</span><span class="p">,</span> <span class="mi">10</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">axis</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="n">sets</span> <span class="o">=</span> <span class="p">[</span><span class="n">k</span><span class="o">.</span><span class="n">sets</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">objs</span><span class="p">]</span>
<span class="n">titles</span> <span class="o">=</span> <span class="p">[</span><span class="n">k</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">objs</span><span class="p">]</span>
<span class="n">plot_sets</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">sets</span><span class="p">,</span> <span class="n">titles</span><span class="p">,</span> <span class="n">tam</span><span class="p">,</span> <span class="n">save</span><span class="p">,</span> <span class="n">file</span><span class="p">,</span> <span class="n">axis</span><span class="p">)</span></div>
<div class="viewcode-block" id="explore_partitioners"><a class="viewcode-back" href="../../../pyFTS.partitioners.html#pyFTS.partitioners.Util.explore_partitioners">[docs]</a><span class="k">def</span> <span class="nf">explore_partitioners</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">npart</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">mf</span><span class="o">=</span><span class="kc">None</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">size</span><span class="o">=</span><span class="p">[</span><span class="mi">12</span><span class="p">,</span> <span class="mi">10</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="sd">&quot;&quot;&quot;</span>
<span class="sd"> Create partitioners for the mf membership functions and npart partitions and show the partitioning images.</span>
<span class="sd"> :data: Time series data</span>
<span class="sd"> :npart: Maximum number of partitions of the universe of discourse</span>
<span class="sd"> :methods: A list with the partitioning methods to be used</span>
<span class="sd"> :mf: A list with the membership functions to be used</span>
<span class="sd"> :transformation: a transformation to be used in partitioner</span>
<span class="sd"> :size: list, the size of the output image [width, height]</span>
<span class="sd"> :save: boolean, if the image will be saved on disk</span>
<span class="sd"> :file: string, the file path to save the image</span>
<span class="sd"> :return: the list of the built partitioners</span>
<span class="sd"> &quot;&quot;&quot;</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="n">methods</span> <span class="o">=</span> <span class="n">all_methods</span>
<span class="k">if</span> <span class="n">mf</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">mf</span> <span class="o">=</span> <span class="n">mfs</span>
<span class="n">objs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">methods</span><span class="p">:</span>
<span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">mf</span><span class="p">:</span>
<span class="n">obj</span> <span class="o">=</span> <span class="n">p</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">npart</span><span class="p">,</span> <span class="n">func</span><span class="o">=</span><span class="n">m</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">obj</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">name</span> <span class="o">+</span> <span class="s2">&quot; - &quot;</span> <span class="o">+</span> <span class="n">obj</span><span class="o">.</span><span class="n">membership_function</span><span class="o">.</span><span class="vm">__name__</span>
<span class="n">objs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>
<span class="n">plot_partitioners</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">objs</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">save</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span>
<span class="k">return</span> <span class="n">objs</span></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.partitioners.Util</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,131 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.partitioners.parallel_util &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.partitioners.parallel_util</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.partitioners.parallel_util</h1><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">copy</span> <span class="kn">import</span> <span class="n">deepcopy</span>
<span class="kn">from</span> <span class="nn">joblib</span> <span class="kn">import</span> <span class="n">Parallel</span><span class="p">,</span> <span class="n">delayed</span>
<span class="kn">import</span> <span class="nn">multiprocessing</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.common</span> <span class="kn">import</span> <span class="n">Membership</span><span class="p">,</span> <span class="n">Util</span>
<span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="kn">import</span> <span class="n">Grid</span><span class="p">,</span><span class="n">Huarng</span><span class="p">,</span><span class="n">FCM</span><span class="p">,</span><span class="n">Entropy</span>
<span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="kn">import</span> <span class="n">Util</span>
<div class="viewcode-block" id="explore_partitioners"><a class="viewcode-back" href="../../../pyFTS.partitioners.html#pyFTS.partitioners.parallel_util.explore_partitioners">[docs]</a><span class="k">def</span> <span class="nf">explore_partitioners</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">npart</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">mf</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">12</span><span class="p">,</span> <span class="mi">10</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">all_methods</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">mfs</span> <span class="o">=</span> <span class="p">[</span><span class="n">Membership</span><span class="o">.</span><span class="n">trimf</span><span class="p">,</span> <span class="n">Membership</span><span class="o">.</span><span class="n">gaussmf</span><span class="p">,</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trapmf</span><span class="p">]</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="n">methods</span> <span class="o">=</span> <span class="n">all_methods</span>
<span class="k">if</span> <span class="n">mf</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">mf</span> <span class="o">=</span> <span class="n">mfs</span>
<span class="n">num_cores</span> <span class="o">=</span> <span class="n">multiprocessing</span><span class="o">.</span><span class="n">cpu_count</span><span class="p">()</span>
<span class="n">objs</span> <span class="o">=</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="nb">print</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">method</span><span class="p">))</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">Parallel</span><span class="p">(</span><span class="n">n_jobs</span><span class="o">=</span><span class="n">num_cores</span><span class="p">)(</span><span class="n">delayed</span><span class="p">(</span><span class="n">method</span><span class="p">)(</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">data</span><span class="p">),</span> <span class="n">npart</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span> <span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">mf</span><span class="p">)</span>
<span class="n">objs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>
<span class="n">objs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ravel</span><span class="p">(</span><span class="n">objs</span><span class="p">)</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
<span class="n">Util</span><span class="o">.</span><span class="n">plot_partitioners</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">objs</span><span class="p">,</span> <span class="n">tam</span><span class="p">,</span> <span class="n">save</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.partitioners.parallel_util</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,462 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.probabilistic.ProbabilityDistribution &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.probabilistic.ProbabilityDistribution</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.probabilistic.ProbabilityDistribution</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</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">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span><span class="n">SortedCollection</span><span class="p">,</span><span class="n">tree</span>
<span class="kn">from</span> <span class="nn">pyFTS.probabilistic</span> <span class="kn">import</span> <span class="n">kde</span>
<div class="viewcode-block" id="from_point"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.from_point">[docs]</a><span class="k">def</span> <span class="nf">from_point</span><span class="p">(</span><span class="n">x</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"> Create a probability distribution from a scalar value</span>
<span class="sd"> :param x: scalar value</span>
<span class="sd"> :param kwargs: common parameters of the distribution</span>
<span class="sd"> :return: the ProbabilityDistribution object</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">ProbabilityDistribution</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
<span class="k">return</span> <span class="n">tmp</span></div>
<div class="viewcode-block" id="ProbabilityDistribution"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution">[docs]</a><span class="k">class</span> <span class="nc">ProbabilityDistribution</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Represents a discrete or continous probability distribution</span>
<span class="sd"> If type is histogram, the PDF is discrete</span>
<span class="sd"> If type is KDE the PDF is continuous</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">type</span> <span class="o">=</span> <span class="s2">&quot;KDE&quot;</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">uod</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;uod&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;Universe of discourse&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">data</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;data&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="nb">type</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> If type is histogram, the PDF is discrete</span>
<span class="sd"> If type is KDE the PDF is continuous</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">bins</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;bins&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;Number of bins on a discrete PDF&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">labels</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;bins_labels&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;Bins labels on a discrete PDF&quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;KDE&quot;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">kde</span> <span class="o">=</span> <span class="n">kde</span><span class="o">.</span><span class="n">KernelSmoothing</span><span class="p">(</span><span class="n">h</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;h&quot;</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span> <span class="n">kernel</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;kernel&quot;</span><span class="p">,</span> <span class="s2">&quot;epanechnikov&quot;</span><span class="p">))</span>
<span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">uod</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">_min</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmin</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">_min</span> <span class="o">=</span> <span class="n">_min</span> <span class="o">*</span> <span class="o">.</span><span class="mi">7</span> <span class="k">if</span> <span class="n">_min</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="n">_min</span> <span class="o">*</span> <span class="mf">1.3</span>
<span class="n">_max</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmax</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">_max</span> <span class="o">=</span> <span class="n">_max</span> <span class="o">*</span> <span class="mf">1.3</span> <span class="k">if</span> <span class="n">_max</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="n">_max</span> <span class="o">*</span> <span class="o">.</span><span class="mi">7</span>
<span class="bp">self</span><span class="o">.</span><span class="n">uod</span> <span class="o">=</span> <span class="p">[</span><span class="n">_min</span><span class="p">,</span> <span class="n">_max</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">nbins</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;num_bins&quot;</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">bins</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">uod</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">uod</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nbins</span><span class="p">))</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">labels</span> <span class="o">=</span> <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">]</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">uod</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">resolution</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">uod</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">uod</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">nbins</span>
<span class="bp">self</span><span class="o">.</span><span class="n">bin_index</span> <span class="o">=</span> <span class="n">SortedCollection</span><span class="o">.</span><span class="n">SortedCollection</span><span class="p">(</span><span class="n">iterable</span><span class="o">=</span><span class="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">quantile_index</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">distribution</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cdf</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">qtl</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</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;name&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
<div class="viewcode-block" id="ProbabilityDistribution.set"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.set">[docs]</a> <span class="k">def</span> <span class="nf">set</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">density</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Assert a probability &#39;density&#39; for a certain value &#39;value&#39;, such that P(value) = density</span>
<span class="sd"> :param value: A value in the universe of discourse from the distribution</span>
<span class="sd"> :param density: The probability density to assign to the value</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">k</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bin_index</span><span class="o">.</span><span class="n">find_ge</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">density</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.append"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.append">[docs]</a> <span class="k">def</span> <span class="nf">append</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">values</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Increment the frequency count for the values</span>
<span class="sd"> :param values: A list of values to account the frequency</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;histogram&quot;</span><span class="p">:</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">values</span><span class="p">:</span>
<span class="n">v</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bin_index</span><span class="o">.</span><span class="n">find_ge</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">distribution</span> <span class="o">=</span> <span class="p">{}</span>
<span class="n">dens</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">)</span>
<span class="k">for</span> <span class="n">v</span><span class="p">,</span><span class="n">d</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">dens</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">[</span><span class="n">v</span><span class="p">]]</span> <span class="o">=</span> <span class="n">d</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.append_interval"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.append_interval">[docs]</a> <span class="k">def</span> <span class="nf">append_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">intervals</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Increment the frequency count for all values inside an interval</span>
<span class="sd"> :param intervals: A list of intervals do increment the frequency</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;histogram&quot;</span><span class="p">:</span>
<span class="k">for</span> <span class="n">interval</span> <span class="ow">in</span> <span class="n">intervals</span><span class="p">:</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bin_index</span><span class="o">.</span><span class="n">inside</span><span class="p">(</span><span class="n">interval</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">interval</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">distribution</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="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.density"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.density">[docs]</a> <span class="k">def</span> <span class="nf">density</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">values</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return the probability densities for the input values</span>
<span class="sd"> :param values: List of values to return the densities</span>
<span class="sd"> :return: List of probability densities for the input values</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">scalar</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">values</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
<span class="n">values</span> <span class="o">=</span> <span class="p">[</span><span class="n">values</span><span class="p">]</span>
<span class="n">scalar</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">values</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;histogram&quot;</span><span class="p">:</span>
<span class="n">v</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bin_index</span><span class="o">.</span><span class="n">find_ge</span><span class="p">(</span><span class="n">k</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="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">/</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">+</span> <span class="mf">1e-5</span><span class="p">))</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;KDE&quot;</span><span class="p">:</span>
<span class="n">v</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">kde</span><span class="o">.</span><span class="n">probability</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">data</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">v</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">v</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bin_index</span><span class="o">.</span><span class="n">find_ge</span><span class="p">(</span><span class="n">k</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="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">v</span><span class="p">])</span>
<span class="k">if</span> <span class="n">scalar</span><span class="p">:</span>
<span class="k">return</span> <span class="n">ret</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.differential_offset"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.differential_offset">[docs]</a> <span class="k">def</span> <span class="nf">differential_offset</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Auxiliary function for probability distributions of differentiated data</span>
<span class="sd"> :param value:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">nbins</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">dist</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">:</span>
<span class="n">nk</span> <span class="o">=</span> <span class="n">k</span><span class="o">+</span><span class="n">value</span>
<span class="n">nbins</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">nk</span><span class="p">)</span>
<span class="n">dist</span><span class="p">[</span><span class="n">nk</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">bins</span> <span class="o">=</span> <span class="n">nbins</span>
<span class="bp">self</span><span class="o">.</span><span class="n">distribution</span> <span class="o">=</span> <span class="n">dist</span>
<span class="bp">self</span><span class="o">.</span><span class="n">labels</span> <span class="o">=</span> <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">bin_index</span> <span class="o">=</span> <span class="n">SortedCollection</span><span class="o">.</span><span class="n">SortedCollection</span><span class="p">(</span><span class="n">iterable</span><span class="o">=</span><span class="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">quantile_index</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cdf</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">qtl</span> <span class="o">=</span> <span class="kc">None</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.expected_value"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.expected_value">[docs]</a> <span class="k">def</span> <span class="nf">expected_value</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return the expected value of the distribution, as E[X] = ∑ x * P(x)</span>
<span class="sd"> :return: The expected value of the distribution</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">([</span><span class="n">v</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">])</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.build_cdf_qtl"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.build_cdf_qtl">[docs]</a> <span class="k">def</span> <span class="nf">build_cdf_qtl</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cdf</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">qtl</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
<span class="k">if</span> <span class="n">k</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">cdf</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cdf</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">ret</span>
<span class="k">if</span> <span class="nb">str</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">qtl</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">qtl</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">ret</span><span class="p">)]</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">qtl</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">ret</span><span class="p">)]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
<span class="n">_keys</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">qtl</span><span class="o">.</span><span class="n">keys</span><span class="p">())]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">quantile_index</span> <span class="o">=</span> <span class="n">SortedCollection</span><span class="o">.</span><span class="n">SortedCollection</span><span class="p">(</span><span class="n">iterable</span><span class="o">=</span><span class="n">_keys</span><span class="p">)</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.cumulative"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.cumulative">[docs]</a> <span class="k">def</span> <span class="nf">cumulative</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">values</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return the cumulative probability densities for the input values,</span>
<span class="sd"> such that F(x) = P(X &lt;= x)</span>
<span class="sd"> :param values: A list of input values</span>
<span class="sd"> :return: The cumulative probability densities for the input values</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">cdf</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">build_cdf_qtl</span><span class="p">()</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">values</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">values</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">k</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bin_index</span><span class="o">.</span><span class="n">find_ge</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
<span class="c1">#ret.append(self.cdf[k])</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cdf</span><span class="p">[</span><span class="n">val</span><span class="p">])</span>
<span class="k">except</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">np</span><span class="o">.</span><span class="n">nan</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">k</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bin_index</span><span class="o">.</span><span class="n">find_ge</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">cdf</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>
<span class="k">except</span><span class="p">:</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.quantile"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.quantile">[docs]</a> <span class="k">def</span> <span class="nf">quantile</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">values</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return the Universe of Discourse values in relation to the quantile input values,</span>
<span class="sd"> such that Q(tau) = min( {x | F(x) &gt;= tau })</span>
<span class="sd"> :param values: input values</span>
<span class="sd"> :return: The list of the quantile values for the input values</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">qtl</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">build_cdf_qtl</span><span class="p">()</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">values</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">values</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">k</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">quantile_index</span><span class="o">.</span><span class="n">find_ge</span><span class="p">(</span><span class="n">val</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="bp">self</span><span class="o">.</span><span class="n">qtl</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">k</span><span class="p">)][</span><span class="mi">0</span><span class="p">])</span>
<span class="k">except</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">np</span><span class="o">.</span><span class="n">nan</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">k</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">quantile_index</span><span class="o">.</span><span class="n">find_ge</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">qtl</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">k</span><span class="p">)]</span>
<span class="k">except</span><span class="p">:</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.entropy"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.entropy">[docs]</a> <span class="k">def</span> <span class="nf">entropy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return the entropy of the probability distribution, H(P) = E[ -ln P(X) ] = - ∑ P(x) log ( P(x) )</span>
<span class="sd"> :return:the entropy of the probability distribution</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">h</span> <span class="o">=</span> <span class="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">])</span>
<span class="k">return</span> <span class="n">h</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.crossentropy"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.crossentropy">[docs]</a> <span class="k">def</span> <span class="nf">crossentropy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">q</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Cross entropy between the actual probability distribution and the informed one, </span>
<span class="sd"> H(P,Q) = - ∑ P(x) log ( Q(x) )</span>
<span class="sd"> :param q: a probabilistic.ProbabilityDistribution object</span>
<span class="sd"> :return: Cross entropy between this probability distribution and the given distribution</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">h</span> <span class="o">=</span> <span class="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">q</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">])</span>
<span class="k">return</span> <span class="n">h</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.kullbackleiblerdivergence"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.kullbackleiblerdivergence">[docs]</a> <span class="k">def</span> <span class="nf">kullbackleiblerdivergence</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">q</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Kullback-Leibler divergence between the actual probability distribution and the informed one.</span>
<span class="sd"> DKL(P || Q) = - ∑ P(x) log( P(X) / Q(x) )</span>
<span class="sd"> :param q: a probabilistic.ProbabilityDistribution object</span>
<span class="sd"> :return: Kullback-Leibler divergence</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">h</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">/</span><span class="n">q</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">])</span>
<span class="k">return</span> <span class="n">h</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.empiricalloglikelihood"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.empiricalloglikelihood">[docs]</a> <span class="k">def</span> <span class="nf">empiricalloglikelihood</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Empirical Log Likelihood of the probability distribution, L(P) = ∑ log( P(x) )</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">_s</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">_s</span> <span class="o">+=</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
<span class="k">return</span> <span class="n">_s</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.pseudologlikelihood"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.pseudologlikelihood">[docs]</a> <span class="k">def</span> <span class="nf">pseudologlikelihood</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Pseudo log likelihood of the probability distribution with respect to data</span>
<span class="sd"> :param data:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">densities</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">_s</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">densities</span><span class="p">:</span>
<span class="k">if</span> <span class="n">k</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">_s</span> <span class="o">+=</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
<span class="k">return</span> <span class="n">_s</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.averageloglikelihood"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.averageloglikelihood">[docs]</a> <span class="k">def</span> <span class="nf">averageloglikelihood</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Average log likelihood of the probability distribution with respect to data</span>
<span class="sd"> :param data:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">densities</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">_s</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">densities</span><span class="p">:</span>
<span class="k">if</span> <span class="n">k</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">_s</span> <span class="o">+=</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
<span class="k">return</span> <span class="n">_s</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.plot"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.plot">[docs]</a> <span class="k">def</span> <span class="nf">plot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="kc">None</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">tam</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span> <span class="mi">6</span><span class="p">],</span> <span class="n">title</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span>
<span class="k">if</span> <span class="n">axis</span> <span class="ow">is</span> <span class="kc">None</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">axis</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">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;histogram&quot;</span><span class="p">:</span>
<span class="n">ys</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ys</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">]</span>
<span class="n">yp</span> <span class="o">=</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="bp">self</span><span class="o">.</span><span class="n">data</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="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">,</span> <span class="n">yp</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="s2">&quot;red&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">title</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">title</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span>
<span class="n">axis</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">,</span> <span class="n">ys</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="n">color</span><span class="p">)</span>
<span class="n">axis</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">axis</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;Universe of Discourse&#39;</span><span class="p">)</span>
<span class="n">axis</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Probability&#39;</span><span class="p">)</span></div>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">):</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">k</span><span class="p">,</span><span class="mi">2</span><span class="p">))</span> <span class="o">+</span> <span class="s1">&#39;:</span><span class="se">\t</span><span class="s1">&#39;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;histogram&quot;</span><span class="p">:</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="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;KDE&quot;</span><span class="p">:</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="bp">self</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">k</span><span class="p">),</span><span class="mi">3</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</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="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="mi">6</span><span class="p">))</span>
<span class="n">ret</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span>
<span class="k">return</span> <span class="n">ret</span></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.probabilistic.ProbabilityDistribution</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -0,0 +1,169 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55120145-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>pyFTS.probabilistic.kde &#8212; pyFTS 1.6 documentation</title>
<link rel="stylesheet" href="../../../_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script 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 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.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.probabilistic.kde</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.probabilistic.kde</h1><div class="highlight"><pre>
<span></span><span class="c1"># -*- coding: utf8 -*-</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Kernel Density Estimation </span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">Transformations</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<div class="viewcode-block" id="KernelSmoothing"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.kde.KernelSmoothing">[docs]</a><span class="k">class</span> <span class="nc">KernelSmoothing</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Kernel Density Estimation&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">h</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;h&#39;</span><span class="p">,</span><span class="o">.</span><span class="mi">5</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;Width parameter&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">kernel</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;kernel&quot;</span><span class="p">,</span> <span class="s2">&quot;epanechnikov&quot;</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;Kernel function&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">data</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;data&quot;</span><span class="p">,</span><span class="kc">None</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transf</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="nb">min</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="nb">max</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">transf</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">)</span>
<div class="viewcode-block" id="KernelSmoothing.kernel_function"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.kde.KernelSmoothing.kernel_function">[docs]</a> <span class="k">def</span> <span class="nf">kernel_function</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">u</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Apply the kernel</span>
<span class="sd"> :param u:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel</span> <span class="o">==</span> <span class="s2">&quot;epanechnikov&quot;</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="p">(</span><span class="mi">3</span><span class="o">/</span><span class="mi">4</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">u</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="k">return</span> <span class="n">tmp</span> <span class="k">if</span> <span class="n">tmp</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel</span> <span class="o">==</span> <span class="s2">&quot;gaussian&quot;</span><span class="p">:</span>
<span class="k">return</span> <span class="p">(</span><span class="mf">1.0</span><span class="o">/</span><span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">))</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="mf">0.5</span><span class="o">*</span><span class="n">u</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel</span> <span class="o">==</span> <span class="s2">&quot;uniform&quot;</span><span class="p">:</span>
<span class="k">return</span> <span class="mf">0.5</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel</span> <span class="o">==</span> <span class="s2">&quot;triangular&quot;</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="mf">1.0</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">u</span><span class="p">)</span>
<span class="k">return</span> <span class="n">tmp</span> <span class="k">if</span> <span class="n">tmp</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel</span> <span class="o">==</span> <span class="s2">&quot;logistic&quot;</span><span class="p">:</span>
<span class="k">return</span> <span class="mf">1.0</span><span class="o">/</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">u</span><span class="p">)</span><span class="o">+</span><span class="mi">2</span><span class="o">+</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">u</span><span class="p">))</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel</span> <span class="o">==</span> <span class="s2">&quot;cosine&quot;</span><span class="p">:</span>
<span class="k">return</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="o">/</span><span class="mf">4.0</span><span class="p">)</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">((</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="o">/</span><span class="mf">2.0</span><span class="p">)</span><span class="o">*</span><span class="n">u</span><span class="p">)</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel</span> <span class="o">==</span> <span class="s2">&quot;sigmoid&quot;</span><span class="p">:</span>
<span class="k">return</span> <span class="p">(</span><span class="mf">2.0</span><span class="o">/</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="mf">1.0</span><span class="o">/</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">u</span><span class="p">)</span><span class="o">+</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">u</span><span class="p">)))</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel</span> <span class="o">==</span> <span class="s2">&quot;tophat&quot;</span><span class="p">:</span>
<span class="k">return</span> <span class="mi">1</span> <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">u</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mf">0.5</span> <span class="k">else</span> <span class="mi">0</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel</span> <span class="o">==</span> <span class="s2">&quot;exponential&quot;</span><span class="p">:</span>
<span class="k">return</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">u</span><span class="p">))</span></div>
<div class="viewcode-block" id="KernelSmoothing.probability"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.kde.KernelSmoothing.probability">[docs]</a> <span class="k">def</span> <span class="nf">probability</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</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"> Probability of the point x on data</span>
<span class="sd"> :param x:</span>
<span class="sd"> :param data:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">data</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;data&#39;</span><span class="p">,</span><span class="kc">None</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">transf</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</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="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">)</span>
<span class="n">nx</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">transf</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="n">p</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">kernel_function</span><span class="p">((</span><span class="n">nx</span> <span class="o">-</span> <span class="n">k</span><span class="p">)</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">h</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">])</span> <span class="o">/</span> <span class="n">l</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">h</span>
<span class="k">return</span> <span class="n">p</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.6 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.probabilistic.kde</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
</div>
</body>
</html>

View File

@ -52,14 +52,6 @@ pyFTS.common.SortedCollection module
:undoc-members:
:show-inheritance:
pyFTS.common.transformations module
-----------------------------------
.. automodule:: pyFTS.common.Transformations
:members:
:undoc-members:
:show-inheritance:
pyFTS.common.Util module
------------------------

View File

@ -60,6 +60,14 @@ pyFTS.common.transformations.scale module
:undoc-members:
:show-inheritance:
pyFTS.common.transformations.smoothing module
---------------------------------------------
.. automodule:: pyFTS.common.transformations.smoothing
:members:
:undoc-members:
:show-inheritance:
pyFTS.common.transformations.som module
---------------------------------------

File diff suppressed because it is too large Load Diff

View File

@ -70,17 +70,17 @@
<li class="toctree-l3"><a class="reference internal" href="pyFTS.benchmarks.html">pyFTS.benchmarks package</a><ul>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks">Module contents</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#submodules">Submodules</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-benchmarks-module">pyFTS.benchmarks.benchmarks module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-measures-module">pyFTS.benchmarks.Measures module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-residualanalysis-module">pyFTS.benchmarks.ResidualAnalysis module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-tests-module">pyFTS.benchmarks.Tests module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-util-module">pyFTS.benchmarks.Util module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-arima-module">pyFTS.benchmarks.arima module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-knn-module">pyFTS.benchmarks.knn module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-naive-module">pyFTS.benchmarks.naive module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-quantreg-module">pyFTS.benchmarks.quantreg module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.benchmarks">pyFTS.benchmarks.benchmarks module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.Measures">pyFTS.benchmarks.Measures module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.ResidualAnalysis">pyFTS.benchmarks.ResidualAnalysis module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.Tests">pyFTS.benchmarks.Tests module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.Util">pyFTS.benchmarks.Util module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.arima">pyFTS.benchmarks.arima module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.knn">pyFTS.benchmarks.knn module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.naive">pyFTS.benchmarks.naive module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.quantreg">pyFTS.benchmarks.quantreg module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-gaussianproc-module">pyFTS.benchmarks.gaussianproc module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-bsts-module">pyFTS.benchmarks.BSTS module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.BSTS">pyFTS.benchmarks.BSTS module</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="pyFTS.common.html">pyFTS.common package</a><ul>
@ -91,10 +91,9 @@
<li class="toctree-l4"><a class="reference internal" href="pyFTS.common.html#module-pyFTS.common.FuzzySet">pyFTS.common.FuzzySet module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.common.html#module-pyFTS.common.Membership">pyFTS.common.Membership module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.common.html#module-pyFTS.common.SortedCollection">pyFTS.common.SortedCollection module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.common.html#pyfts-common-transformations-module">pyFTS.common.transformations module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.common.html#pyfts-common-util-module">pyFTS.common.Util module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.common.html#module-pyFTS.common.Util">pyFTS.common.Util module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.common.html#module-pyFTS.common.flrg">pyFTS.common.flrg module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.common.html#pyfts-common-fts-module">pyFTS.common.fts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.common.html#module-pyFTS.common.fts">pyFTS.common.fts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.common.html#module-pyFTS.common.tree">pyFTS.common.tree module</a></li>
</ul>
</li>
@ -107,6 +106,7 @@
<li class="toctree-l4"><a class="reference internal" href="pyFTS.common.transformations.html#pyfts-common-transformations-normalization-module">pyFTS.common.transformations.normalization module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.common.transformations.html#pyfts-common-transformations-roi-module">pyFTS.common.transformations.roi module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.common.transformations.html#pyfts-common-transformations-scale-module">pyFTS.common.transformations.scale module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.common.transformations.html#pyfts-common-transformations-smoothing-module">pyFTS.common.transformations.smoothing module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.common.transformations.html#pyfts-common-transformations-som-module">pyFTS.common.transformations.som module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.common.transformations.html#pyfts-common-transformations-transformation-module">pyFTS.common.transformations.transformation module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.common.transformations.html#pyfts-common-transformations-trend-module">pyFTS.common.transformations.trend module</a></li>
@ -143,7 +143,7 @@
<li class="toctree-l3"><a class="reference internal" href="pyFTS.distributed.html">pyFTS.distributed package</a><ul>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.distributed.html#module-pyFTS.distributed">Module contents</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.distributed.html#submodules">Submodules</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.distributed.html#pyfts-distributed-dispy-module">pyFTS.distributed.dispy module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.distributed.html#module-pyFTS.distributed.dispy">pyFTS.distributed.dispy module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.distributed.html#pyfts-distributed-spark-module">pyFTS.distributed.spark module</a></li>
</ul>
</li>
@ -151,8 +151,8 @@
<li class="toctree-l4"><a class="reference internal" href="pyFTS.hyperparam.html#module-pyFTS.hyperparam">Module contents</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.hyperparam.html#submodules">Submodules</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.hyperparam.html#module-pyFTS.hyperparam.Util">pyFTS.hyperparam.Util module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.hyperparam.html#pyfts-hyperparam-gridsearch-module">pyFTS.hyperparam.GridSearch module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.hyperparam.html#pyfts-hyperparam-evolutionary-module">pyFTS.hyperparam.Evolutionary module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.hyperparam.html#module-pyFTS.hyperparam.GridSearch">pyFTS.hyperparam.GridSearch module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.hyperparam.html#module-pyFTS.hyperparam.Evolutionary">pyFTS.hyperparam.Evolutionary module</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="pyFTS.models.html">pyFTS.models package</a><ul>
@ -166,16 +166,16 @@
</ul>
</li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#submodules">Submodules</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#pyfts-models-song-module">pyFTS.models.song module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#pyfts-models-chen-module">pyFTS.models.chen module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#pyfts-models-yu-module">pyFTS.models.yu module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#pyfts-models-cheng-module">pyFTS.models.cheng module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#pyfts-models-hofts-module">pyFTS.models.hofts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#pyfts-models-hwang-module">pyFTS.models.hwang module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#pyfts-models-ifts-module">pyFTS.models.ifts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#pyfts-models-ismailefendi-module">pyFTS.models.ismailefendi module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#pyfts-models-pwfts-module">pyFTS.models.pwfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#pyfts-models-sadaei-module">pyFTS.models.sadaei module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.song">pyFTS.models.song module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.chen">pyFTS.models.chen module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.yu">pyFTS.models.yu module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.cheng">pyFTS.models.cheng module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.hofts">pyFTS.models.hofts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.hwang">pyFTS.models.hwang module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.ifts">pyFTS.models.ifts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.ismailefendi">pyFTS.models.ismailefendi module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.pwfts">pyFTS.models.pwfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.sadaei">pyFTS.models.sadaei module</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="pyFTS.partitioners.html">pyFTS.partitioners package</a><ul>
@ -186,19 +186,19 @@
<li class="toctree-l4"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.Entropy">pyFTS.partitioners.Entropy module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.FCM">pyFTS.partitioners.FCM module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.Grid">pyFTS.partitioners.Grid module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.partitioners.html#pyfts-partitioners-huarng-module">pyFTS.partitioners.Huarng module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.Huarng">pyFTS.partitioners.Huarng module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.Singleton">pyFTS.partitioners.Singleton module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.Simple">pyFTS.partitioners.Simple module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.SubClust">pyFTS.partitioners.SubClust module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.partitioners.html#pyfts-partitioners-util-module">pyFTS.partitioners.Util module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.partitioners.html#pyfts-partitioners-parallel-util-module">pyFTS.partitioners.parallel_util module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.Util">pyFTS.partitioners.Util module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.parallel_util">pyFTS.partitioners.parallel_util module</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="pyFTS.probabilistic.html">pyFTS.probabilistic package</a><ul>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.probabilistic.html#module-pyFTS.probabilistic">Module contents</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.probabilistic.html#submodules">Submodules</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.probabilistic.html#pyfts-probabilistic-probabilitydistribution-module">pyFTS.probabilistic.ProbabilityDistribution module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.probabilistic.html#pyfts-probabilistic-kde-module">pyFTS.probabilistic.kde module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.probabilistic.html#module-pyFTS.probabilistic.ProbabilityDistribution">pyFTS.probabilistic.ProbabilityDistribution module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.probabilistic.html#module-pyFTS.probabilistic.kde">pyFTS.probabilistic.kde module</a></li>
</ul>
</li>
</ul>

Binary file not shown.

View File

@ -78,6 +78,56 @@
<td>&#160;&#160;&#160;
<a href="pyFTS.benchmarks.html#module-pyFTS.benchmarks"><code class="xref">pyFTS.benchmarks</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.arima"><code class="xref">pyFTS.benchmarks.arima</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.benchmarks"><code class="xref">pyFTS.benchmarks.benchmarks</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.BSTS"><code class="xref">pyFTS.benchmarks.BSTS</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.knn"><code class="xref">pyFTS.benchmarks.knn</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.Measures"><code class="xref">pyFTS.benchmarks.Measures</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.naive"><code class="xref">pyFTS.benchmarks.naive</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.quantreg"><code class="xref">pyFTS.benchmarks.quantreg</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.ResidualAnalysis"><code class="xref">pyFTS.benchmarks.ResidualAnalysis</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.Tests"><code class="xref">pyFTS.benchmarks.Tests</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.Util"><code class="xref">pyFTS.benchmarks.Util</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
@ -98,6 +148,11 @@
<td>&#160;&#160;&#160;
<a href="pyFTS.common.html#module-pyFTS.common.flrg"><code class="xref">pyFTS.common.flrg</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.common.html#module-pyFTS.common.fts"><code class="xref">pyFTS.common.fts</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
@ -118,6 +173,11 @@
<td>&#160;&#160;&#160;
<a href="pyFTS.common.html#module-pyFTS.common.tree"><code class="xref">pyFTS.common.tree</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.common.html#module-pyFTS.common.Util"><code class="xref">pyFTS.common.Util</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
@ -243,11 +303,26 @@
<td>&#160;&#160;&#160;
<a href="pyFTS.distributed.html#module-pyFTS.distributed"><code class="xref">pyFTS.distributed</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.distributed.html#module-pyFTS.distributed.dispy"><code class="xref">pyFTS.distributed.dispy</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.hyperparam.html#module-pyFTS.hyperparam"><code class="xref">pyFTS.hyperparam</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.hyperparam.html#module-pyFTS.hyperparam.Evolutionary"><code class="xref">pyFTS.hyperparam.Evolutionary</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.hyperparam.html#module-pyFTS.hyperparam.GridSearch"><code class="xref">pyFTS.hyperparam.GridSearch</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
@ -258,21 +333,76 @@
<td>&#160;&#160;&#160;
<a href="pyFTS.models.html#module-pyFTS.models"><code class="xref">pyFTS.models</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.html#module-pyFTS.models.chen"><code class="xref">pyFTS.models.chen</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.html#module-pyFTS.models.cheng"><code class="xref">pyFTS.models.cheng</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.ensemble.html#module-pyFTS.models.ensemble"><code class="xref">pyFTS.models.ensemble</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.ensemble.html#module-pyFTS.models.ensemble.ensemble"><code class="xref">pyFTS.models.ensemble.ensemble</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.ensemble.html#module-pyFTS.models.ensemble.multiseasonal"><code class="xref">pyFTS.models.ensemble.multiseasonal</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.html#module-pyFTS.models.hofts"><code class="xref">pyFTS.models.hofts</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.html#module-pyFTS.models.hwang"><code class="xref">pyFTS.models.hwang</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.html#module-pyFTS.models.ifts"><code class="xref">pyFTS.models.ifts</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.incremental.html#module-pyFTS.models.incremental"><code class="xref">pyFTS.models.incremental</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.incremental.html#module-pyFTS.models.incremental.IncrementalEnsemble"><code class="xref">pyFTS.models.incremental.IncrementalEnsemble</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.incremental.html#module-pyFTS.models.incremental.TimeVariant"><code class="xref">pyFTS.models.incremental.TimeVariant</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.html#module-pyFTS.models.ismailefendi"><code class="xref">pyFTS.models.ismailefendi</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.multivariate.html#module-pyFTS.models.multivariate"><code class="xref">pyFTS.models.multivariate</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.multivariate.html#module-pyFTS.models.multivariate.cmvfts"><code class="xref">pyFTS.models.multivariate.cmvfts</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
@ -288,16 +418,36 @@
<td>&#160;&#160;&#160;
<a href="pyFTS.models.multivariate.html#module-pyFTS.models.multivariate.flrg"><code class="xref">pyFTS.models.multivariate.flrg</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.multivariate.html#module-pyFTS.models.multivariate.granular"><code class="xref">pyFTS.models.multivariate.granular</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.multivariate.html#module-pyFTS.models.multivariate.grid"><code class="xref">pyFTS.models.multivariate.grid</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.multivariate.html#module-pyFTS.models.multivariate.mvfts"><code class="xref">pyFTS.models.multivariate.mvfts</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.multivariate.html#module-pyFTS.models.multivariate.partitioner"><code class="xref">pyFTS.models.multivariate.partitioner</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.multivariate.html#module-pyFTS.models.multivariate.variable"><code class="xref">pyFTS.models.multivariate.variable</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.multivariate.html#module-pyFTS.models.multivariate.wmvfts"><code class="xref">pyFTS.models.multivariate.wmvfts</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
@ -308,11 +458,26 @@
<td>&#160;&#160;&#160;
<a href="pyFTS.models.nonstationary.html#module-pyFTS.models.nonstationary.common"><code class="xref">pyFTS.models.nonstationary.common</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.nonstationary.html#module-pyFTS.models.nonstationary.cvfts"><code class="xref">pyFTS.models.nonstationary.cvfts</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.nonstationary.html#module-pyFTS.models.nonstationary.flrg"><code class="xref">pyFTS.models.nonstationary.flrg</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.nonstationary.html#module-pyFTS.models.nonstationary.honsfts"><code class="xref">pyFTS.models.nonstationary.honsfts</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.nonstationary.html#module-pyFTS.models.nonstationary.nsfts"><code class="xref">pyFTS.models.nonstationary.nsfts</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
@ -323,16 +488,41 @@
<td>&#160;&#160;&#160;
<a href="pyFTS.models.nonstationary.html#module-pyFTS.models.nonstationary.perturbation"><code class="xref">pyFTS.models.nonstationary.perturbation</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.nonstationary.html#module-pyFTS.models.nonstationary.util"><code class="xref">pyFTS.models.nonstationary.util</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.html#module-pyFTS.models.pwfts"><code class="xref">pyFTS.models.pwfts</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.html#module-pyFTS.models.sadaei"><code class="xref">pyFTS.models.sadaei</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.seasonal.html#module-pyFTS.models.seasonal"><code class="xref">pyFTS.models.seasonal</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.seasonal.html#module-pyFTS.models.seasonal.cmsfts"><code class="xref">pyFTS.models.seasonal.cmsfts</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.seasonal.html#module-pyFTS.models.seasonal.common"><code class="xref">pyFTS.models.seasonal.common</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.seasonal.html#module-pyFTS.models.seasonal.msfts"><code class="xref">pyFTS.models.seasonal.msfts</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
@ -343,6 +533,21 @@
<td>&#160;&#160;&#160;
<a href="pyFTS.models.seasonal.html#module-pyFTS.models.seasonal.SeasonalIndexer"><code class="xref">pyFTS.models.seasonal.SeasonalIndexer</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.seasonal.html#module-pyFTS.models.seasonal.sfts"><code class="xref">pyFTS.models.seasonal.sfts</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.html#module-pyFTS.models.song"><code class="xref">pyFTS.models.song</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.models.html#module-pyFTS.models.yu"><code class="xref">pyFTS.models.yu</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
@ -368,6 +573,16 @@
<td>&#160;&#160;&#160;
<a href="pyFTS.partitioners.html#module-pyFTS.partitioners.Grid"><code class="xref">pyFTS.partitioners.Grid</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.partitioners.html#module-pyFTS.partitioners.Huarng"><code class="xref">pyFTS.partitioners.Huarng</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.partitioners.html#module-pyFTS.partitioners.parallel_util"><code class="xref">pyFTS.partitioners.parallel_util</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
@ -388,11 +603,26 @@
<td>&#160;&#160;&#160;
<a href="pyFTS.partitioners.html#module-pyFTS.partitioners.SubClust"><code class="xref">pyFTS.partitioners.SubClust</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.partitioners.html#module-pyFTS.partitioners.Util"><code class="xref">pyFTS.partitioners.Util</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.probabilistic.html#module-pyFTS.probabilistic"><code class="xref">pyFTS.probabilistic</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.probabilistic.html#module-pyFTS.probabilistic.kde"><code class="xref">pyFTS.probabilistic.kde</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.probabilistic.html#module-pyFTS.probabilistic.ProbabilityDistribution"><code class="xref">pyFTS.probabilistic.ProbabilityDistribution</code></a></td><td>
<em></em></td></tr>
</table>

File diff suppressed because it is too large Load Diff

View File

@ -762,11 +762,272 @@ bisect but with a simpler API and support for key functions.</p>
</dd></dl>
</div>
<div class="section" id="pyfts-common-transformations-module">
<h2>pyFTS.common.transformations module<a class="headerlink" href="#pyfts-common-transformations-module" title="Permalink to this headline"></a></h2>
</div>
<div class="section" id="pyfts-common-util-module">
<h2>pyFTS.common.Util module<a class="headerlink" href="#pyfts-common-util-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.common.Util">
<span id="pyfts-common-util-module"></span><h2>pyFTS.common.Util module<a class="headerlink" href="#module-pyFTS.common.Util" title="Permalink to this headline"></a></h2>
<p>Common facilities for pyFTS</p>
<dl class="py function">
<dt id="pyFTS.common.Util.current_milli_time">
<code class="sig-prename descclassname">pyFTS.common.Util.</code><code class="sig-name descname">current_milli_time</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pyFTS.common.Util.current_milli_time" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="pyFTS.common.Util.draw_sets_on_axis">
<code class="sig-prename descclassname">pyFTS.common.Util.</code><code class="sig-name descname">draw_sets_on_axis</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">axis</span></em>, <em class="sig-param"><span class="n">model</span></em>, <em class="sig-param"><span class="n">size</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/Util.html#draw_sets_on_axis"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.Util.draw_sets_on_axis" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="pyFTS.common.Util.enumerate2">
<code class="sig-prename descclassname">pyFTS.common.Util.</code><code class="sig-name descname">enumerate2</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">xs</span></em>, <em class="sig-param"><span class="n">start</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">step</span><span class="o">=</span><span class="default_value">1</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/Util.html#enumerate2"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.Util.enumerate2" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="pyFTS.common.Util.load_env">
<code class="sig-prename descclassname">pyFTS.common.Util.</code><code class="sig-name descname">load_env</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">file</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/Util.html#load_env"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.Util.load_env" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="pyFTS.common.Util.load_obj">
<code class="sig-prename descclassname">pyFTS.common.Util.</code><code class="sig-name descname">load_obj</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">file</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/Util.html#load_obj"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.Util.load_obj" title="Permalink to this definition"></a></dt>
<dd><p>Load to memory an object stored filesystem. This function depends on Dill package</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>file</strong> file name where the object is stored</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>object</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.common.Util.persist_env">
<code class="sig-prename descclassname">pyFTS.common.Util.</code><code class="sig-name descname">persist_env</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">file</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/Util.html#persist_env"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.Util.persist_env" title="Permalink to this definition"></a></dt>
<dd><p>Persist an entire environment on file. This function depends on Dill package</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>file</strong> file name to store the environment</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.common.Util.persist_obj">
<code class="sig-prename descclassname">pyFTS.common.Util.</code><code class="sig-name descname">persist_obj</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">obj</span></em>, <em class="sig-param"><span class="n">file</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/Util.html#persist_obj"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.Util.persist_obj" title="Permalink to this definition"></a></dt>
<dd><p>Persist an object on filesystem. This function depends on Dill package</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>obj</strong> object on memory</p></li>
<li><p><strong>file</strong> file name to store the object</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.common.Util.plot_compared_intervals_ahead">
<code class="sig-prename descclassname">pyFTS.common.Util.</code><code class="sig-name descname">plot_compared_intervals_ahead</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">original</span></em>, <em class="sig-param"><span class="n">models</span></em>, <em class="sig-param"><span class="n">colors</span></em>, <em class="sig-param"><span class="n">distributions</span></em>, <em class="sig-param"><span class="n">time_from</span></em>, <em class="sig-param"><span class="n">time_to</span></em>, <em class="sig-param"><span class="n">intervals</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="n">save</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">file</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">tam</span><span class="o">=</span><span class="default_value">[20, 5]</span></em>, <em class="sig-param"><span class="n">resolution</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">cmap</span><span class="o">=</span><span class="default_value">'Blues'</span></em>, <em class="sig-param"><span class="n">linewidth</span><span class="o">=</span><span class="default_value">1.5</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/Util.html#plot_compared_intervals_ahead"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.Util.plot_compared_intervals_ahead" title="Permalink to this definition"></a></dt>
<dd><p>Plot the forecasts of several one step ahead models, by point or by interval</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>original</strong> Original time series data (list)</p></li>
<li><p><strong>models</strong> List of models to compare</p></li>
<li><p><strong>colors</strong> List of models colors</p></li>
<li><p><strong>distributions</strong> True to plot a distribution</p></li>
<li><p><strong>time_from</strong> index of data poit to start the ahead forecasting</p></li>
<li><p><strong>time_to</strong> number of steps ahead to forecast</p></li>
<li><p><strong>interpol</strong> Fill space between distribution plots</p></li>
<li><p><strong>save</strong> Save the picture on file</p></li>
<li><p><strong>file</strong> Filename to save the picture</p></li>
<li><p><strong>tam</strong> Size of the picture</p></li>
<li><p><strong>resolution</strong> </p></li>
<li><p><strong>cmap</strong> Color map to be used on distribution plot</p></li>
<li><p><strong>option</strong> Distribution type to be passed for models</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.common.Util.plot_density_rectange">
<code class="sig-prename descclassname">pyFTS.common.Util.</code><code class="sig-name descname">plot_density_rectange</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ax</span></em>, <em class="sig-param"><span class="n">cmap</span></em>, <em class="sig-param"><span class="n">density</span></em>, <em class="sig-param"><span class="n">fig</span></em>, <em class="sig-param"><span class="n">resolution</span></em>, <em class="sig-param"><span class="n">time_from</span></em>, <em class="sig-param"><span class="n">time_to</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/Util.html#plot_density_rectange"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.Util.plot_density_rectange" title="Permalink to this definition"></a></dt>
<dd><p>Auxiliar function to plot_compared_intervals_ahead</p>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.common.Util.plot_distribution">
<code class="sig-prename descclassname">pyFTS.common.Util.</code><code class="sig-name descname">plot_distribution</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ax</span></em>, <em class="sig-param"><span class="n">cmap</span></em>, <em class="sig-param"><span class="n">probabilitydist</span></em>, <em class="sig-param"><span class="n">fig</span></em>, <em class="sig-param"><span class="n">time_from</span></em>, <em class="sig-param"><span class="n">reference_data</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/Util.html#plot_distribution"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.Util.plot_distribution" title="Permalink to this definition"></a></dt>
<dd><p>Plot forecasted ProbabilityDistribution objects on a matplotlib axis</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>ax</strong> matplotlib axis</p></li>
<li><p><strong>cmap</strong> matplotlib colormap name</p></li>
<li><p><strong>probabilitydist</strong> list of ProbabilityDistribution objects</p></li>
<li><p><strong>fig</strong> matplotlib figure</p></li>
<li><p><strong>time_from</strong> starting time (on x axis) to begin the plots</p></li>
<li><p><strong>reference_data</strong> </p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.common.Util.plot_distribution2">
<code class="sig-prename descclassname">pyFTS.common.Util.</code><code class="sig-name descname">plot_distribution2</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">probabilitydist</span></em>, <em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/Util.html#plot_distribution2"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.Util.plot_distribution2" title="Permalink to this definition"></a></dt>
<dd><p>Plot distributions in y-axis over the time (x-axis)</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>probabilitydist</strong> the forecasted probability distributions to plot</p></li>
<li><p><strong>data</strong> the original test sample</p></li>
<li><p><strong>start_at</strong> the time index (inside of data) to start to plot the probability distributions</p></li>
<li><p><strong>ax</strong> a matplotlib axis. If no value was provided a new axis is created.</p></li>
<li><p><strong>cmap</strong> a matplotlib colormap name, the default value is Blues</p></li>
<li><p><strong>quantiles</strong> the list of quantiles intervals to plot, e. g. [.05, .25, .75, .95]</p></li>
<li><p><strong>median</strong> a boolean value indicating if the median value will be plot.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.common.Util.plot_distribution_tiled">
<code class="sig-prename descclassname">pyFTS.common.Util.</code><code class="sig-name descname">plot_distribution_tiled</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">distributions</span></em>, <em class="sig-param"><span class="n">data</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">rows</span><span class="o">=</span><span class="default_value">5</span></em>, <em class="sig-param"><span class="n">cols</span><span class="o">=</span><span class="default_value">5</span></em>, <em class="sig-param"><span class="n">index</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">axis</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">size</span><span class="o">=</span><span class="default_value">[10, 20]</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/Util.html#plot_distribution_tiled"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.Util.plot_distribution_tiled" title="Permalink to this definition"></a></dt>
<dd><p>Plot one distribution individually in each axis, with probability in y-axis and UoD on x-axis</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>distributions</strong> </p></li>
<li><p><strong>data</strong> </p></li>
<li><p><strong>rows</strong> </p></li>
<li><p><strong>cols</strong> </p></li>
<li><p><strong>index</strong> </p></li>
<li><p><strong>axis</strong> </p></li>
<li><p><strong>size</strong> </p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.common.Util.plot_interval">
<code class="sig-prename descclassname">pyFTS.common.Util.</code><code class="sig-name descname">plot_interval</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">axis</span></em>, <em class="sig-param"><span class="n">intervals</span></em>, <em class="sig-param"><span class="n">order</span></em>, <em class="sig-param"><span class="n">label</span></em>, <em class="sig-param"><span class="n">color</span><span class="o">=</span><span class="default_value">'red'</span></em>, <em class="sig-param"><span class="n">typeonlegend</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">ls</span><span class="o">=</span><span class="default_value">'-'</span></em>, <em class="sig-param"><span class="n">linewidth</span><span class="o">=</span><span class="default_value">1</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/Util.html#plot_interval"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.Util.plot_interval" title="Permalink to this definition"></a></dt>
<dd><p>Plot forecasted intervals on matplotlib</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>axis</strong> matplotlib axis</p></li>
<li><p><strong>intervals</strong> list of forecasted intervals</p></li>
<li><p><strong>order</strong> order of the model that create the forecasts</p></li>
<li><p><strong>label</strong> figure label</p></li>
<li><p><strong>color</strong> matplotlib color name</p></li>
<li><p><strong>typeonlegend</strong> </p></li>
<li><p><strong>ls</strong> matplotlib line style</p></li>
<li><p><strong>linewidth</strong> matplotlib width</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.common.Util.plot_interval2">
<code class="sig-prename descclassname">pyFTS.common.Util.</code><code class="sig-name descname">plot_interval2</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">intervals</span></em>, <em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/Util.html#plot_interval2"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.Util.plot_interval2" title="Permalink to this definition"></a></dt>
<dd><p>Plot forecasted intervals on matplotlib</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>intervals</strong> list of forecasted intervals</p></li>
<li><p><strong>data</strong> the original test sample</p></li>
<li><p><strong>start_at</strong> the time index (inside of data) to start to plot the intervals</p></li>
<li><p><strong>label</strong> figure label</p></li>
<li><p><strong>color</strong> matplotlib color name</p></li>
<li><p><strong>typeonlegend</strong> </p></li>
<li><p><strong>ls</strong> matplotlib line style</p></li>
<li><p><strong>linewidth</strong> matplotlib width</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.common.Util.plot_probability_distributions">
<code class="sig-prename descclassname">pyFTS.common.Util.</code><code class="sig-name descname">plot_probability_distributions</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">pmfs</span></em>, <em class="sig-param"><span class="n">lcolors</span></em>, <em class="sig-param"><span class="n">tam</span><span class="o">=</span><span class="default_value">[15, 7]</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/Util.html#plot_probability_distributions"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.Util.plot_probability_distributions" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="pyFTS.common.Util.plot_rules">
<code class="sig-prename descclassname">pyFTS.common.Util.</code><code class="sig-name descname">plot_rules</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">model</span></em>, <em class="sig-param"><span class="n">size</span><span class="o">=</span><span class="default_value">[5, 5]</span></em>, <em class="sig-param"><span class="n">axis</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">rules_by_axis</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">columns</span><span class="o">=</span><span class="default_value">1</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/Util.html#plot_rules"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.Util.plot_rules" title="Permalink to this definition"></a></dt>
<dd><p>Plot the FLRG rules of a FTS model on a matplotlib axis</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>model</strong> FTS model</p></li>
<li><p><strong>size</strong> figure size</p></li>
<li><p><strong>axis</strong> matplotlib axis</p></li>
<li><p><strong>rules_by_axis</strong> number of rules plotted by column</p></li>
<li><p><strong>columns</strong> number of columns</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.common.Util.show_and_save_image">
<code class="sig-prename descclassname">pyFTS.common.Util.</code><code class="sig-name descname">show_and_save_image</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">fig</span></em>, <em class="sig-param"><span class="n">file</span></em>, <em class="sig-param"><span class="n">flag</span></em>, <em class="sig-param"><span class="n">lgd</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/Util.html#show_and_save_image"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.Util.show_and_save_image" title="Permalink to this definition"></a></dt>
<dd><p>Show and image and save on file</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>fig</strong> Matplotlib Figure object</p></li>
<li><p><strong>file</strong> filename to save the picture</p></li>
<li><p><strong>flag</strong> if True the image will be saved</p></li>
<li><p><strong>lgd</strong> legend</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.common.Util.sliding_window">
<code class="sig-prename descclassname">pyFTS.common.Util.</code><code class="sig-name descname">sliding_window</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">windowsize</span></em>, <em class="sig-param"><span class="n">train</span><span class="o">=</span><span class="default_value">0.8</span></em>, <em class="sig-param"><span class="n">inc</span><span class="o">=</span><span class="default_value">0.1</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/Util.html#sliding_window"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.Util.sliding_window" title="Permalink to this definition"></a></dt>
<dd><p>Sliding window method of cross validation for time series</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> the entire dataset</p></li>
<li><p><strong>windowsize</strong> window size</p></li>
<li><p><strong>train</strong> percentual of the window size will be used for training the models</p></li>
<li><p><strong>inc</strong> percentual of data used for slide the window</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>window count, training set, test set</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.common.Util.uniquefilename">
<code class="sig-prename descclassname">pyFTS.common.Util.</code><code class="sig-name descname">uniquefilename</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">name</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/Util.html#uniquefilename"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.Util.uniquefilename" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</div>
<div class="section" id="module-pyFTS.common.flrg">
<span id="pyfts-common-flrg-module"></span><h2>pyFTS.common.flrg module<a class="headerlink" href="#module-pyFTS.common.flrg" title="Permalink to this headline"></a></h2>
@ -878,8 +1139,562 @@ when the LHS pattern is identified on time t.</p>
</dd></dl>
</div>
<div class="section" id="pyfts-common-fts-module">
<h2>pyFTS.common.fts module<a class="headerlink" href="#pyfts-common-fts-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.common.fts">
<span id="pyfts-common-fts-module"></span><h2>pyFTS.common.fts module<a class="headerlink" href="#module-pyFTS.common.fts" title="Permalink to this headline"></a></h2>
<dl class="py class">
<dt id="pyFTS.common.fts.FTS">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.common.fts.</code><code class="sig-name descname">FTS</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a></p>
<p>Fuzzy Time Series object model</p>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.alpha_cut">
<code class="sig-name descname">alpha_cut</code><a class="headerlink" href="#pyFTS.common.fts.FTS.alpha_cut" title="Permalink to this definition"></a></dt>
<dd><p>A float with the minimal membership to be considered on fuzzyfication process</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.append_log">
<code class="sig-name descname">append_log</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">operation</span></em>, <em class="sig-param"><span class="n">value</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.append_log"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.append_log" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.append_rule">
<code class="sig-name descname">append_rule</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">flrg</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.append_rule"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.append_rule" title="Permalink to this definition"></a></dt>
<dd><p>Append FLRG rule to the model</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>flrg</strong> rule</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.append_transformation">
<code class="sig-name descname">append_transformation</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">transformation</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.append_transformation"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.append_transformation" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.apply_inverse_transformations">
<code class="sig-name descname">apply_inverse_transformations</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">params</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.apply_inverse_transformations"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.apply_inverse_transformations" title="Permalink to this definition"></a></dt>
<dd><p>Apply the data transformations for data postprocessing</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> input data</p></li>
<li><p><strong>params</strong> transformation parameters</p></li>
<li><p><strong>updateUoD</strong> </p></li>
<li><p><strong>kwargs</strong> </p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>postprocessed data</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.apply_transformations">
<code class="sig-name descname">apply_transformations</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">params</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">updateUoD</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.apply_transformations"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.apply_transformations" title="Permalink to this definition"></a></dt>
<dd><p>Apply the data transformations for data preprocessing</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> input data</p></li>
<li><p><strong>params</strong> transformation parameters</p></li>
<li><p><strong>updateUoD</strong> </p></li>
<li><p><strong>kwargs</strong> </p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>preprocessed data</p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.auto_update">
<code class="sig-name descname">auto_update</code><a class="headerlink" href="#pyFTS.common.fts.FTS.auto_update" title="Permalink to this definition"></a></dt>
<dd><p>A boolean value indicating that model is incremental</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.benchmark_only">
<code class="sig-name descname">benchmark_only</code><a class="headerlink" href="#pyFTS.common.fts.FTS.benchmark_only" title="Permalink to this definition"></a></dt>
<dd><p>A boolean value indicating a façade for external (non-FTS) model used on benchmarks or ensembles.</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.clip_uod">
<code class="sig-name descname">clip_uod</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ndata</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.clip_uod"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.clip_uod" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.clone_parameters">
<code class="sig-name descname">clone_parameters</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">model</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.clone_parameters"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.clone_parameters" title="Permalink to this definition"></a></dt>
<dd><p>Import the parameters values from other model</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>model</strong> a model to clone the parameters</p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.detail">
<code class="sig-name descname">detail</code><a class="headerlink" href="#pyFTS.common.fts.FTS.detail" title="Permalink to this definition"></a></dt>
<dd><p>A string with the model detailed information</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.fit">
<code class="sig-name descname">fit</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ndata</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.fit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.fit" title="Permalink to this definition"></a></dt>
<dd><p>Fit the models parameters based on the training data.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>ndata</strong> training time series data</p></li>
<li><p><strong>kwargs</strong> </p></li>
<li><p><strong>num_batches</strong> split the training data in num_batches to save memory during the training process</p></li>
<li><p><strong>save_model</strong> save final model on disk</p></li>
<li><p><strong>batch_save</strong> save the model between each batch</p></li>
<li><p><strong>file_path</strong> path to save the model</p></li>
<li><p><strong>distributed</strong> boolean, indicate if the training procedure will be distributed in a dispy cluster</p></li>
<li><p><strong>nodes</strong> a list with the dispy cluster nodes addresses</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.flrgs">
<code class="sig-name descname">flrgs</code><a class="headerlink" href="#pyFTS.common.fts.FTS.flrgs" title="Permalink to this definition"></a></dt>
<dd><p>The list of Fuzzy Logical Relationship Groups - FLRG</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.forecast">
<code class="sig-name descname">forecast</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.forecast"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.forecast" title="Permalink to this definition"></a></dt>
<dd><p>Point forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.forecast_ahead">
<code class="sig-name descname">forecast_ahead</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">steps</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.forecast_ahead"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.forecast_ahead" title="Permalink to this definition"></a></dt>
<dd><p>Point forecast from 1 to H steps ahead, where H is given by the steps parameter</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>steps</strong> the number of steps ahead to forecast (default: 1)</p></li>
<li><p><strong>start_at</strong> in the multi step forecasting, the index of the data where to start forecasting (default: 0)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.forecast_ahead_distribution">
<code class="sig-name descname">forecast_ahead_distribution</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">steps</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.forecast_ahead_distribution"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.forecast_ahead_distribution" title="Permalink to this definition"></a></dt>
<dd><p>Probabilistic forecast from 1 to H steps ahead, where H is given by the steps parameter</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>steps</strong> the number of steps ahead to forecast</p></li>
<li><p><strong>start_at</strong> in the multi step forecasting, the index of the data where to start forecasting (default: 0)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted Probability Distributions</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.forecast_ahead_interval">
<code class="sig-name descname">forecast_ahead_interval</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">steps</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.forecast_ahead_interval"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.forecast_ahead_interval" title="Permalink to this definition"></a></dt>
<dd><p>Interval forecast from 1 to H steps ahead, where H is given by the steps parameter</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>steps</strong> the number of steps ahead to forecast</p></li>
<li><p><strong>start_at</strong> in the multi step forecasting, the index of the data where to start forecasting (default: 0)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted intervals</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.forecast_ahead_multivariate">
<code class="sig-name descname">forecast_ahead_multivariate</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">steps</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.forecast_ahead_multivariate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.forecast_ahead_multivariate" title="Permalink to this definition"></a></dt>
<dd><p>Multivariate forecast n step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> Pandas dataframe with one column for each variable and with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>steps</strong> the number of steps ahead to forecast</p></li>
<li><p><strong>start_at</strong> in the multi step forecasting, the index of the data where to start forecasting (default: 0)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a Pandas Dataframe object representing the forecasted values for each variable</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.forecast_distribution">
<code class="sig-name descname">forecast_distribution</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.forecast_distribution"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.forecast_distribution" title="Permalink to this definition"></a></dt>
<dd><p>Probabilistic forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with probabilistic.ProbabilityDistribution objects representing the forecasted Probability Distributions</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.forecast_interval">
<code class="sig-name descname">forecast_interval</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.forecast_interval"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.forecast_interval" title="Permalink to this definition"></a></dt>
<dd><p>Interval forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the prediction intervals</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.forecast_multivariate">
<code class="sig-name descname">forecast_multivariate</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.forecast_multivariate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.forecast_multivariate" title="Permalink to this definition"></a></dt>
<dd><p>Multivariate forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> Pandas dataframe with one column for each variable and with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a Pandas Dataframe object representing the forecasted values for each variable</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.forecast_step">
<code class="sig-name descname">forecast_step</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">step</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.forecast_step"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.forecast_step" title="Permalink to this definition"></a></dt>
<dd><p>Point forecast for H steps ahead, where H is given by the step parameter</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>step</strong> the forecasting horizon (default: 1)</p></li>
<li><p><strong>start_at</strong> in the multi step forecasting, the index of the data where to start forecasting (default: 0)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.fuzzy">
<code class="sig-name descname">fuzzy</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.fuzzy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.fuzzy" title="Permalink to this definition"></a></dt>
<dd><p>Fuzzify a data point</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>data</strong> data point</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>maximum membership fuzzy set</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.get_UoD">
<code class="sig-name descname">get_UoD</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.get_UoD"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.get_UoD" title="Permalink to this definition"></a></dt>
<dd><p>Returns the interval of the known bounds of the universe of discourse (UoD), i. e.,
the known minimum and maximum values of the time series.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>A set with the lower and the upper bounds of the UoD</p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.has_interval_forecasting">
<code class="sig-name descname">has_interval_forecasting</code><a class="headerlink" href="#pyFTS.common.fts.FTS.has_interval_forecasting" title="Permalink to this definition"></a></dt>
<dd><p>A boolean value indicating if the model supports interval forecasting, default: False</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.has_point_forecasting">
<code class="sig-name descname">has_point_forecasting</code><a class="headerlink" href="#pyFTS.common.fts.FTS.has_point_forecasting" title="Permalink to this definition"></a></dt>
<dd><p>A boolean value indicating if the model supports point forecasting, default: True</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.has_probability_forecasting">
<code class="sig-name descname">has_probability_forecasting</code><a class="headerlink" href="#pyFTS.common.fts.FTS.has_probability_forecasting" title="Permalink to this definition"></a></dt>
<dd><p>A boolean value indicating if the model support probabilistic forecasting, default: False</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.has_seasonality">
<code class="sig-name descname">has_seasonality</code><a class="headerlink" href="#pyFTS.common.fts.FTS.has_seasonality" title="Permalink to this definition"></a></dt>
<dd><p>A boolean value indicating if the model supports seasonal indexers, default: False</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.indexer">
<code class="sig-name descname">indexer</code><a class="headerlink" href="#pyFTS.common.fts.FTS.indexer" title="Permalink to this definition"></a></dt>
<dd><p>An pyFTS.models.seasonal.Indexer object for indexing the time series data</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.is_clustered">
<code class="sig-name descname">is_clustered</code><a class="headerlink" href="#pyFTS.common.fts.FTS.is_clustered" title="Permalink to this definition"></a></dt>
<dd><p>A boolean value indicating if the model support multivariate time series (Pandas DataFrame), but works like
a monovariate method, default: False</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.is_high_order">
<code class="sig-name descname">is_high_order</code><a class="headerlink" href="#pyFTS.common.fts.FTS.is_high_order" title="Permalink to this definition"></a></dt>
<dd><p>A boolean value indicating if the model support orders greater than 1, default: False</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.is_multivariate">
<code class="sig-name descname">is_multivariate</code><a class="headerlink" href="#pyFTS.common.fts.FTS.is_multivariate" title="Permalink to this definition"></a></dt>
<dd><p>A boolean value indicating if the model support multivariate time series (Pandas DataFrame), default: False</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.is_time_variant">
<code class="sig-name descname">is_time_variant</code><a class="headerlink" href="#pyFTS.common.fts.FTS.is_time_variant" title="Permalink to this definition"></a></dt>
<dd><p>A boolean value indicating if this model is time variant</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.is_wrapper">
<code class="sig-name descname">is_wrapper</code><a class="headerlink" href="#pyFTS.common.fts.FTS.is_wrapper" title="Permalink to this definition"></a></dt>
<dd><p>Indicates that this model is a wrapper for other(s) method(s)</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.lags">
<code class="sig-name descname">lags</code><a class="headerlink" href="#pyFTS.common.fts.FTS.lags" title="Permalink to this definition"></a></dt>
<dd><p>The list of lag indexes for high order models</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.len_total">
<code class="sig-name descname">len_total</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.len_total"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.len_total" title="Permalink to this definition"></a></dt>
<dd><p>Total length of the model, adding the number of terms in all rules</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.log">
<code class="sig-name descname">log</code><a class="headerlink" href="#pyFTS.common.fts.FTS.log" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.max_lag">
<code class="sig-name descname">max_lag</code><a class="headerlink" href="#pyFTS.common.fts.FTS.max_lag" title="Permalink to this definition"></a></dt>
<dd><p>A integer indicating the largest lag used by the model. This value also indicates the minimum number of past lags
needed to forecast a single step ahead</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.merge">
<code class="sig-name descname">merge</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">model</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.merge"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.merge" title="Permalink to this definition"></a></dt>
<dd><p>Merge the FLRG rules from other model</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>model</strong> source model</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.min_order">
<code class="sig-name descname">min_order</code><a class="headerlink" href="#pyFTS.common.fts.FTS.min_order" title="Permalink to this definition"></a></dt>
<dd><p>In high order models, this integer value indicates the minimal order supported for the model, default: 1</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.name">
<code class="sig-name descname">name</code><a class="headerlink" href="#pyFTS.common.fts.FTS.name" title="Permalink to this definition"></a></dt>
<dd><p>A string with the model name</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.offset">
<code class="sig-name descname">offset</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.offset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.offset" title="Permalink to this definition"></a></dt>
<dd><p>Returns the number of lags to skip in the input test data in order to synchronize it with
the forecasted values given by the predict function. This is necessary due to the order of the
model, among other parameters.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>An integer with the number of lags to skip</p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.order">
<code class="sig-name descname">order</code><a class="headerlink" href="#pyFTS.common.fts.FTS.order" title="Permalink to this definition"></a></dt>
<dd><p>A integer with the model order (number of past lags are used on forecasting)</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.original_max">
<code class="sig-name descname">original_max</code><a class="headerlink" href="#pyFTS.common.fts.FTS.original_max" title="Permalink to this definition"></a></dt>
<dd><p>A float with the upper limit of the Universe of Discourse, the maximal value found on training data</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.original_min">
<code class="sig-name descname">original_min</code><a class="headerlink" href="#pyFTS.common.fts.FTS.original_min" title="Permalink to this definition"></a></dt>
<dd><p>A float with the lower limit of the Universe of Discourse, the minimal value found on training data</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.partitioner">
<code class="sig-name descname">partitioner</code><a class="headerlink" href="#pyFTS.common.fts.FTS.partitioner" title="Permalink to this definition"></a></dt>
<dd><p>A pyFTS.partitioners.Partitioner object with the Universe of Discourse partitioner used on the model. This is a mandatory dependecy.</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.predict">
<code class="sig-name descname">predict</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.predict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.predict" title="Permalink to this definition"></a></dt>
<dd><p>Forecast using trained model</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series with minimal length to the order of the model</p></li>
<li><p><strong>type</strong> the forecasting type, one of these values: point(default), interval, distribution or multivariate.</p></li>
<li><p><strong>steps_ahead</strong> The forecasting path H, i. e., tell the model to forecast from t+1 to t+H.</p></li>
<li><p><strong>step_to</strong> The forecasting step H, i. e., tell the model to forecast to t+H for each input sample</p></li>
<li><p><strong>start_at</strong> in the multi step forecasting, the index of the data where to start forecasting (default value: 0)</p></li>
<li><p><strong>distributed</strong> boolean, indicate if the forecasting procedure will be distributed in a dispy cluster (default value: False)</p></li>
<li><p><strong>nodes</strong> a list with the dispy cluster nodes addresses</p></li>
<li><p><strong>explain</strong> try to explain, step by step, the one-step-ahead point forecasting result given the input data. (default value: False)</p></li>
<li><p><strong>generators</strong> for multivariate methods on multi step ahead forecasting, generators is a dict where the keys
are the dataframe columun names (except the target_variable) and the values are lambda functions that
accept one value (the actual value of the variable) and return the next value or trained FTS
models that accept the actual values and forecast new ones.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a numpy array with the forecasted data</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.reset_calculated_values">
<code class="sig-name descname">reset_calculated_values</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.reset_calculated_values"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.reset_calculated_values" title="Permalink to this definition"></a></dt>
<dd><p>Reset all pre-calculated values on the FLRGs</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.shortname">
<code class="sig-name descname">shortname</code><a class="headerlink" href="#pyFTS.common.fts.FTS.shortname" title="Permalink to this definition"></a></dt>
<dd><p>A string with a short name or alias for the model</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.standard_horizon">
<code class="sig-name descname">standard_horizon</code><a class="headerlink" href="#pyFTS.common.fts.FTS.standard_horizon" title="Permalink to this definition"></a></dt>
<dd><p>Standard forecasting horizon (Default: 1)</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.common.fts.FTS.train">
<code class="sig-name descname">train</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.train" title="Permalink to this definition"></a></dt>
<dd><p>Method specific parameter fitting</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> training time series data</p></li>
<li><p><strong>kwargs</strong> Method specific parameters</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.transformations">
<code class="sig-name descname">transformations</code><a class="headerlink" href="#pyFTS.common.fts.FTS.transformations" title="Permalink to this definition"></a></dt>
<dd><p>A list with the data transformations (common.Transformations) applied on model pre and post processing, default: []</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.transformations_param">
<code class="sig-name descname">transformations_param</code><a class="headerlink" href="#pyFTS.common.fts.FTS.transformations_param" title="Permalink to this definition"></a></dt>
<dd><p>A list with the specific parameters for each data transformation</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.common.fts.FTS.uod_clip">
<code class="sig-name descname">uod_clip</code><a class="headerlink" href="#pyFTS.common.fts.FTS.uod_clip" title="Permalink to this definition"></a></dt>
<dd><p>Flag indicating if the test data will be clipped inside the training Universe of Discourse</p>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="module-pyFTS.common.tree">
<span id="pyfts-common-tree-module"></span><h2>pyFTS.common.tree module<a class="headerlink" href="#module-pyFTS.common.tree" title="Permalink to this headline"></a></h2>
@ -948,10 +1763,9 @@ when the LHS pattern is identified on time t.</p>
<li><a class="reference internal" href="#module-pyFTS.common.FuzzySet">pyFTS.common.FuzzySet module</a></li>
<li><a class="reference internal" href="#module-pyFTS.common.Membership">pyFTS.common.Membership module</a></li>
<li><a class="reference internal" href="#module-pyFTS.common.SortedCollection">pyFTS.common.SortedCollection module</a></li>
<li><a class="reference internal" href="#pyfts-common-transformations-module">pyFTS.common.transformations module</a></li>
<li><a class="reference internal" href="#pyfts-common-util-module">pyFTS.common.Util module</a></li>
<li><a class="reference internal" href="#module-pyFTS.common.Util">pyFTS.common.Util module</a></li>
<li><a class="reference internal" href="#module-pyFTS.common.flrg">pyFTS.common.flrg module</a></li>
<li><a class="reference internal" href="#pyfts-common-fts-module">pyFTS.common.fts module</a></li>
<li><a class="reference internal" href="#module-pyFTS.common.fts">pyFTS.common.fts module</a></li>
<li><a class="reference internal" href="#module-pyFTS.common.tree">pyFTS.common.tree module</a></li>
</ul>
</li>

View File

@ -89,6 +89,9 @@
<div class="section" id="pyfts-common-transformations-scale-module">
<h2>pyFTS.common.transformations.scale module<a class="headerlink" href="#pyfts-common-transformations-scale-module" title="Permalink to this headline"></a></h2>
</div>
<div class="section" id="pyfts-common-transformations-smoothing-module">
<h2>pyFTS.common.transformations.smoothing module<a class="headerlink" href="#pyfts-common-transformations-smoothing-module" title="Permalink to this headline"></a></h2>
</div>
<div class="section" id="pyfts-common-transformations-som-module">
<h2>pyFTS.common.transformations.som module<a class="headerlink" href="#pyfts-common-transformations-som-module" title="Permalink to this headline"></a></h2>
</div>
@ -118,6 +121,7 @@
<li><a class="reference internal" href="#pyfts-common-transformations-normalization-module">pyFTS.common.transformations.normalization module</a></li>
<li><a class="reference internal" href="#pyfts-common-transformations-roi-module">pyFTS.common.transformations.roi module</a></li>
<li><a class="reference internal" href="#pyfts-common-transformations-scale-module">pyFTS.common.transformations.scale module</a></li>
<li><a class="reference internal" href="#pyfts-common-transformations-smoothing-module">pyFTS.common.transformations.smoothing module</a></li>
<li><a class="reference internal" href="#pyfts-common-transformations-som-module">pyFTS.common.transformations.som module</a></li>
<li><a class="reference internal" href="#pyfts-common-transformations-transformation-module">pyFTS.common.transformations.transformation module</a></li>
<li><a class="reference internal" href="#pyfts-common-transformations-trend-module">pyFTS.common.transformations.trend module</a></li>

View File

@ -71,8 +71,67 @@
<div class="section" id="submodules">
<h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this headline"></a></h2>
</div>
<div class="section" id="pyfts-distributed-dispy-module">
<h2>pyFTS.distributed.dispy module<a class="headerlink" href="#pyfts-distributed-dispy-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.distributed.dispy">
<span id="pyfts-distributed-dispy-module"></span><h2>pyFTS.distributed.dispy module<a class="headerlink" href="#module-pyFTS.distributed.dispy" title="Permalink to this headline"></a></h2>
<dl class="py function">
<dt id="pyFTS.distributed.dispy.distributed_predict">
<code class="sig-prename descclassname">pyFTS.distributed.dispy.</code><code class="sig-name descname">distributed_predict</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">model</span></em>, <em class="sig-param"><span class="n">parameters</span></em>, <em class="sig-param"><span class="n">nodes</span></em>, <em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">num_batches</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/distributed/dispy.html#distributed_predict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.distributed.dispy.distributed_predict" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="pyFTS.distributed.dispy.distributed_train">
<code class="sig-prename descclassname">pyFTS.distributed.dispy.</code><code class="sig-name descname">distributed_train</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">model</span></em>, <em class="sig-param"><span class="n">train_method</span></em>, <em class="sig-param"><span class="n">nodes</span></em>, <em class="sig-param"><span class="n">fts_method</span></em>, <em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">num_batches</span><span class="o">=</span><span class="default_value">10</span></em>, <em class="sig-param"><span class="n">train_parameters</span><span class="o">=</span><span class="default_value">{}</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/distributed/dispy.html#distributed_train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.distributed.dispy.distributed_train" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="pyFTS.distributed.dispy.get_number_of_cpus">
<code class="sig-prename descclassname">pyFTS.distributed.dispy.</code><code class="sig-name descname">get_number_of_cpus</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">cluster</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/distributed/dispy.html#get_number_of_cpus"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.distributed.dispy.get_number_of_cpus" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="pyFTS.distributed.dispy.simple_model_predict">
<code class="sig-prename descclassname">pyFTS.distributed.dispy.</code><code class="sig-name descname">simple_model_predict</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">model</span></em>, <em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">parameters</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/distributed/dispy.html#simple_model_predict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.distributed.dispy.simple_model_predict" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="pyFTS.distributed.dispy.simple_model_train">
<code class="sig-prename descclassname">pyFTS.distributed.dispy.</code><code class="sig-name descname">simple_model_train</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">model</span></em>, <em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">parameters</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/distributed/dispy.html#simple_model_train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.distributed.dispy.simple_model_train" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="pyFTS.distributed.dispy.start_dispy_cluster">
<code class="sig-prename descclassname">pyFTS.distributed.dispy.</code><code class="sig-name descname">start_dispy_cluster</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">method</span></em>, <em class="sig-param"><span class="n">nodes</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/distributed/dispy.html#start_dispy_cluster"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.distributed.dispy.start_dispy_cluster" title="Permalink to this definition"></a></dt>
<dd><p>Start a new Dispy cluster on nodes to execute the method method</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>method</strong> function to be executed on each cluster node</p></li>
<li><p><strong>nodes</strong> list of node names or IPs.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>the dispy cluster instance and the http_server for monitoring</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.distributed.dispy.stop_dispy_cluster">
<code class="sig-prename descclassname">pyFTS.distributed.dispy.</code><code class="sig-name descname">stop_dispy_cluster</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">cluster</span></em>, <em class="sig-param"><span class="n">http_server</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/distributed/dispy.html#stop_dispy_cluster"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.distributed.dispy.stop_dispy_cluster" title="Permalink to this definition"></a></dt>
<dd><p>Stop a dispy cluster and http_server</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>cluster</strong> </p></li>
<li><p><strong>http_server</strong> </p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
</div>
<div class="section" id="pyfts-distributed-spark-module">
<h2>pyFTS.distributed.spark module<a class="headerlink" href="#pyfts-distributed-spark-module" title="Permalink to this headline"></a></h2>
@ -91,7 +150,7 @@
<li><a class="reference internal" href="#">pyFTS.distributed package</a><ul>
<li><a class="reference internal" href="#module-pyFTS.distributed">Module contents</a></li>
<li><a class="reference internal" href="#submodules">Submodules</a></li>
<li><a class="reference internal" href="#pyfts-distributed-dispy-module">pyFTS.distributed.dispy module</a></li>
<li><a class="reference internal" href="#module-pyFTS.distributed.dispy">pyFTS.distributed.dispy module</a></li>
<li><a class="reference internal" href="#pyfts-distributed-spark-module">pyFTS.distributed.spark module</a></li>
</ul>
</li>

View File

@ -71,17 +71,17 @@
<li class="toctree-l1"><a class="reference internal" href="pyFTS.benchmarks.html">pyFTS.benchmarks package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks">Module contents</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#submodules">Submodules</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-benchmarks-module">pyFTS.benchmarks.benchmarks module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-measures-module">pyFTS.benchmarks.Measures module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-residualanalysis-module">pyFTS.benchmarks.ResidualAnalysis module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-tests-module">pyFTS.benchmarks.Tests module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-util-module">pyFTS.benchmarks.Util module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-arima-module">pyFTS.benchmarks.arima module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-knn-module">pyFTS.benchmarks.knn module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-naive-module">pyFTS.benchmarks.naive module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-quantreg-module">pyFTS.benchmarks.quantreg module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.benchmarks">pyFTS.benchmarks.benchmarks module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.Measures">pyFTS.benchmarks.Measures module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.ResidualAnalysis">pyFTS.benchmarks.ResidualAnalysis module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.Tests">pyFTS.benchmarks.Tests module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.Util">pyFTS.benchmarks.Util module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.arima">pyFTS.benchmarks.arima module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.knn">pyFTS.benchmarks.knn module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.naive">pyFTS.benchmarks.naive module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.quantreg">pyFTS.benchmarks.quantreg module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-gaussianproc-module">pyFTS.benchmarks.gaussianproc module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#pyfts-benchmarks-bsts-module">pyFTS.benchmarks.BSTS module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.benchmarks.html#module-pyFTS.benchmarks.BSTS">pyFTS.benchmarks.BSTS module</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="pyFTS.common.html">pyFTS.common package</a><ul>
@ -92,10 +92,9 @@
<li class="toctree-l2"><a class="reference internal" href="pyFTS.common.html#module-pyFTS.common.FuzzySet">pyFTS.common.FuzzySet module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.common.html#module-pyFTS.common.Membership">pyFTS.common.Membership module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.common.html#module-pyFTS.common.SortedCollection">pyFTS.common.SortedCollection module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.common.html#pyfts-common-transformations-module">pyFTS.common.transformations module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.common.html#pyfts-common-util-module">pyFTS.common.Util module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.common.html#module-pyFTS.common.Util">pyFTS.common.Util module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.common.html#module-pyFTS.common.flrg">pyFTS.common.flrg module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.common.html#pyfts-common-fts-module">pyFTS.common.fts module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.common.html#module-pyFTS.common.fts">pyFTS.common.fts module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.common.html#module-pyFTS.common.tree">pyFTS.common.tree module</a></li>
</ul>
</li>
@ -108,6 +107,7 @@
<li class="toctree-l2"><a class="reference internal" href="pyFTS.common.transformations.html#pyfts-common-transformations-normalization-module">pyFTS.common.transformations.normalization module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.common.transformations.html#pyfts-common-transformations-roi-module">pyFTS.common.transformations.roi module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.common.transformations.html#pyfts-common-transformations-scale-module">pyFTS.common.transformations.scale module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.common.transformations.html#pyfts-common-transformations-smoothing-module">pyFTS.common.transformations.smoothing module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.common.transformations.html#pyfts-common-transformations-som-module">pyFTS.common.transformations.som module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.common.transformations.html#pyfts-common-transformations-transformation-module">pyFTS.common.transformations.transformation module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.common.transformations.html#pyfts-common-transformations-trend-module">pyFTS.common.transformations.trend module</a></li>
@ -144,7 +144,7 @@
<li class="toctree-l1"><a class="reference internal" href="pyFTS.distributed.html">pyFTS.distributed package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.distributed.html#module-pyFTS.distributed">Module contents</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.distributed.html#submodules">Submodules</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.distributed.html#pyfts-distributed-dispy-module">pyFTS.distributed.dispy module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.distributed.html#module-pyFTS.distributed.dispy">pyFTS.distributed.dispy module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.distributed.html#pyfts-distributed-spark-module">pyFTS.distributed.spark module</a></li>
</ul>
</li>
@ -152,8 +152,8 @@
<li class="toctree-l2"><a class="reference internal" href="pyFTS.hyperparam.html#module-pyFTS.hyperparam">Module contents</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.hyperparam.html#submodules">Submodules</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.hyperparam.html#module-pyFTS.hyperparam.Util">pyFTS.hyperparam.Util module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.hyperparam.html#pyfts-hyperparam-gridsearch-module">pyFTS.hyperparam.GridSearch module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.hyperparam.html#pyfts-hyperparam-evolutionary-module">pyFTS.hyperparam.Evolutionary module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.hyperparam.html#module-pyFTS.hyperparam.GridSearch">pyFTS.hyperparam.GridSearch module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.hyperparam.html#module-pyFTS.hyperparam.Evolutionary">pyFTS.hyperparam.Evolutionary module</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="pyFTS.models.html">pyFTS.models package</a><ul>
@ -161,16 +161,16 @@
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#subpackages">Subpackages</a><ul>
<li class="toctree-l3"><a class="reference internal" href="pyFTS.models.ensemble.html">pyFTS.models.ensemble package</a><ul>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.ensemble.html#submodules">Submodules</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.ensemble.html#pyfts-models-ensemble-ensemble-module">pyFTS.models.ensemble.ensemble module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.ensemble.html#pyfts-models-ensemble-multiseasonal-module">pyFTS.models.ensemble.multiseasonal module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.ensemble.html#module-pyFTS.models.ensemble.ensemble">pyFTS.models.ensemble.ensemble module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.ensemble.html#module-pyFTS.models.ensemble.multiseasonal">pyFTS.models.ensemble.multiseasonal module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.ensemble.html#module-pyFTS.models.ensemble">Module contents</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="pyFTS.models.incremental.html">pyFTS.models.incremental package</a><ul>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.incremental.html#module-pyFTS.models.incremental">Module contents</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.incremental.html#submodules">Submodules</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.incremental.html#pyfts-models-incremental-timevariant-module">pyFTS.models.incremental.TimeVariant module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.incremental.html#pyfts-models-incremental-incrementalensemble-module">pyFTS.models.incremental.IncrementalEnsemble module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.incremental.html#module-pyFTS.models.incremental.TimeVariant">pyFTS.models.incremental.TimeVariant module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.incremental.html#module-pyFTS.models.incremental.IncrementalEnsemble">pyFTS.models.incremental.IncrementalEnsemble module</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="pyFTS.models.multivariate.html">pyFTS.models.multivariate package</a><ul>
@ -178,53 +178,53 @@
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.multivariate.html#submodules">Submodules</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.multivariate.html#module-pyFTS.models.multivariate.FLR">pyFTS.models.multivariate.FLR module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.multivariate.html#module-pyFTS.models.multivariate.common">pyFTS.models.multivariate.common module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.multivariate.html#pyfts-models-multivariate-variable-module">pyFTS.models.multivariate.variable module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.multivariate.html#module-pyFTS.models.multivariate.variable">pyFTS.models.multivariate.variable module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.multivariate.html#module-pyFTS.models.multivariate.flrg">pyFTS.models.multivariate.flrg module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.multivariate.html#module-pyFTS.models.multivariate.partitioner">pyFTS.models.multivariate.partitioner module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.multivariate.html#module-pyFTS.models.multivariate.grid">pyFTS.models.multivariate.grid module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.multivariate.html#pyfts-models-multivariate-mvfts-module">pyFTS.models.multivariate.mvfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.multivariate.html#pyfts-models-multivariate-wmvfts-module">pyFTS.models.multivariate.wmvfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.multivariate.html#pyfts-models-multivariate-cmvfts-module">pyFTS.models.multivariate.cmvfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.multivariate.html#pyfts-models-multivariate-granular-module">pyFTS.models.multivariate.granular module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.multivariate.html#module-pyFTS.models.multivariate.mvfts">pyFTS.models.multivariate.mvfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.multivariate.html#module-pyFTS.models.multivariate.wmvfts">pyFTS.models.multivariate.wmvfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.multivariate.html#module-pyFTS.models.multivariate.cmvfts">pyFTS.models.multivariate.cmvfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.multivariate.html#module-pyFTS.models.multivariate.granular">pyFTS.models.multivariate.granular module</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="pyFTS.models.nonstationary.html">pyFTS.models.nonstationary package</a><ul>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.nonstationary.html#submodules">Submodules</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.nonstationary.html#module-pyFTS.models.nonstationary.common">pyFTS.models.nonstationary.common module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.nonstationary.html#pyfts-models-nonstationary-cvfts-module">pyFTS.models.nonstationary.cvfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.nonstationary.html#module-pyFTS.models.nonstationary.cvfts">pyFTS.models.nonstationary.cvfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.nonstationary.html#module-pyFTS.models.nonstationary.flrg">pyFTS.models.nonstationary.flrg module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.nonstationary.html#pyfts-models-nonstationary-honsfts-module">pyFTS.models.nonstationary.honsfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.nonstationary.html#pyfts-models-nonstationary-nsfts-module">pyFTS.models.nonstationary.nsfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.nonstationary.html#module-pyFTS.models.nonstationary.honsfts">pyFTS.models.nonstationary.honsfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.nonstationary.html#module-pyFTS.models.nonstationary.nsfts">pyFTS.models.nonstationary.nsfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.nonstationary.html#module-pyFTS.models.nonstationary.partitioners">pyFTS.models.nonstationary.partitioners module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.nonstationary.html#module-pyFTS.models.nonstationary.perturbation">pyFTS.models.nonstationary.perturbation module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.nonstationary.html#pyfts-models-nonstationary-util-module">pyFTS.models.nonstationary.util module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.nonstationary.html#module-pyFTS.models.nonstationary.util">pyFTS.models.nonstationary.util module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.nonstationary.html#module-pyFTS.models.nonstationary">Module contents</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="pyFTS.models.seasonal.html">pyFTS.models.seasonal package</a><ul>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.seasonal.html#submodules">Submodules</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.seasonal.html#module-pyFTS.models.seasonal.SeasonalIndexer">pyFTS.models.seasonal.SeasonalIndexer module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.seasonal.html#pyfts-models-seasonal-cmsfts-module">pyFTS.models.seasonal.cmsfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.seasonal.html#module-pyFTS.models.seasonal.cmsfts">pyFTS.models.seasonal.cmsfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.seasonal.html#module-pyFTS.models.seasonal.common">pyFTS.models.seasonal.common module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.seasonal.html#pyfts-models-seasonal-msfts-module">pyFTS.models.seasonal.msfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.seasonal.html#module-pyFTS.models.seasonal.msfts">pyFTS.models.seasonal.msfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.seasonal.html#module-pyFTS.models.seasonal.partitioner">pyFTS.models.seasonal.partitioner module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.seasonal.html#pyfts-models-seasonal-sfts-module">pyFTS.models.seasonal.sfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.seasonal.html#module-pyFTS.models.seasonal.sfts">pyFTS.models.seasonal.sfts module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.models.seasonal.html#module-pyFTS.models.seasonal">Module contents</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#submodules">Submodules</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#pyfts-models-song-module">pyFTS.models.song module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#pyfts-models-chen-module">pyFTS.models.chen module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#pyfts-models-yu-module">pyFTS.models.yu module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#pyfts-models-cheng-module">pyFTS.models.cheng module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#pyfts-models-hofts-module">pyFTS.models.hofts module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#pyfts-models-hwang-module">pyFTS.models.hwang module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#pyfts-models-ifts-module">pyFTS.models.ifts module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#pyfts-models-ismailefendi-module">pyFTS.models.ismailefendi module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#pyfts-models-pwfts-module">pyFTS.models.pwfts module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#pyfts-models-sadaei-module">pyFTS.models.sadaei module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.song">pyFTS.models.song module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.chen">pyFTS.models.chen module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.yu">pyFTS.models.yu module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.cheng">pyFTS.models.cheng module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.hofts">pyFTS.models.hofts module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.hwang">pyFTS.models.hwang module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.ifts">pyFTS.models.ifts module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.ismailefendi">pyFTS.models.ismailefendi module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.pwfts">pyFTS.models.pwfts module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.models.html#module-pyFTS.models.sadaei">pyFTS.models.sadaei module</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="pyFTS.partitioners.html">pyFTS.partitioners package</a><ul>
@ -235,19 +235,19 @@
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.Entropy">pyFTS.partitioners.Entropy module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.FCM">pyFTS.partitioners.FCM module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.Grid">pyFTS.partitioners.Grid module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#pyfts-partitioners-huarng-module">pyFTS.partitioners.Huarng module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.Huarng">pyFTS.partitioners.Huarng module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.Singleton">pyFTS.partitioners.Singleton module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.Simple">pyFTS.partitioners.Simple module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.SubClust">pyFTS.partitioners.SubClust module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#pyfts-partitioners-util-module">pyFTS.partitioners.Util module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#pyfts-partitioners-parallel-util-module">pyFTS.partitioners.parallel_util module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.Util">pyFTS.partitioners.Util module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.parallel_util">pyFTS.partitioners.parallel_util module</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="pyFTS.probabilistic.html">pyFTS.probabilistic package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.probabilistic.html#module-pyFTS.probabilistic">Module contents</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.probabilistic.html#submodules">Submodules</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.probabilistic.html#pyfts-probabilistic-probabilitydistribution-module">pyFTS.probabilistic.ProbabilityDistribution module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.probabilistic.html#pyfts-probabilistic-kde-module">pyFTS.probabilistic.kde module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.probabilistic.html#module-pyFTS.probabilistic.ProbabilityDistribution">pyFTS.probabilistic.ProbabilityDistribution module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.probabilistic.html#module-pyFTS.probabilistic.kde">pyFTS.probabilistic.kde module</a></li>
</ul>
</li>
</ul>

View File

@ -131,11 +131,343 @@ Value: the measure value</p>
</dd></dl>
</div>
<div class="section" id="pyfts-hyperparam-gridsearch-module">
<h2>pyFTS.hyperparam.GridSearch module<a class="headerlink" href="#pyfts-hyperparam-gridsearch-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.hyperparam.GridSearch">
<span id="pyfts-hyperparam-gridsearch-module"></span><h2>pyFTS.hyperparam.GridSearch module<a class="headerlink" href="#module-pyFTS.hyperparam.GridSearch" title="Permalink to this headline"></a></h2>
<dl class="py function">
<dt id="pyFTS.hyperparam.GridSearch.cluster_method">
<code class="sig-prename descclassname">pyFTS.hyperparam.GridSearch.</code><code class="sig-name descname">cluster_method</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">individual</span></em>, <em class="sig-param"><span class="n">dataset</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/GridSearch.html#cluster_method"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.GridSearch.cluster_method" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="pyFTS.hyperparam.GridSearch.dict_individual">
<code class="sig-prename descclassname">pyFTS.hyperparam.GridSearch.</code><code class="sig-name descname">dict_individual</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">mf</span></em>, <em class="sig-param"><span class="n">partitioner</span></em>, <em class="sig-param"><span class="n">partitions</span></em>, <em class="sig-param"><span class="n">order</span></em>, <em class="sig-param"><span class="n">lags</span></em>, <em class="sig-param"><span class="n">alpha_cut</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/GridSearch.html#dict_individual"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.GridSearch.dict_individual" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="pyFTS.hyperparam.GridSearch.execute">
<code class="sig-prename descclassname">pyFTS.hyperparam.GridSearch.</code><code class="sig-name descname">execute</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">hyperparams</span></em>, <em class="sig-param"><span class="n">datasetname</span></em>, <em class="sig-param"><span class="n">dataset</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/GridSearch.html#execute"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.GridSearch.execute" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="pyFTS.hyperparam.GridSearch.process_jobs">
<code class="sig-prename descclassname">pyFTS.hyperparam.GridSearch.</code><code class="sig-name descname">process_jobs</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">jobs</span></em>, <em class="sig-param"><span class="n">datasetname</span></em>, <em class="sig-param"><span class="n">conn</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/GridSearch.html#process_jobs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.GridSearch.process_jobs" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</div>
<div class="section" id="pyfts-hyperparam-evolutionary-module">
<h2>pyFTS.hyperparam.Evolutionary module<a class="headerlink" href="#pyfts-hyperparam-evolutionary-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.hyperparam.Evolutionary">
<span id="pyfts-hyperparam-evolutionary-module"></span><h2>pyFTS.hyperparam.Evolutionary module<a class="headerlink" href="#module-pyFTS.hyperparam.Evolutionary" title="Permalink to this headline"></a></h2>
<p>Distributed Evolutionary Hyperparameter Optimization (DEHO) for MVFTS</p>
<dl class="py function">
<dt id="pyFTS.hyperparam.Evolutionary.GeneticAlgorithm">
<code class="sig-prename descclassname">pyFTS.hyperparam.Evolutionary.</code><code class="sig-name descname">GeneticAlgorithm</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">dataset</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/Evolutionary.html#GeneticAlgorithm"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.Evolutionary.GeneticAlgorithm" title="Permalink to this definition"></a></dt>
<dd><p>Genetic algoritm for Distributed Evolutionary Hyperparameter Optimization (DEHO)</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>dataset</strong> The time series to optimize the FTS</p></li>
<li><p><strong>ngen</strong> An integer value with the maximum number of generations, default value: 30</p></li>
<li><p><strong>mgen</strong> An integer value with the maximum number of generations without improvement to stop, default value 7</p></li>
<li><p><strong>npop</strong> An integer value with the population size, default value: 20</p></li>
<li><p><strong>pcross</strong> A float value between 0 and 1 with the probability of crossover, default: .5</p></li>
<li><p><strong>psel</strong> A float value between 0 and 1 with the probability of selection, default: .5</p></li>
<li><p><strong>pmut</strong> A float value between 0 and 1 with the probability of mutation, default: .3</p></li>
<li><p><strong>fts_method</strong> The FTS method to optimize</p></li>
<li><p><strong>parameters</strong> dict with model specific arguments for fts_method</p></li>
<li><p><strong>elitism</strong> A boolean value indicating if the best individual must always survive to next population</p></li>
<li><p><strong>initial_operator</strong> a function that receives npop and return a random population with size npop</p></li>
<li><p><strong>evalutation_operator</strong> a function that receives a dataset and an individual and return its fitness</p></li>
<li><p><strong>selection_operator</strong> a function that receives the whole population and return a selected individual</p></li>
<li><p><strong>crossover_operator</strong> a function that receives the whole population and return a descendent individual</p></li>
<li><p><strong>mutation_operator</strong> a function that receives one individual and return a changed individual</p></li>
<li><p><strong>window_size</strong> An integer value with the the length of scrolling window for train/test on dataset</p></li>
<li><p><strong>train_rate</strong> A float value between 0 and 1 with the train/test split ([0,1])</p></li>
<li><p><strong>increment_rate</strong> A float value between 0 and 1 with the the increment of the scrolling window,
relative to the window_size ([0,1])</p></li>
<li><p><strong>collect_statistics</strong> A boolean value indicating to collect statistics for each generation</p></li>
<li><p><strong>distributed</strong> A value indicating it the execution will be local and sequential (distributed=False),
or parallel and distributed (distributed=dispy or distributed=spark)</p></li>
<li><p><strong>cluster</strong> If distributed=dispy the list of cluster nodes, else if distributed=spark it is the master node</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>the best genotype</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.hyperparam.Evolutionary.crossover">
<code class="sig-prename descclassname">pyFTS.hyperparam.Evolutionary.</code><code class="sig-name descname">crossover</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">population</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/Evolutionary.html#crossover"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.Evolutionary.crossover" title="Permalink to this definition"></a></dt>
<dd><p>Crossover operation between two parents</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>population</strong> the original population</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a genotype</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.hyperparam.Evolutionary.double_tournament">
<code class="sig-prename descclassname">pyFTS.hyperparam.Evolutionary.</code><code class="sig-name descname">double_tournament</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">population</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/Evolutionary.html#double_tournament"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.Evolutionary.double_tournament" title="Permalink to this definition"></a></dt>
<dd><p>Double tournament selection strategy.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>population</strong> </p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.hyperparam.Evolutionary.elitism">
<code class="sig-prename descclassname">pyFTS.hyperparam.Evolutionary.</code><code class="sig-name descname">elitism</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">population</span></em>, <em class="sig-param"><span class="n">new_population</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/Evolutionary.html#elitism"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.Evolutionary.elitism" title="Permalink to this definition"></a></dt>
<dd><p>Elitism operation, always select the best individual of the population and discard the worst</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>population</strong> </p></li>
<li><p><strong>new_population</strong> </p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.hyperparam.Evolutionary.evaluate">
<code class="sig-prename descclassname">pyFTS.hyperparam.Evolutionary.</code><code class="sig-name descname">evaluate</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">dataset</span></em>, <em class="sig-param"><span class="n">individual</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/Evolutionary.html#evaluate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.Evolutionary.evaluate" title="Permalink to this definition"></a></dt>
<dd><p>Evaluate an individual using a sliding window cross validation over the dataset.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>dataset</strong> Evaluation dataset</p></li>
<li><p><strong>individual</strong> genotype to be tested</p></li>
<li><p><strong>window_size</strong> The length of scrolling window for train/test on dataset</p></li>
<li><p><strong>train_rate</strong> The train/test split ([0,1])</p></li>
<li><p><strong>increment_rate</strong> The increment of the scrolling window, relative to the window_size ([0,1])</p></li>
<li><p><strong>parameters</strong> dict with model specific arguments for fit method.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a tuple (len_lags, rmse) with the parsimony fitness value and the accuracy fitness value</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.hyperparam.Evolutionary.execute">
<code class="sig-prename descclassname">pyFTS.hyperparam.Evolutionary.</code><code class="sig-name descname">execute</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">datasetname</span></em>, <em class="sig-param"><span class="n">dataset</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/Evolutionary.html#execute"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.Evolutionary.execute" title="Permalink to this definition"></a></dt>
<dd><p>Batch execution of Distributed Evolutionary Hyperparameter Optimization (DEHO) for monovariate methods</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>datasetname</strong> </p></li>
<li><p><strong>dataset</strong> The time series to optimize the FTS</p></li>
<li><p><strong>file</strong> </p></li>
<li><p><strong>experiments</strong> </p></li>
<li><p><strong>distributed</strong> </p></li>
<li><p><strong>ngen</strong> An integer value with the maximum number of generations, default value: 30</p></li>
<li><p><strong>mgen</strong> An integer value with the maximum number of generations without improvement to stop, default value 7</p></li>
<li><p><strong>npop</strong> An integer value with the population size, default value: 20</p></li>
<li><p><strong>pcross</strong> A float value between 0 and 1 with the probability of crossover, default: .5</p></li>
<li><p><strong>psel</strong> A float value between 0 and 1 with the probability of selection, default: .5</p></li>
<li><p><strong>pmut</strong> A float value between 0 and 1 with the probability of mutation, default: .3</p></li>
<li><p><strong>fts_method</strong> The FTS method to optimize</p></li>
<li><p><strong>parameters</strong> dict with model specific arguments for fts_method</p></li>
<li><p><strong>elitism</strong> A boolean value indicating if the best individual must always survive to next population</p></li>
<li><p><strong>initial_operator</strong> a function that receives npop and return a random population with size npop</p></li>
<li><p><strong>random_individual</strong> create an random genotype</p></li>
<li><p><strong>evalutation_operator</strong> a function that receives a dataset and an individual and return its fitness</p></li>
<li><p><strong>selection_operator</strong> a function that receives the whole population and return a selected individual</p></li>
<li><p><strong>crossover_operator</strong> a function that receives the whole population and return a descendent individual</p></li>
<li><p><strong>mutation_operator</strong> a function that receives one individual and return a changed individual</p></li>
<li><p><strong>window_size</strong> An integer value with the the length of scrolling window for train/test on dataset</p></li>
<li><p><strong>train_rate</strong> A float value between 0 and 1 with the train/test split ([0,1])</p></li>
<li><p><strong>increment_rate</strong> A float value between 0 and 1 with the the increment of the scrolling window,
relative to the window_size ([0,1])</p></li>
<li><p><strong>collect_statistics</strong> A boolean value indicating to collect statistics for each generation</p></li>
<li><p><strong>distributed</strong> A value indicating it the execution will be local and sequential (distributed=False),
or parallel and distributed (distributed=dispy or distributed=spark)</p></li>
<li><p><strong>cluster</strong> If distributed=dispy the list of cluster nodes, else if distributed=spark it is the master node</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>the best genotype</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.hyperparam.Evolutionary.genotype">
<code class="sig-prename descclassname">pyFTS.hyperparam.Evolutionary.</code><code class="sig-name descname">genotype</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">mf</span></em>, <em class="sig-param"><span class="n">npart</span></em>, <em class="sig-param"><span class="n">partitioner</span></em>, <em class="sig-param"><span class="n">order</span></em>, <em class="sig-param"><span class="n">alpha</span></em>, <em class="sig-param"><span class="n">lags</span></em>, <em class="sig-param"><span class="n">f1</span></em>, <em class="sig-param"><span class="n">f2</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/Evolutionary.html#genotype"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.Evolutionary.genotype" title="Permalink to this definition"></a></dt>
<dd><p>Create the individual genotype</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>mf</strong> membership function</p></li>
<li><p><strong>npart</strong> number of partitions</p></li>
<li><p><strong>partitioner</strong> partitioner method</p></li>
<li><p><strong>order</strong> model order</p></li>
<li><p><strong>alpha</strong> alpha-cut</p></li>
<li><p><strong>lags</strong> array with lag indexes</p></li>
<li><p><strong>f1</strong> accuracy fitness value</p></li>
<li><p><strong>f2</strong> parsimony fitness value</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>the genotype, a dictionary with all hyperparameters</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.hyperparam.Evolutionary.initial_population">
<code class="sig-prename descclassname">pyFTS.hyperparam.Evolutionary.</code><code class="sig-name descname">initial_population</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">n</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/Evolutionary.html#initial_population"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.Evolutionary.initial_population" title="Permalink to this definition"></a></dt>
<dd><p>Create a random population of size n</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>n</strong> the size of the population</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with n random individuals</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.hyperparam.Evolutionary.lag_crossover2">
<code class="sig-prename descclassname">pyFTS.hyperparam.Evolutionary.</code><code class="sig-name descname">lag_crossover2</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">best</span></em>, <em class="sig-param"><span class="n">worst</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/Evolutionary.html#lag_crossover2"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.Evolutionary.lag_crossover2" title="Permalink to this definition"></a></dt>
<dd><p>Cross over two lag genes</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>best</strong> best genotype</p></li>
<li><p><strong>worst</strong> worst genotype</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a tuple (order, lags)</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.hyperparam.Evolutionary.log_result">
<code class="sig-prename descclassname">pyFTS.hyperparam.Evolutionary.</code><code class="sig-name descname">log_result</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">conn</span></em>, <em class="sig-param"><span class="n">datasetname</span></em>, <em class="sig-param"><span class="n">fts_method</span></em>, <em class="sig-param"><span class="n">result</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/Evolutionary.html#log_result"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.Evolutionary.log_result" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="pyFTS.hyperparam.Evolutionary.mutation">
<code class="sig-prename descclassname">pyFTS.hyperparam.Evolutionary.</code><code class="sig-name descname">mutation</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">individual</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/Evolutionary.html#mutation"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.Evolutionary.mutation" title="Permalink to this definition"></a></dt>
<dd><p>Mutation operator</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>individual</strong> an individual genotype</p></li>
<li><p><strong>pmut</strong> individual probability o</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.hyperparam.Evolutionary.mutation_lags">
<code class="sig-prename descclassname">pyFTS.hyperparam.Evolutionary.</code><code class="sig-name descname">mutation_lags</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">lags</span></em>, <em class="sig-param"><span class="n">order</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/Evolutionary.html#mutation_lags"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.Evolutionary.mutation_lags" title="Permalink to this definition"></a></dt>
<dd><p>Mutation operation for lags gene</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>lags</strong> </p></li>
<li><p><strong>order</strong> </p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.hyperparam.Evolutionary.persist_statistics">
<code class="sig-prename descclassname">pyFTS.hyperparam.Evolutionary.</code><code class="sig-name descname">persist_statistics</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">datasetname</span></em>, <em class="sig-param"><span class="n">statistics</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/Evolutionary.html#persist_statistics"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.Evolutionary.persist_statistics" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="pyFTS.hyperparam.Evolutionary.phenotype">
<code class="sig-prename descclassname">pyFTS.hyperparam.Evolutionary.</code><code class="sig-name descname">phenotype</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">individual</span></em>, <em class="sig-param"><span class="n">train</span></em>, <em class="sig-param"><span class="n">fts_method</span></em>, <em class="sig-param"><span class="n">parameters</span><span class="o">=</span><span class="default_value">{}</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/Evolutionary.html#phenotype"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.Evolutionary.phenotype" title="Permalink to this definition"></a></dt>
<dd><p>Instantiate the genotype, creating a fitted model with the genotype hyperparameters</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>individual</strong> a genotype</p></li>
<li><p><strong>train</strong> the training dataset</p></li>
<li><p><strong>fts_method</strong> the FTS method</p></li>
<li><p><strong>parameters</strong> dict with model specific arguments for fit method.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a fitted FTS model</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.hyperparam.Evolutionary.process_experiment">
<code class="sig-prename descclassname">pyFTS.hyperparam.Evolutionary.</code><code class="sig-name descname">process_experiment</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">fts_method</span></em>, <em class="sig-param"><span class="n">result</span></em>, <em class="sig-param"><span class="n">datasetname</span></em>, <em class="sig-param"><span class="n">conn</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/Evolutionary.html#process_experiment"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.Evolutionary.process_experiment" title="Permalink to this definition"></a></dt>
<dd><p>Persist the results of an DEHO execution in sqlite database (best hyperparameters) and json file (generation statistics)</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>fts_method</strong> </p></li>
<li><p><strong>result</strong> </p></li>
<li><p><strong>datasetname</strong> </p></li>
<li><p><strong>conn</strong> </p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.hyperparam.Evolutionary.random_genotype">
<code class="sig-prename descclassname">pyFTS.hyperparam.Evolutionary.</code><code class="sig-name descname">random_genotype</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/Evolutionary.html#random_genotype"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.Evolutionary.random_genotype" title="Permalink to this definition"></a></dt>
<dd><p>Create random genotype</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>the genotype, a dictionary with all hyperparameters</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.hyperparam.Evolutionary.tournament">
<code class="sig-prename descclassname">pyFTS.hyperparam.Evolutionary.</code><code class="sig-name descname">tournament</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">population</span></em>, <em class="sig-param"><span class="n">objective</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/hyperparam/Evolutionary.html#tournament"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.hyperparam.Evolutionary.tournament" title="Permalink to this definition"></a></dt>
<dd><p>Simple tournament selection strategy.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>population</strong> the population</p></li>
<li><p><strong>objective</strong> the objective to be considered on tournament</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
</div>
</div>
@ -152,8 +484,8 @@ Value: the measure value</p>
<li><a class="reference internal" href="#module-pyFTS.hyperparam">Module contents</a></li>
<li><a class="reference internal" href="#submodules">Submodules</a></li>
<li><a class="reference internal" href="#module-pyFTS.hyperparam.Util">pyFTS.hyperparam.Util module</a></li>
<li><a class="reference internal" href="#pyfts-hyperparam-gridsearch-module">pyFTS.hyperparam.GridSearch module</a></li>
<li><a class="reference internal" href="#pyfts-hyperparam-evolutionary-module">pyFTS.hyperparam.Evolutionary module</a></li>
<li><a class="reference internal" href="#module-pyFTS.hyperparam.GridSearch">pyFTS.hyperparam.GridSearch module</a></li>
<li><a class="reference internal" href="#module-pyFTS.hyperparam.Evolutionary">pyFTS.hyperparam.Evolutionary module</a></li>
</ul>
</li>
</ul>

View File

@ -69,11 +69,321 @@
<div class="section" id="submodules">
<h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this headline"></a></h2>
</div>
<div class="section" id="pyfts-models-ensemble-ensemble-module">
<h2>pyFTS.models.ensemble.ensemble module<a class="headerlink" href="#pyfts-models-ensemble-ensemble-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.models.ensemble.ensemble">
<span id="pyfts-models-ensemble-ensemble-module"></span><h2>pyFTS.models.ensemble.ensemble module<a class="headerlink" href="#module-pyFTS.models.ensemble.ensemble" title="Permalink to this headline"></a></h2>
<p>EnsembleFTS wraps several FTS methods to ensemble their forecasts, providing point,
interval and probabilistic forecasting.</p>
<p>Silva, P. C. L et al. Probabilistic Forecasting with Seasonal Ensemble Fuzzy Time-Series
XIII Brazilian Congress on Computational Intelligence, 2017. Rio de Janeiro, Brazil.</p>
<dl class="py class">
<dt id="pyFTS.models.ensemble.ensemble.AllMethodEnsembleFTS">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.ensemble.ensemble.</code><code class="sig-name descname">AllMethodEnsembleFTS</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/ensemble.html#AllMethodEnsembleFTS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.AllMethodEnsembleFTS" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS" title="pyFTS.models.ensemble.ensemble.EnsembleFTS"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.models.ensemble.ensemble.EnsembleFTS</span></code></a></p>
<p>Creates an EnsembleFTS with all point forecast methods, sharing the same partitioner</p>
<dl class="py method">
<dt id="pyFTS.models.ensemble.ensemble.AllMethodEnsembleFTS.set_transformations">
<code class="sig-name descname">set_transformations</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">model</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/ensemble.html#AllMethodEnsembleFTS.set_transformations"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.AllMethodEnsembleFTS.set_transformations" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.ensemble.ensemble.AllMethodEnsembleFTS.train">
<code class="sig-name descname">train</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/ensemble.html#AllMethodEnsembleFTS.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.AllMethodEnsembleFTS.train" title="Permalink to this definition"></a></dt>
<dd><p>Method specific parameter fitting</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> training time series data</p></li>
<li><p><strong>kwargs</strong> Method specific parameters</p></li>
</ul>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt id="pyFTS.models.ensemble.ensemble.EnsembleFTS">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.ensemble.ensemble.</code><code class="sig-name descname">EnsembleFTS</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/ensemble.html#EnsembleFTS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="pyFTS.common.html#pyFTS.common.fts.FTS" title="pyFTS.common.fts.FTS"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.common.fts.FTS</span></code></a></p>
<p>Ensemble FTS</p>
<dl class="py attribute">
<dt id="pyFTS.models.ensemble.ensemble.EnsembleFTS.alpha">
<code class="sig-name descname">alpha</code><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS.alpha" title="Permalink to this definition"></a></dt>
<dd><p>The quantiles</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.ensemble.ensemble.EnsembleFTS.append_model">
<code class="sig-name descname">append_model</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">model</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/ensemble.html#EnsembleFTS.append_model"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS.append_model" title="Permalink to this definition"></a></dt>
<dd><p>Append a new trained model to the ensemble</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>model</strong> FTS model</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.ensemble.ensemble.EnsembleFTS.forecast">
<code class="sig-name descname">forecast</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/ensemble.html#EnsembleFTS.forecast"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS.forecast" title="Permalink to this definition"></a></dt>
<dd><p>Point forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.ensemble.ensemble.EnsembleFTS.forecast_ahead_distribution">
<code class="sig-name descname">forecast_ahead_distribution</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">steps</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/ensemble.html#EnsembleFTS.forecast_ahead_distribution"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS.forecast_ahead_distribution" title="Permalink to this definition"></a></dt>
<dd><p>Probabilistic forecast from 1 to H steps ahead, where H is given by the steps parameter</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>steps</strong> the number of steps ahead to forecast</p></li>
<li><p><strong>start_at</strong> in the multi step forecasting, the index of the data where to start forecasting (default: 0)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted Probability Distributions</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.ensemble.ensemble.EnsembleFTS.forecast_ahead_interval">
<code class="sig-name descname">forecast_ahead_interval</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">steps</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/ensemble.html#EnsembleFTS.forecast_ahead_interval"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS.forecast_ahead_interval" title="Permalink to this definition"></a></dt>
<dd><p>Interval forecast from 1 to H steps ahead, where H is given by the steps parameter</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>steps</strong> the number of steps ahead to forecast</p></li>
<li><p><strong>start_at</strong> in the multi step forecasting, the index of the data where to start forecasting (default: 0)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted intervals</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.ensemble.ensemble.EnsembleFTS.forecast_distribution">
<code class="sig-name descname">forecast_distribution</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/ensemble.html#EnsembleFTS.forecast_distribution"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS.forecast_distribution" title="Permalink to this definition"></a></dt>
<dd><p>Probabilistic forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with probabilistic.ProbabilityDistribution objects representing the forecasted Probability Distributions</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.ensemble.ensemble.EnsembleFTS.forecast_interval">
<code class="sig-name descname">forecast_interval</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/ensemble.html#EnsembleFTS.forecast_interval"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS.forecast_interval" title="Permalink to this definition"></a></dt>
<dd><p>Interval forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the prediction intervals</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.ensemble.ensemble.EnsembleFTS.get_UoD">
<code class="sig-name descname">get_UoD</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/ensemble.html#EnsembleFTS.get_UoD"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS.get_UoD" title="Permalink to this definition"></a></dt>
<dd><p>Returns the interval of the known bounds of the universe of discourse (UoD), i. e.,
the known minimum and maximum values of the time series.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>A set with the lower and the upper bounds of the UoD</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.ensemble.ensemble.EnsembleFTS.get_distribution_interquantile">
<code class="sig-name descname">get_distribution_interquantile</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">forecasts</span></em>, <em class="sig-param"><span class="n">alpha</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/ensemble.html#EnsembleFTS.get_distribution_interquantile"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS.get_distribution_interquantile" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.ensemble.ensemble.EnsembleFTS.get_interval">
<code class="sig-name descname">get_interval</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">forecasts</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/ensemble.html#EnsembleFTS.get_interval"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS.get_interval" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.ensemble.ensemble.EnsembleFTS.get_models_forecasts">
<code class="sig-name descname">get_models_forecasts</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/ensemble.html#EnsembleFTS.get_models_forecasts"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS.get_models_forecasts" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.ensemble.ensemble.EnsembleFTS.get_point">
<code class="sig-name descname">get_point</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">forecasts</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/ensemble.html#EnsembleFTS.get_point"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS.get_point" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.ensemble.ensemble.EnsembleFTS.interval_method">
<code class="sig-name descname">interval_method</code><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS.interval_method" title="Permalink to this definition"></a></dt>
<dd><p>The method used to mix the several models forecasts into a interval forecast. Options: quantile, extremum, normal</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.ensemble.ensemble.EnsembleFTS.models">
<code class="sig-name descname">models</code><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS.models" title="Permalink to this definition"></a></dt>
<dd><p>A list of FTS models, the ensemble components</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.ensemble.ensemble.EnsembleFTS.parameters">
<code class="sig-name descname">parameters</code><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS.parameters" title="Permalink to this definition"></a></dt>
<dd><p>A list with the parameters for each component model</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.ensemble.ensemble.EnsembleFTS.point_method">
<code class="sig-name descname">point_method</code><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS.point_method" title="Permalink to this definition"></a></dt>
<dd><p>The method used to mix the several models forecasts into a unique point forecast. Options: mean, median, quantile, exponential</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.ensemble.ensemble.EnsembleFTS.train">
<code class="sig-name descname">train</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/ensemble.html#EnsembleFTS.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS.train" title="Permalink to this definition"></a></dt>
<dd><p>Method specific parameter fitting</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> training time series data</p></li>
<li><p><strong>kwargs</strong> Method specific parameters</p></li>
</ul>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt id="pyFTS.models.ensemble.ensemble.SimpleEnsembleFTS">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.ensemble.ensemble.</code><code class="sig-name descname">SimpleEnsembleFTS</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/ensemble.html#SimpleEnsembleFTS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.SimpleEnsembleFTS" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS" title="pyFTS.models.ensemble.ensemble.EnsembleFTS"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.models.ensemble.ensemble.EnsembleFTS</span></code></a></p>
<p>An homogeneous FTS method ensemble with variations on partitionings and orders.</p>
<dl class="py attribute">
<dt id="pyFTS.models.ensemble.ensemble.SimpleEnsembleFTS.method">
<code class="sig-name descname">method</code><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.SimpleEnsembleFTS.method" title="Permalink to this definition"></a></dt>
<dd><p>FTS method class that will be used on internal models</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.ensemble.ensemble.SimpleEnsembleFTS.orders">
<code class="sig-name descname">orders</code><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.SimpleEnsembleFTS.orders" title="Permalink to this definition"></a></dt>
<dd><p>Possible variations of order on internal models</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.ensemble.ensemble.SimpleEnsembleFTS.partitioner_method">
<code class="sig-name descname">partitioner_method</code><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.SimpleEnsembleFTS.partitioner_method" title="Permalink to this definition"></a></dt>
<dd><p>UoD partitioner class that will be used on internal methods</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.ensemble.ensemble.SimpleEnsembleFTS.partitions">
<code class="sig-name descname">partitions</code><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.SimpleEnsembleFTS.partitions" title="Permalink to this definition"></a></dt>
<dd><p>Possible variations of number of partitions on internal models</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.ensemble.ensemble.SimpleEnsembleFTS.train">
<code class="sig-name descname">train</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/ensemble.html#SimpleEnsembleFTS.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.SimpleEnsembleFTS.train" title="Permalink to this definition"></a></dt>
<dd><p>Method specific parameter fitting</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> training time series data</p></li>
<li><p><strong>kwargs</strong> Method specific parameters</p></li>
</ul>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.models.ensemble.ensemble.sampler">
<code class="sig-prename descclassname">pyFTS.models.ensemble.ensemble.</code><code class="sig-name descname">sampler</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">quantiles</span></em>, <em class="sig-param"><span class="n">bounds</span><span class="o">=</span><span class="default_value">False</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/ensemble.html#sampler"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.ensemble.sampler" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</div>
<div class="section" id="pyfts-models-ensemble-multiseasonal-module">
<h2>pyFTS.models.ensemble.multiseasonal module<a class="headerlink" href="#pyfts-models-ensemble-multiseasonal-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.models.ensemble.multiseasonal">
<span id="pyfts-models-ensemble-multiseasonal-module"></span><h2>pyFTS.models.ensemble.multiseasonal module<a class="headerlink" href="#module-pyFTS.models.ensemble.multiseasonal" title="Permalink to this headline"></a></h2>
<p>Silva, P. C. L et al. Probabilistic Forecasting with Seasonal Ensemble Fuzzy Time-Series
XIII Brazilian Congress on Computational Intelligence, 2017. Rio de Janeiro, Brazil.</p>
<dl class="py class">
<dt id="pyFTS.models.ensemble.multiseasonal.SeasonalEnsembleFTS">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.ensemble.multiseasonal.</code><code class="sig-name descname">SeasonalEnsembleFTS</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">name</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/multiseasonal.html#SeasonalEnsembleFTS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.multiseasonal.SeasonalEnsembleFTS" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#pyFTS.models.ensemble.ensemble.EnsembleFTS" title="pyFTS.models.ensemble.ensemble.EnsembleFTS"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.models.ensemble.ensemble.EnsembleFTS</span></code></a></p>
<dl class="py method">
<dt id="pyFTS.models.ensemble.multiseasonal.SeasonalEnsembleFTS.forecast_distribution">
<code class="sig-name descname">forecast_distribution</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/multiseasonal.html#SeasonalEnsembleFTS.forecast_distribution"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.multiseasonal.SeasonalEnsembleFTS.forecast_distribution" title="Permalink to this definition"></a></dt>
<dd><p>Probabilistic forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with probabilistic.ProbabilityDistribution objects representing the forecasted Probability Distributions</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.ensemble.multiseasonal.SeasonalEnsembleFTS.train">
<code class="sig-name descname">train</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/multiseasonal.html#SeasonalEnsembleFTS.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.multiseasonal.SeasonalEnsembleFTS.train" title="Permalink to this definition"></a></dt>
<dd><p>Method specific parameter fitting</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> training time series data</p></li>
<li><p><strong>kwargs</strong> Method specific parameters</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.ensemble.multiseasonal.SeasonalEnsembleFTS.update_uod">
<code class="sig-name descname">update_uod</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/multiseasonal.html#SeasonalEnsembleFTS.update_uod"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.multiseasonal.SeasonalEnsembleFTS.update_uod" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.models.ensemble.multiseasonal.train_individual_model">
<code class="sig-prename descclassname">pyFTS.models.ensemble.multiseasonal.</code><code class="sig-name descname">train_individual_model</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">partitioner</span></em>, <em class="sig-param"><span class="n">train_data</span></em>, <em class="sig-param"><span class="n">indexer</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/ensemble/multiseasonal.html#train_individual_model"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.ensemble.multiseasonal.train_individual_model" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</div>
<div class="section" id="module-pyFTS.models.ensemble">
<span id="module-contents"></span><h2>Module contents<a class="headerlink" href="#module-pyFTS.models.ensemble" title="Permalink to this headline"></a></h2>
@ -92,8 +402,8 @@
<ul>
<li><a class="reference internal" href="#">pyFTS.models.ensemble package</a><ul>
<li><a class="reference internal" href="#submodules">Submodules</a></li>
<li><a class="reference internal" href="#pyfts-models-ensemble-ensemble-module">pyFTS.models.ensemble.ensemble module</a></li>
<li><a class="reference internal" href="#pyfts-models-ensemble-multiseasonal-module">pyFTS.models.ensemble.multiseasonal module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.ensemble.ensemble">pyFTS.models.ensemble.ensemble module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.ensemble.multiseasonal">pyFTS.models.ensemble.multiseasonal module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.ensemble">Module contents</a></li>
</ul>
</li>

File diff suppressed because it is too large Load Diff

View File

@ -73,11 +73,250 @@
<div class="section" id="submodules">
<h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this headline"></a></h2>
</div>
<div class="section" id="pyfts-models-incremental-timevariant-module">
<h2>pyFTS.models.incremental.TimeVariant module<a class="headerlink" href="#pyfts-models-incremental-timevariant-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.models.incremental.TimeVariant">
<span id="pyfts-models-incremental-timevariant-module"></span><h2>pyFTS.models.incremental.TimeVariant module<a class="headerlink" href="#module-pyFTS.models.incremental.TimeVariant" title="Permalink to this headline"></a></h2>
<p>Meta model that wraps another FTS method and continously retrain it using a data window with
the most recent data</p>
<dl class="py class">
<dt id="pyFTS.models.incremental.TimeVariant.Retrainer">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.incremental.TimeVariant.</code><code class="sig-name descname">Retrainer</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/incremental/TimeVariant.html#Retrainer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.incremental.TimeVariant.Retrainer" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="pyFTS.common.html#pyFTS.common.fts.FTS" title="pyFTS.common.fts.FTS"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.common.fts.FTS</span></code></a></p>
<p>Meta model for incremental/online learning that retrain its internal model after
data windows controlled by the parameter batch_size, using as the training data a
window of recent lags, whose size is controlled by the parameter window_length.</p>
<dl class="py attribute">
<dt id="pyFTS.models.incremental.TimeVariant.Retrainer.auto_update">
<code class="sig-name descname">auto_update</code><a class="headerlink" href="#pyFTS.models.incremental.TimeVariant.Retrainer.auto_update" title="Permalink to this definition"></a></dt>
<dd><p>If true the model is updated at each time and not recreated</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.incremental.TimeVariant.Retrainer.batch_size">
<code class="sig-name descname">batch_size</code><a class="headerlink" href="#pyFTS.models.incremental.TimeVariant.Retrainer.batch_size" title="Permalink to this definition"></a></dt>
<dd><p>The batch interval between each retraining</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.incremental.TimeVariant.Retrainer.forecast">
<code class="sig-name descname">forecast</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/incremental/TimeVariant.html#Retrainer.forecast"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.incremental.TimeVariant.Retrainer.forecast" title="Permalink to this definition"></a></dt>
<dd><p>Point forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.incremental.TimeVariant.Retrainer.forecast_ahead">
<code class="sig-name descname">forecast_ahead</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">steps</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/incremental/TimeVariant.html#Retrainer.forecast_ahead"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.incremental.TimeVariant.Retrainer.forecast_ahead" title="Permalink to this definition"></a></dt>
<dd><p>Point forecast from 1 to H steps ahead, where H is given by the steps parameter</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>steps</strong> the number of steps ahead to forecast (default: 1)</p></li>
<li><p><strong>start_at</strong> in the multi step forecasting, the index of the data where to start forecasting (default: 0)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted values</p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.incremental.TimeVariant.Retrainer.fts_method">
<code class="sig-name descname">fts_method</code><a class="headerlink" href="#pyFTS.models.incremental.TimeVariant.Retrainer.fts_method" title="Permalink to this definition"></a></dt>
<dd><p>The FTS method to be called when a new model is build</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.incremental.TimeVariant.Retrainer.fts_params">
<code class="sig-name descname">fts_params</code><a class="headerlink" href="#pyFTS.models.incremental.TimeVariant.Retrainer.fts_params" title="Permalink to this definition"></a></dt>
<dd><p>The FTS method specific parameters</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.incremental.TimeVariant.Retrainer.model">
<code class="sig-name descname">model</code><a class="headerlink" href="#pyFTS.models.incremental.TimeVariant.Retrainer.model" title="Permalink to this definition"></a></dt>
<dd><p>The most recent trained model</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.incremental.TimeVariant.Retrainer.offset">
<code class="sig-name descname">offset</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/incremental/TimeVariant.html#Retrainer.offset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.incremental.TimeVariant.Retrainer.offset" title="Permalink to this definition"></a></dt>
<dd><p>Returns the number of lags to skip in the input test data in order to synchronize it with
the forecasted values given by the predict function. This is necessary due to the order of the
model, among other parameters.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>An integer with the number of lags to skip</p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.incremental.TimeVariant.Retrainer.partitioner">
<code class="sig-name descname">partitioner</code><a class="headerlink" href="#pyFTS.models.incremental.TimeVariant.Retrainer.partitioner" title="Permalink to this definition"></a></dt>
<dd><p>The most recent trained partitioner</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.incremental.TimeVariant.Retrainer.partitioner_method">
<code class="sig-name descname">partitioner_method</code><a class="headerlink" href="#pyFTS.models.incremental.TimeVariant.Retrainer.partitioner_method" title="Permalink to this definition"></a></dt>
<dd><p>The partitioner method to be called when a new model is build</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.incremental.TimeVariant.Retrainer.partitioner_params">
<code class="sig-name descname">partitioner_params</code><a class="headerlink" href="#pyFTS.models.incremental.TimeVariant.Retrainer.partitioner_params" title="Permalink to this definition"></a></dt>
<dd><p>The partitioner method parameters</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.incremental.TimeVariant.Retrainer.train">
<code class="sig-name descname">train</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/incremental/TimeVariant.html#Retrainer.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.incremental.TimeVariant.Retrainer.train" title="Permalink to this definition"></a></dt>
<dd><p>Method specific parameter fitting</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> training time series data</p></li>
<li><p><strong>kwargs</strong> Method specific parameters</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.incremental.TimeVariant.Retrainer.window_length">
<code class="sig-name descname">window_length</code><a class="headerlink" href="#pyFTS.models.incremental.TimeVariant.Retrainer.window_length" title="Permalink to this definition"></a></dt>
<dd><p>The memory window length</p>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="pyfts-models-incremental-incrementalensemble-module">
<h2>pyFTS.models.incremental.IncrementalEnsemble module<a class="headerlink" href="#pyfts-models-incremental-incrementalensemble-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.models.incremental.IncrementalEnsemble">
<span id="pyfts-models-incremental-incrementalensemble-module"></span><h2>pyFTS.models.incremental.IncrementalEnsemble module<a class="headerlink" href="#module-pyFTS.models.incremental.IncrementalEnsemble" title="Permalink to this headline"></a></h2>
<p>Time Variant/Incremental Ensemble of FTS methods</p>
<dl class="py class">
<dt id="pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.incremental.IncrementalEnsemble.</code><code class="sig-name descname">IncrementalEnsembleFTS</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/incremental/IncrementalEnsemble.html#IncrementalEnsembleFTS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="pyFTS.models.ensemble.html#pyFTS.models.ensemble.ensemble.EnsembleFTS" title="pyFTS.models.ensemble.ensemble.EnsembleFTS"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.models.ensemble.ensemble.EnsembleFTS</span></code></a></p>
<p>Time Variant/Incremental Ensemble of FTS methods</p>
<dl class="py attribute">
<dt id="pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.batch_size">
<code class="sig-name descname">batch_size</code><a class="headerlink" href="#pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.batch_size" title="Permalink to this definition"></a></dt>
<dd><p>The batch interval between each retraining</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.forecast">
<code class="sig-name descname">forecast</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/incremental/IncrementalEnsemble.html#IncrementalEnsembleFTS.forecast"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.forecast" title="Permalink to this definition"></a></dt>
<dd><p>Point forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.forecast_ahead">
<code class="sig-name descname">forecast_ahead</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">steps</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/incremental/IncrementalEnsemble.html#IncrementalEnsembleFTS.forecast_ahead"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.forecast_ahead" title="Permalink to this definition"></a></dt>
<dd><p>Point forecast from 1 to H steps ahead, where H is given by the steps parameter</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>steps</strong> the number of steps ahead to forecast (default: 1)</p></li>
<li><p><strong>start_at</strong> in the multi step forecasting, the index of the data where to start forecasting (default: 0)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted values</p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.fts_method">
<code class="sig-name descname">fts_method</code><a class="headerlink" href="#pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.fts_method" title="Permalink to this definition"></a></dt>
<dd><p>The FTS method to be called when a new model is build</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.fts_params">
<code class="sig-name descname">fts_params</code><a class="headerlink" href="#pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.fts_params" title="Permalink to this definition"></a></dt>
<dd><p>The FTS method specific parameters</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.num_models">
<code class="sig-name descname">num_models</code><a class="headerlink" href="#pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.num_models" title="Permalink to this definition"></a></dt>
<dd><p>The number of models to hold in the ensemble</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.offset">
<code class="sig-name descname">offset</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/incremental/IncrementalEnsemble.html#IncrementalEnsembleFTS.offset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.offset" title="Permalink to this definition"></a></dt>
<dd><p>Returns the number of lags to skip in the input test data in order to synchronize it with
the forecasted values given by the predict function. This is necessary due to the order of the
model, among other parameters.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>An integer with the number of lags to skip</p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.partitioner_method">
<code class="sig-name descname">partitioner_method</code><a class="headerlink" href="#pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.partitioner_method" title="Permalink to this definition"></a></dt>
<dd><p>The partitioner method to be called when a new model is build</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.partitioner_params">
<code class="sig-name descname">partitioner_params</code><a class="headerlink" href="#pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.partitioner_params" title="Permalink to this definition"></a></dt>
<dd><p>The partitioner method parameters</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.train">
<code class="sig-name descname">train</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/incremental/IncrementalEnsemble.html#IncrementalEnsembleFTS.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.train" title="Permalink to this definition"></a></dt>
<dd><p>Method specific parameter fitting</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> training time series data</p></li>
<li><p><strong>kwargs</strong> Method specific parameters</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.window_length">
<code class="sig-name descname">window_length</code><a class="headerlink" href="#pyFTS.models.incremental.IncrementalEnsemble.IncrementalEnsembleFTS.window_length" title="Permalink to this definition"></a></dt>
<dd><p>The memory window length</p>
</dd></dl>
</dd></dl>
</div>
</div>
@ -93,8 +332,8 @@
<li><a class="reference internal" href="#">pyFTS.models.incremental package</a><ul>
<li><a class="reference internal" href="#module-pyFTS.models.incremental">Module contents</a></li>
<li><a class="reference internal" href="#submodules">Submodules</a></li>
<li><a class="reference internal" href="#pyfts-models-incremental-timevariant-module">pyFTS.models.incremental.TimeVariant module</a></li>
<li><a class="reference internal" href="#pyfts-models-incremental-incrementalensemble-module">pyFTS.models.incremental.IncrementalEnsemble module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.incremental.TimeVariant">pyFTS.models.incremental.TimeVariant module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.incremental.IncrementalEnsemble">pyFTS.models.incremental.IncrementalEnsemble module</a></li>
</ul>
</li>
</ul>

View File

@ -146,8 +146,87 @@
<dd></dd></dl>
</div>
<div class="section" id="pyfts-models-multivariate-variable-module">
<h2>pyFTS.models.multivariate.variable module<a class="headerlink" href="#pyfts-models-multivariate-variable-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.models.multivariate.variable">
<span id="pyfts-models-multivariate-variable-module"></span><h2>pyFTS.models.multivariate.variable module<a class="headerlink" href="#module-pyFTS.models.multivariate.variable" title="Permalink to this headline"></a></h2>
<dl class="py class">
<dt id="pyFTS.models.multivariate.variable.Variable">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.multivariate.variable.</code><code class="sig-name descname">Variable</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">name</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/variable.html#Variable"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.variable.Variable" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a></p>
<p>A variable of a fuzzy time series multivariate model. Each variable contains its own
transformations and partitioners.</p>
<dl class="py attribute">
<dt id="pyFTS.models.multivariate.variable.Variable.alias">
<code class="sig-name descname">alias</code><a class="headerlink" href="#pyFTS.models.multivariate.variable.Variable.alias" title="Permalink to this definition"></a></dt>
<dd><p>A string with the alias of the variable</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.multivariate.variable.Variable.alpha_cut">
<code class="sig-name descname">alpha_cut</code><a class="headerlink" href="#pyFTS.models.multivariate.variable.Variable.alpha_cut" title="Permalink to this definition"></a></dt>
<dd><p>Minimal membership value to be considered on fuzzyfication process</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.variable.Variable.apply_inverse_transformations">
<code class="sig-name descname">apply_inverse_transformations</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/variable.html#Variable.apply_inverse_transformations"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.variable.Variable.apply_inverse_transformations" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.variable.Variable.apply_transformations">
<code class="sig-name descname">apply_transformations</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/variable.html#Variable.apply_transformations"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.variable.Variable.apply_transformations" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.variable.Variable.build">
<code class="sig-name descname">build</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/variable.html#Variable.build"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.variable.Variable.build" title="Permalink to this definition"></a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>kwargs</strong> </p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.multivariate.variable.Variable.data_label">
<code class="sig-name descname">data_label</code><a class="headerlink" href="#pyFTS.models.multivariate.variable.Variable.data_label" title="Permalink to this definition"></a></dt>
<dd><p>A string with the column name on DataFrame</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.multivariate.variable.Variable.data_type">
<code class="sig-name descname">data_type</code><a class="headerlink" href="#pyFTS.models.multivariate.variable.Variable.data_type" title="Permalink to this definition"></a></dt>
<dd><p>The type of the data column on Pandas Dataframe</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.multivariate.variable.Variable.mask">
<code class="sig-name descname">mask</code><a class="headerlink" href="#pyFTS.models.multivariate.variable.Variable.mask" title="Permalink to this definition"></a></dt>
<dd><p>The mask for format the data column on Pandas Dataframe</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.multivariate.variable.Variable.name">
<code class="sig-name descname">name</code><a class="headerlink" href="#pyFTS.models.multivariate.variable.Variable.name" title="Permalink to this definition"></a></dt>
<dd><p>A string with the name of the variable</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.multivariate.variable.Variable.partitioner">
<code class="sig-name descname">partitioner</code><a class="headerlink" href="#pyFTS.models.multivariate.variable.Variable.partitioner" title="Permalink to this definition"></a></dt>
<dd><p>UoD partitioner for the variable data</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.multivariate.variable.Variable.transformation">
<code class="sig-name descname">transformation</code><a class="headerlink" href="#pyFTS.models.multivariate.variable.Variable.transformation" title="Permalink to this definition"></a></dt>
<dd><p>Pre processing transformation for the variable</p>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="module-pyFTS.models.multivariate.flrg">
<span id="pyfts-models-multivariate-flrg-module"></span><h2>pyFTS.models.multivariate.flrg module<a class="headerlink" href="#module-pyFTS.models.multivariate.flrg" title="Permalink to this headline"></a></h2>
@ -364,17 +443,436 @@ multivariate fuzzy set base.</p>
</dd></dl>
</div>
<div class="section" id="pyfts-models-multivariate-mvfts-module">
<h2>pyFTS.models.multivariate.mvfts module<a class="headerlink" href="#pyfts-models-multivariate-mvfts-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.models.multivariate.mvfts">
<span id="pyfts-models-multivariate-mvfts-module"></span><h2>pyFTS.models.multivariate.mvfts module<a class="headerlink" href="#module-pyFTS.models.multivariate.mvfts" title="Permalink to this headline"></a></h2>
<dl class="py class">
<dt id="pyFTS.models.multivariate.mvfts.MVFTS">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.multivariate.mvfts.</code><code class="sig-name descname">MVFTS</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/mvfts.html#MVFTS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.mvfts.MVFTS" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="pyFTS.common.html#pyFTS.common.fts.FTS" title="pyFTS.common.fts.FTS"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.common.fts.FTS</span></code></a></p>
<p>Multivariate extension of Chens ConventionalFTS method</p>
<dl class="py method">
<dt id="pyFTS.models.multivariate.mvfts.MVFTS.append_transformation">
<code class="sig-name descname">append_transformation</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">transformation</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/mvfts.html#MVFTS.append_transformation"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.mvfts.MVFTS.append_transformation" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.mvfts.MVFTS.append_variable">
<code class="sig-name descname">append_variable</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">var</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/mvfts.html#MVFTS.append_variable"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.mvfts.MVFTS.append_variable" title="Permalink to this definition"></a></dt>
<dd><p>Append a new endogenous variable to the model</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>var</strong> variable object</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.mvfts.MVFTS.apply_transformations">
<code class="sig-name descname">apply_transformations</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">params</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">updateUoD</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/mvfts.html#MVFTS.apply_transformations"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.mvfts.MVFTS.apply_transformations" title="Permalink to this definition"></a></dt>
<dd><p>Apply the data transformations for data preprocessing</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> input data</p></li>
<li><p><strong>params</strong> transformation parameters</p></li>
<li><p><strong>updateUoD</strong> </p></li>
<li><p><strong>kwargs</strong> </p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>preprocessed data</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.mvfts.MVFTS.clone_parameters">
<code class="sig-name descname">clone_parameters</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">model</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/mvfts.html#MVFTS.clone_parameters"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.mvfts.MVFTS.clone_parameters" title="Permalink to this definition"></a></dt>
<dd><p>Import the parameters values from other model</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>model</strong> a model to clone the parameters</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.mvfts.MVFTS.forecast">
<code class="sig-name descname">forecast</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/mvfts.html#MVFTS.forecast"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.mvfts.MVFTS.forecast" title="Permalink to this definition"></a></dt>
<dd><p>Point forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.mvfts.MVFTS.forecast_ahead">
<code class="sig-name descname">forecast_ahead</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">steps</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/mvfts.html#MVFTS.forecast_ahead"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.mvfts.MVFTS.forecast_ahead" title="Permalink to this definition"></a></dt>
<dd><p>Point forecast from 1 to H steps ahead, where H is given by the steps parameter</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>steps</strong> the number of steps ahead to forecast (default: 1)</p></li>
<li><p><strong>start_at</strong> in the multi step forecasting, the index of the data where to start forecasting (default: 0)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.mvfts.MVFTS.forecast_ahead_interval">
<code class="sig-name descname">forecast_ahead_interval</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">steps</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/mvfts.html#MVFTS.forecast_ahead_interval"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.mvfts.MVFTS.forecast_ahead_interval" title="Permalink to this definition"></a></dt>
<dd><p>Interval forecast from 1 to H steps ahead, where H is given by the steps parameter</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>steps</strong> the number of steps ahead to forecast</p></li>
<li><p><strong>start_at</strong> in the multi step forecasting, the index of the data where to start forecasting (default: 0)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted intervals</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.mvfts.MVFTS.forecast_interval">
<code class="sig-name descname">forecast_interval</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/mvfts.html#MVFTS.forecast_interval"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.mvfts.MVFTS.forecast_interval" title="Permalink to this definition"></a></dt>
<dd><p>Interval forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the prediction intervals</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.mvfts.MVFTS.format_data">
<code class="sig-name descname">format_data</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/mvfts.html#MVFTS.format_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.mvfts.MVFTS.format_data" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.mvfts.MVFTS.generate_flrg">
<code class="sig-name descname">generate_flrg</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">flrs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/mvfts.html#MVFTS.generate_flrg"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.mvfts.MVFTS.generate_flrg" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.mvfts.MVFTS.generate_flrs">
<code class="sig-name descname">generate_flrs</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/mvfts.html#MVFTS.generate_flrs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.mvfts.MVFTS.generate_flrs" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.mvfts.MVFTS.generate_lhs_flrs">
<code class="sig-name descname">generate_lhs_flrs</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/mvfts.html#MVFTS.generate_lhs_flrs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.mvfts.MVFTS.generate_lhs_flrs" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.mvfts.MVFTS.train">
<code class="sig-name descname">train</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/mvfts.html#MVFTS.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.mvfts.MVFTS.train" title="Permalink to this definition"></a></dt>
<dd><p>Method specific parameter fitting</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> training time series data</p></li>
<li><p><strong>kwargs</strong> Method specific parameters</p></li>
</ul>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.models.multivariate.mvfts.product_dict">
<code class="sig-prename descclassname">pyFTS.models.multivariate.mvfts.</code><code class="sig-name descname">product_dict</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/mvfts.html#product_dict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.mvfts.product_dict" title="Permalink to this definition"></a></dt>
<dd><p>Code by Seth Johnson
:param kwargs:
:return:</p>
</dd></dl>
</div>
<div class="section" id="pyfts-models-multivariate-wmvfts-module">
<h2>pyFTS.models.multivariate.wmvfts module<a class="headerlink" href="#pyfts-models-multivariate-wmvfts-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.models.multivariate.wmvfts">
<span id="pyfts-models-multivariate-wmvfts-module"></span><h2>pyFTS.models.multivariate.wmvfts module<a class="headerlink" href="#module-pyFTS.models.multivariate.wmvfts" title="Permalink to this headline"></a></h2>
<dl class="py class">
<dt id="pyFTS.models.multivariate.wmvfts.WeightedFLRG">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.multivariate.wmvfts.</code><code class="sig-name descname">WeightedFLRG</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/wmvfts.html#WeightedFLRG"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.wmvfts.WeightedFLRG" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#pyFTS.models.multivariate.flrg.FLRG" title="pyFTS.models.multivariate.flrg.FLRG"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.models.multivariate.flrg.FLRG</span></code></a></p>
<p>Weighted Multivariate Fuzzy Logical Rule Group</p>
<dl class="py method">
<dt id="pyFTS.models.multivariate.wmvfts.WeightedFLRG.append_rhs">
<code class="sig-name descname">append_rhs</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">fset</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/wmvfts.html#WeightedFLRG.append_rhs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.wmvfts.WeightedFLRG.append_rhs" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.wmvfts.WeightedFLRG.get_lower">
<code class="sig-name descname">get_lower</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">sets</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/wmvfts.html#WeightedFLRG.get_lower"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.wmvfts.WeightedFLRG.get_lower" title="Permalink to this definition"></a></dt>
<dd><p>Returns the lower bound value for the RHS fuzzy sets</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>sets</strong> fuzzy sets</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>lower bound value</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.wmvfts.WeightedFLRG.get_midpoint">
<code class="sig-name descname">get_midpoint</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">sets</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/wmvfts.html#WeightedFLRG.get_midpoint"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.wmvfts.WeightedFLRG.get_midpoint" title="Permalink to this definition"></a></dt>
<dd><p>Returns the midpoint value for the RHS fuzzy sets</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>sets</strong> fuzzy sets</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>the midpoint value</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.wmvfts.WeightedFLRG.get_upper">
<code class="sig-name descname">get_upper</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">sets</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/wmvfts.html#WeightedFLRG.get_upper"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.wmvfts.WeightedFLRG.get_upper" title="Permalink to this definition"></a></dt>
<dd><p>Returns the upper bound value for the RHS fuzzy sets</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>sets</strong> fuzzy sets</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>upper bound value</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.wmvfts.WeightedFLRG.weights">
<code class="sig-name descname">weights</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/wmvfts.html#WeightedFLRG.weights"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.wmvfts.WeightedFLRG.weights" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
<dl class="py class">
<dt id="pyFTS.models.multivariate.wmvfts.WeightedMVFTS">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.multivariate.wmvfts.</code><code class="sig-name descname">WeightedMVFTS</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/wmvfts.html#WeightedMVFTS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.wmvfts.WeightedMVFTS" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#pyFTS.models.multivariate.mvfts.MVFTS" title="pyFTS.models.multivariate.mvfts.MVFTS"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.models.multivariate.mvfts.MVFTS</span></code></a></p>
<p>Weighted Multivariate FTS</p>
<dl class="py method">
<dt id="pyFTS.models.multivariate.wmvfts.WeightedMVFTS.generate_flrg">
<code class="sig-name descname">generate_flrg</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">flrs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/wmvfts.html#WeightedMVFTS.generate_flrg"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.wmvfts.WeightedMVFTS.generate_flrg" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
</div>
<div class="section" id="pyfts-models-multivariate-cmvfts-module">
<h2>pyFTS.models.multivariate.cmvfts module<a class="headerlink" href="#pyfts-models-multivariate-cmvfts-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.models.multivariate.cmvfts">
<span id="pyfts-models-multivariate-cmvfts-module"></span><h2>pyFTS.models.multivariate.cmvfts module<a class="headerlink" href="#module-pyFTS.models.multivariate.cmvfts" title="Permalink to this headline"></a></h2>
<dl class="py class">
<dt id="pyFTS.models.multivariate.cmvfts.ClusteredMVFTS">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.multivariate.cmvfts.</code><code class="sig-name descname">ClusteredMVFTS</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/cmvfts.html#ClusteredMVFTS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#pyFTS.models.multivariate.mvfts.MVFTS" title="pyFTS.models.multivariate.mvfts.MVFTS"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.models.multivariate.mvfts.MVFTS</span></code></a></p>
<p>Meta model for high order, clustered multivariate FTS</p>
<dl class="py method">
<dt id="pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.check_data">
<code class="sig-name descname">check_data</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/cmvfts.html#ClusteredMVFTS.check_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.check_data" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.forecast">
<code class="sig-name descname">forecast</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/cmvfts.html#ClusteredMVFTS.forecast"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.forecast" title="Permalink to this definition"></a></dt>
<dd><p>Point forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.forecast_ahead_distribution">
<code class="sig-name descname">forecast_ahead_distribution</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">steps</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/cmvfts.html#ClusteredMVFTS.forecast_ahead_distribution"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.forecast_ahead_distribution" title="Permalink to this definition"></a></dt>
<dd><p>Probabilistic forecast from 1 to H steps ahead, where H is given by the steps parameter</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>steps</strong> the number of steps ahead to forecast</p></li>
<li><p><strong>start_at</strong> in the multi step forecasting, the index of the data where to start forecasting (default: 0)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted Probability Distributions</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.forecast_ahead_multivariate">
<code class="sig-name descname">forecast_ahead_multivariate</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">steps</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/cmvfts.html#ClusteredMVFTS.forecast_ahead_multivariate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.forecast_ahead_multivariate" title="Permalink to this definition"></a></dt>
<dd><p>Multivariate forecast n step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> Pandas dataframe with one column for each variable and with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>steps</strong> the number of steps ahead to forecast</p></li>
<li><p><strong>start_at</strong> in the multi step forecasting, the index of the data where to start forecasting (default: 0)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a Pandas Dataframe object representing the forecasted values for each variable</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.forecast_distribution">
<code class="sig-name descname">forecast_distribution</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/cmvfts.html#ClusteredMVFTS.forecast_distribution"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.forecast_distribution" title="Permalink to this definition"></a></dt>
<dd><p>Probabilistic forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with probabilistic.ProbabilityDistribution objects representing the forecasted Probability Distributions</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.forecast_interval">
<code class="sig-name descname">forecast_interval</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/cmvfts.html#ClusteredMVFTS.forecast_interval"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.forecast_interval" title="Permalink to this definition"></a></dt>
<dd><p>Interval forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the prediction intervals</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.forecast_multivariate">
<code class="sig-name descname">forecast_multivariate</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/cmvfts.html#ClusteredMVFTS.forecast_multivariate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.forecast_multivariate" title="Permalink to this definition"></a></dt>
<dd><p>Multivariate forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> Pandas dataframe with one column for each variable and with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a Pandas Dataframe object representing the forecasted values for each variable</p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.fts_method">
<code class="sig-name descname">fts_method</code><a class="headerlink" href="#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.fts_method" title="Permalink to this definition"></a></dt>
<dd><p>The FTS method to be called when a new model is build</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.fts_params">
<code class="sig-name descname">fts_params</code><a class="headerlink" href="#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.fts_params" title="Permalink to this definition"></a></dt>
<dd><p>The FTS method specific parameters</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.fuzzyfy">
<code class="sig-name descname">fuzzyfy</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/cmvfts.html#ClusteredMVFTS.fuzzyfy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.fuzzyfy" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py attribute">
<dt id="pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.model">
<code class="sig-name descname">model</code><a class="headerlink" href="#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.model" title="Permalink to this definition"></a></dt>
<dd><p>The most recent trained model</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.train">
<code class="sig-name descname">train</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/cmvfts.html#ClusteredMVFTS.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS.train" title="Permalink to this definition"></a></dt>
<dd><p>Method specific parameter fitting</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> training time series data</p></li>
<li><p><strong>kwargs</strong> Method specific parameters</p></li>
</ul>
</dd>
</dl>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="pyfts-models-multivariate-granular-module">
<h2>pyFTS.models.multivariate.granular module<a class="headerlink" href="#pyfts-models-multivariate-granular-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.models.multivariate.granular">
<span id="pyfts-models-multivariate-granular-module"></span><h2>pyFTS.models.multivariate.granular module<a class="headerlink" href="#module-pyFTS.models.multivariate.granular" title="Permalink to this headline"></a></h2>
<dl class="py class">
<dt id="pyFTS.models.multivariate.granular.GranularWMVFTS">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.multivariate.granular.</code><code class="sig-name descname">GranularWMVFTS</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/granular.html#GranularWMVFTS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.granular.GranularWMVFTS" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#pyFTS.models.multivariate.cmvfts.ClusteredMVFTS" title="pyFTS.models.multivariate.cmvfts.ClusteredMVFTS"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.models.multivariate.cmvfts.ClusteredMVFTS</span></code></a></p>
<p>Granular multivariate weighted high order FTS</p>
<dl class="py attribute">
<dt id="pyFTS.models.multivariate.granular.GranularWMVFTS.model">
<code class="sig-name descname">model</code><a class="headerlink" href="#pyFTS.models.multivariate.granular.GranularWMVFTS.model" title="Permalink to this definition"></a></dt>
<dd><p>The most recent trained model</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.multivariate.granular.GranularWMVFTS.train">
<code class="sig-name descname">train</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/granular.html#GranularWMVFTS.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.granular.GranularWMVFTS.train" title="Permalink to this definition"></a></dt>
<dd><p>Method specific parameter fitting</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> training time series data</p></li>
<li><p><strong>kwargs</strong> Method specific parameters</p></li>
</ul>
</dd>
</dl>
</dd></dl>
</dd></dl>
</div>
</div>
@ -392,14 +890,14 @@ multivariate fuzzy set base.</p>
<li><a class="reference internal" href="#submodules">Submodules</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.multivariate.FLR">pyFTS.models.multivariate.FLR module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.multivariate.common">pyFTS.models.multivariate.common module</a></li>
<li><a class="reference internal" href="#pyfts-models-multivariate-variable-module">pyFTS.models.multivariate.variable module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.multivariate.variable">pyFTS.models.multivariate.variable module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.multivariate.flrg">pyFTS.models.multivariate.flrg module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.multivariate.partitioner">pyFTS.models.multivariate.partitioner module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.multivariate.grid">pyFTS.models.multivariate.grid module</a></li>
<li><a class="reference internal" href="#pyfts-models-multivariate-mvfts-module">pyFTS.models.multivariate.mvfts module</a></li>
<li><a class="reference internal" href="#pyfts-models-multivariate-wmvfts-module">pyFTS.models.multivariate.wmvfts module</a></li>
<li><a class="reference internal" href="#pyfts-models-multivariate-cmvfts-module">pyFTS.models.multivariate.cmvfts module</a></li>
<li><a class="reference internal" href="#pyfts-models-multivariate-granular-module">pyFTS.models.multivariate.granular module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.multivariate.mvfts">pyFTS.models.multivariate.mvfts module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.multivariate.wmvfts">pyFTS.models.multivariate.wmvfts module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.multivariate.cmvfts">pyFTS.models.multivariate.cmvfts module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.multivariate.granular">pyFTS.models.multivariate.granular module</a></li>
</ul>
</li>
</ul>

View File

@ -203,8 +203,94 @@ IEEE Transactions on Fuzzy Systems, v. 16, n. 4, p. 1072-1086, 2008.</p>
<dd></dd></dl>
</div>
<div class="section" id="pyfts-models-nonstationary-cvfts-module">
<h2>pyFTS.models.nonstationary.cvfts module<a class="headerlink" href="#pyfts-models-nonstationary-cvfts-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.models.nonstationary.cvfts">
<span id="pyfts-models-nonstationary-cvfts-module"></span><h2>pyFTS.models.nonstationary.cvfts module<a class="headerlink" href="#module-pyFTS.models.nonstationary.cvfts" title="Permalink to this headline"></a></h2>
<dl class="py class">
<dt id="pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.nonstationary.cvfts.</code><code class="sig-name descname">ConditionalVarianceFTS</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/cvfts.html#ConditionalVarianceFTS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="pyFTS.models.html#pyFTS.models.hofts.HighOrderFTS" title="pyFTS.models.hofts.HighOrderFTS"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.models.hofts.HighOrderFTS</span></code></a></p>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS.forecast">
<code class="sig-name descname">forecast</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ndata</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/cvfts.html#ConditionalVarianceFTS.forecast"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS.forecast" title="Permalink to this definition"></a></dt>
<dd><p>Point forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS.forecast_interval">
<code class="sig-name descname">forecast_interval</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ndata</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/cvfts.html#ConditionalVarianceFTS.forecast_interval"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS.forecast_interval" title="Permalink to this definition"></a></dt>
<dd><p>Interval forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the prediction intervals</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS.generate_flrg">
<code class="sig-name descname">generate_flrg</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">flrs</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/cvfts.html#ConditionalVarianceFTS.generate_flrg"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS.generate_flrg" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS.perturbation_factors">
<code class="sig-name descname">perturbation_factors</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/cvfts.html#ConditionalVarianceFTS.perturbation_factors"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS.perturbation_factors" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS.perturbation_factors__old">
<code class="sig-name descname">perturbation_factors__old</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/cvfts.html#ConditionalVarianceFTS.perturbation_factors__old"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS.perturbation_factors__old" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS.train">
<code class="sig-name descname">train</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ndata</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/cvfts.html#ConditionalVarianceFTS.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.cvfts.ConditionalVarianceFTS.train" title="Permalink to this definition"></a></dt>
<dd><p>Method specific parameter fitting</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> training time series data</p></li>
<li><p><strong>kwargs</strong> Method specific parameters</p></li>
</ul>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt id="pyFTS.models.nonstationary.cvfts.HighOrderNonstationaryFLRG">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.nonstationary.cvfts.</code><code class="sig-name descname">HighOrderNonstationaryFLRG</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">order</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/cvfts.html#HighOrderNonstationaryFLRG"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.cvfts.HighOrderNonstationaryFLRG" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="pyFTS.models.html#pyFTS.models.hofts.HighOrderFTS" title="pyFTS.models.hofts.HighOrderFTS"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.models.hofts.HighOrderFTS</span></code></a></p>
<p>Conventional High Order Fuzzy Logical Relationship Group</p>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.cvfts.HighOrderNonstationaryFLRG.append_lhs">
<code class="sig-name descname">append_lhs</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">c</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/cvfts.html#HighOrderNonstationaryFLRG.append_lhs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.cvfts.HighOrderNonstationaryFLRG.append_lhs" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.cvfts.HighOrderNonstationaryFLRG.append_rhs">
<code class="sig-name descname">append_rhs</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">c</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/cvfts.html#HighOrderNonstationaryFLRG.append_rhs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.cvfts.HighOrderNonstationaryFLRG.append_rhs" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
</div>
<div class="section" id="module-pyFTS.models.nonstationary.flrg">
<span id="pyfts-models-nonstationary-flrg-module"></span><h2>pyFTS.models.nonstationary.flrg module<a class="headerlink" href="#module-pyFTS.models.nonstationary.flrg" title="Permalink to this headline"></a></h2>
@ -285,11 +371,269 @@ IEEE Transactions on Fuzzy Systems, v. 16, n. 4, p. 1072-1086, 2008.</p>
</dd></dl>
</div>
<div class="section" id="pyfts-models-nonstationary-honsfts-module">
<h2>pyFTS.models.nonstationary.honsfts module<a class="headerlink" href="#pyfts-models-nonstationary-honsfts-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.models.nonstationary.honsfts">
<span id="pyfts-models-nonstationary-honsfts-module"></span><h2>pyFTS.models.nonstationary.honsfts module<a class="headerlink" href="#module-pyFTS.models.nonstationary.honsfts" title="Permalink to this headline"></a></h2>
<dl class="py class">
<dt id="pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.nonstationary.honsfts.</code><code class="sig-name descname">HighOrderNonStationaryFLRG</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">order</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/honsfts.html#HighOrderNonStationaryFLRG"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#pyFTS.models.nonstationary.flrg.NonStationaryFLRG" title="pyFTS.models.nonstationary.flrg.NonStationaryFLRG"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.models.nonstationary.flrg.NonStationaryFLRG</span></code></a></p>
<p>First Order NonStationary Fuzzy Logical Relationship Group</p>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG.append_lhs">
<code class="sig-name descname">append_lhs</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">c</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/honsfts.html#HighOrderNonStationaryFLRG.append_lhs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG.append_lhs" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG.append_rhs">
<code class="sig-name descname">append_rhs</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">fset</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/honsfts.html#HighOrderNonStationaryFLRG.append_rhs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG.append_rhs" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG.get_lower">
<code class="sig-name descname">get_lower</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">sets</span></em>, <em class="sig-param"><span class="n">perturb</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/honsfts.html#HighOrderNonStationaryFLRG.get_lower"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG.get_lower" title="Permalink to this definition"></a></dt>
<dd><p>Returns the lower bound value for the RHS fuzzy sets</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>sets</strong> fuzzy sets</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>lower bound value</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG.get_midpoint">
<code class="sig-name descname">get_midpoint</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">sets</span></em>, <em class="sig-param"><span class="n">perturb</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/honsfts.html#HighOrderNonStationaryFLRG.get_midpoint"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG.get_midpoint" title="Permalink to this definition"></a></dt>
<dd><p>Returns the midpoint value for the RHS fuzzy sets</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>sets</strong> fuzzy sets</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>the midpoint value</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG.get_upper">
<code class="sig-name descname">get_upper</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">sets</span></em>, <em class="sig-param"><span class="n">perturb</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/honsfts.html#HighOrderNonStationaryFLRG.get_upper"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG.get_upper" title="Permalink to this definition"></a></dt>
<dd><p>Returns the upper bound value for the RHS fuzzy sets</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>sets</strong> fuzzy sets</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>upper bound value</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG.weights">
<code class="sig-name descname">weights</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/honsfts.html#HighOrderNonStationaryFLRG.weights"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFLRG.weights" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
<dl class="py class">
<dt id="pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFTS">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.nonstationary.honsfts.</code><code class="sig-name descname">HighOrderNonStationaryFTS</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/honsfts.html#HighOrderNonStationaryFTS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFTS" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#pyFTS.models.nonstationary.nsfts.NonStationaryFTS" title="pyFTS.models.nonstationary.nsfts.NonStationaryFTS"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.models.nonstationary.nsfts.NonStationaryFTS</span></code></a></p>
<p>NonStationaryFTS Fuzzy Time Series</p>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFTS.configure_lags">
<code class="sig-name descname">configure_lags</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/honsfts.html#HighOrderNonStationaryFTS.configure_lags"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFTS.configure_lags" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFTS.forecast">
<code class="sig-name descname">forecast</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ndata</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/honsfts.html#HighOrderNonStationaryFTS.forecast"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFTS.forecast" title="Permalink to this definition"></a></dt>
<dd><p>Point forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFTS.generate_flrg">
<code class="sig-name descname">generate_flrg</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/honsfts.html#HighOrderNonStationaryFTS.generate_flrg"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFTS.generate_flrg" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFTS.train">
<code class="sig-name descname">train</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/honsfts.html#HighOrderNonStationaryFTS.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.honsfts.HighOrderNonStationaryFTS.train" title="Permalink to this definition"></a></dt>
<dd><p>Method specific parameter fitting</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> training time series data</p></li>
<li><p><strong>kwargs</strong> Method specific parameters</p></li>
</ul>
</dd>
</dl>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="pyfts-models-nonstationary-nsfts-module">
<h2>pyFTS.models.nonstationary.nsfts module<a class="headerlink" href="#pyfts-models-nonstationary-nsfts-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.models.nonstationary.nsfts">
<span id="pyfts-models-nonstationary-nsfts-module"></span><h2>pyFTS.models.nonstationary.nsfts module<a class="headerlink" href="#module-pyFTS.models.nonstationary.nsfts" title="Permalink to this headline"></a></h2>
<dl class="py class">
<dt id="pyFTS.models.nonstationary.nsfts.ConventionalNonStationaryFLRG">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.nonstationary.nsfts.</code><code class="sig-name descname">ConventionalNonStationaryFLRG</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">LHS</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/nsfts.html#ConventionalNonStationaryFLRG"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.nsfts.ConventionalNonStationaryFLRG" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#pyFTS.models.nonstationary.flrg.NonStationaryFLRG" title="pyFTS.models.nonstationary.flrg.NonStationaryFLRG"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.models.nonstationary.flrg.NonStationaryFLRG</span></code></a></p>
<p>First Order NonStationary Fuzzy Logical Relationship Group</p>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.nsfts.ConventionalNonStationaryFLRG.append_rhs">
<code class="sig-name descname">append_rhs</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">c</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/nsfts.html#ConventionalNonStationaryFLRG.append_rhs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.nsfts.ConventionalNonStationaryFLRG.append_rhs" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.nsfts.ConventionalNonStationaryFLRG.get_key">
<code class="sig-name descname">get_key</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/nsfts.html#ConventionalNonStationaryFLRG.get_key"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.nsfts.ConventionalNonStationaryFLRG.get_key" title="Permalink to this definition"></a></dt>
<dd><p>Returns a unique identifier for this FLRG</p>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt id="pyFTS.models.nonstationary.nsfts.NonStationaryFTS">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.nonstationary.nsfts.</code><code class="sig-name descname">NonStationaryFTS</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/nsfts.html#NonStationaryFTS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.nsfts.NonStationaryFTS" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="pyFTS.common.html#pyFTS.common.fts.FTS" title="pyFTS.common.fts.FTS"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.common.fts.FTS</span></code></a></p>
<p>NonStationaryFTS Fuzzy Time Series</p>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.nsfts.NonStationaryFTS.conditional_perturbation_factors">
<code class="sig-name descname">conditional_perturbation_factors</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/nsfts.html#NonStationaryFTS.conditional_perturbation_factors"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.nsfts.NonStationaryFTS.conditional_perturbation_factors" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.nsfts.NonStationaryFTS.forecast">
<code class="sig-name descname">forecast</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ndata</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/nsfts.html#NonStationaryFTS.forecast"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.nsfts.NonStationaryFTS.forecast" title="Permalink to this definition"></a></dt>
<dd><p>Point forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.nsfts.NonStationaryFTS.forecast_interval">
<code class="sig-name descname">forecast_interval</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ndata</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/nsfts.html#NonStationaryFTS.forecast_interval"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.nsfts.NonStationaryFTS.forecast_interval" title="Permalink to this definition"></a></dt>
<dd><p>Interval forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the prediction intervals</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.nsfts.NonStationaryFTS.generate_flrg">
<code class="sig-name descname">generate_flrg</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">flrs</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/nsfts.html#NonStationaryFTS.generate_flrg"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.nsfts.NonStationaryFTS.generate_flrg" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.nsfts.NonStationaryFTS.train">
<code class="sig-name descname">train</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/nsfts.html#NonStationaryFTS.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.nsfts.NonStationaryFTS.train" title="Permalink to this definition"></a></dt>
<dd><p>Method specific parameter fitting</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> training time series data</p></li>
<li><p><strong>kwargs</strong> Method specific parameters</p></li>
</ul>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt id="pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFLRG">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.nonstationary.nsfts.</code><code class="sig-name descname">WeightedNonStationaryFLRG</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">LHS</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/nsfts.html#WeightedNonStationaryFLRG"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFLRG" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#pyFTS.models.nonstationary.flrg.NonStationaryFLRG" title="pyFTS.models.nonstationary.flrg.NonStationaryFLRG"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.models.nonstationary.flrg.NonStationaryFLRG</span></code></a></p>
<p>First Order NonStationary Fuzzy Logical Relationship Group</p>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFLRG.append_rhs">
<code class="sig-name descname">append_rhs</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">c</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/nsfts.html#WeightedNonStationaryFLRG.append_rhs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFLRG.append_rhs" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFLRG.get_key">
<code class="sig-name descname">get_key</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/nsfts.html#WeightedNonStationaryFLRG.get_key"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFLRG.get_key" title="Permalink to this definition"></a></dt>
<dd><p>Returns a unique identifier for this FLRG</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFLRG.get_midpoint">
<code class="sig-name descname">get_midpoint</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">sets</span></em>, <em class="sig-param"><span class="n">perturb</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/nsfts.html#WeightedNonStationaryFLRG.get_midpoint"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFLRG.get_midpoint" title="Permalink to this definition"></a></dt>
<dd><p>Returns the midpoint value for the RHS fuzzy sets</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>sets</strong> fuzzy sets</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>the midpoint value</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFLRG.weights">
<code class="sig-name descname">weights</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/nsfts.html#WeightedNonStationaryFLRG.weights"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFLRG.weights" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
<dl class="py class">
<dt id="pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFTS">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.nonstationary.nsfts.</code><code class="sig-name descname">WeightedNonStationaryFTS</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/nsfts.html#WeightedNonStationaryFTS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFTS" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#pyFTS.models.nonstationary.nsfts.NonStationaryFTS" title="pyFTS.models.nonstationary.nsfts.NonStationaryFTS"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.models.nonstationary.nsfts.NonStationaryFTS</span></code></a></p>
<p>Weighted NonStationaryFTS Fuzzy Time Series</p>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFTS.generate_flrg">
<code class="sig-name descname">generate_flrg</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">flrs</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/nsfts.html#WeightedNonStationaryFTS.generate_flrg"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFTS.generate_flrg" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFTS.train">
<code class="sig-name descname">train</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/nsfts.html#WeightedNonStationaryFTS.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.nsfts.WeightedNonStationaryFTS.train" title="Permalink to this definition"></a></dt>
<dd><p>Method specific parameter fitting</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> training time series data</p></li>
<li><p><strong>kwargs</strong> Method specific parameters</p></li>
</ul>
</dd>
</dl>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="module-pyFTS.models.nonstationary.partitioners">
<span id="pyfts-models-nonstationary-partitioners-module"></span><h2>pyFTS.models.nonstationary.partitioners module<a class="headerlink" href="#module-pyFTS.models.nonstationary.partitioners" title="Permalink to this headline"></a></h2>
@ -385,8 +729,18 @@ IEEE Transactions on Fuzzy Systems, v. 16, n. 4, p. 1072-1086, 2008.</p>
<dd></dd></dl>
</div>
<div class="section" id="pyfts-models-nonstationary-util-module">
<h2>pyFTS.models.nonstationary.util module<a class="headerlink" href="#pyfts-models-nonstationary-util-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.models.nonstationary.util">
<span id="pyfts-models-nonstationary-util-module"></span><h2>pyFTS.models.nonstationary.util module<a class="headerlink" href="#module-pyFTS.models.nonstationary.util" title="Permalink to this headline"></a></h2>
<dl class="py function">
<dt id="pyFTS.models.nonstationary.util.plot_sets">
<code class="sig-prename descclassname">pyFTS.models.nonstationary.util.</code><code class="sig-name descname">plot_sets</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">partitioner</span></em>, <em class="sig-param"><span class="n">start</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">end</span><span class="o">=</span><span class="default_value">10</span></em>, <em class="sig-param"><span class="n">step</span><span class="o">=</span><span class="default_value">1</span></em>, <em class="sig-param"><span class="n">tam</span><span class="o">=</span><span class="default_value">[5, 5]</span></em>, <em class="sig-param"><span class="n">colors</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">save</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">file</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">axes</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">data</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">window_size</span><span class="o">=</span><span class="default_value">1</span></em>, <em class="sig-param"><span class="n">only_lines</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">legend</span><span class="o">=</span><span class="default_value">True</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/util.html#plot_sets"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.util.plot_sets" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="pyFTS.models.nonstationary.util.plot_sets_conditional">
<code class="sig-prename descclassname">pyFTS.models.nonstationary.util.</code><code class="sig-name descname">plot_sets_conditional</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">model</span></em>, <em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">step</span><span class="o">=</span><span class="default_value">1</span></em>, <em class="sig-param"><span class="n">size</span><span class="o">=</span><span class="default_value">[5, 5]</span></em>, <em class="sig-param"><span class="n">colors</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">save</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">file</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">axes</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">fig</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/nonstationary/util.html#plot_sets_conditional"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.nonstationary.util.plot_sets_conditional" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</div>
<div class="section" id="module-pyFTS.models.nonstationary">
<span id="module-contents"></span><h2>Module contents<a class="headerlink" href="#module-pyFTS.models.nonstationary" title="Permalink to this headline"></a></h2>
@ -406,13 +760,13 @@ IEEE Transactions on Fuzzy Systems, v. 16, n. 4, p. 1072-1086, 2008.</p>
<li><a class="reference internal" href="#">pyFTS.models.nonstationary package</a><ul>
<li><a class="reference internal" href="#submodules">Submodules</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.nonstationary.common">pyFTS.models.nonstationary.common module</a></li>
<li><a class="reference internal" href="#pyfts-models-nonstationary-cvfts-module">pyFTS.models.nonstationary.cvfts module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.nonstationary.cvfts">pyFTS.models.nonstationary.cvfts module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.nonstationary.flrg">pyFTS.models.nonstationary.flrg module</a></li>
<li><a class="reference internal" href="#pyfts-models-nonstationary-honsfts-module">pyFTS.models.nonstationary.honsfts module</a></li>
<li><a class="reference internal" href="#pyfts-models-nonstationary-nsfts-module">pyFTS.models.nonstationary.nsfts module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.nonstationary.honsfts">pyFTS.models.nonstationary.honsfts module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.nonstationary.nsfts">pyFTS.models.nonstationary.nsfts module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.nonstationary.partitioners">pyFTS.models.nonstationary.partitioners module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.nonstationary.perturbation">pyFTS.models.nonstationary.perturbation module</a></li>
<li><a class="reference internal" href="#pyfts-models-nonstationary-util-module">pyFTS.models.nonstationary.util module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.nonstationary.util">pyFTS.models.nonstationary.util module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.nonstationary">Module contents</a></li>
</ul>
</li>

View File

@ -215,8 +215,86 @@
</dd></dl>
</div>
<div class="section" id="pyfts-models-seasonal-cmsfts-module">
<h2>pyFTS.models.seasonal.cmsfts module<a class="headerlink" href="#pyfts-models-seasonal-cmsfts-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.models.seasonal.cmsfts">
<span id="pyfts-models-seasonal-cmsfts-module"></span><h2>pyFTS.models.seasonal.cmsfts module<a class="headerlink" href="#module-pyFTS.models.seasonal.cmsfts" title="Permalink to this headline"></a></h2>
<dl class="py class">
<dt id="pyFTS.models.seasonal.cmsfts.ContextualMultiSeasonalFTS">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.seasonal.cmsfts.</code><code class="sig-name descname">ContextualMultiSeasonalFTS</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/cmsfts.html#ContextualMultiSeasonalFTS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.cmsfts.ContextualMultiSeasonalFTS" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#pyFTS.models.seasonal.sfts.SeasonalFTS" title="pyFTS.models.seasonal.sfts.SeasonalFTS"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.models.seasonal.sfts.SeasonalFTS</span></code></a></p>
<p>Contextual Multi-Seasonal Fuzzy Time Series</p>
<dl class="py method">
<dt id="pyFTS.models.seasonal.cmsfts.ContextualMultiSeasonalFTS.forecast">
<code class="sig-name descname">forecast</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/cmsfts.html#ContextualMultiSeasonalFTS.forecast"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.cmsfts.ContextualMultiSeasonalFTS.forecast" title="Permalink to this definition"></a></dt>
<dd><p>Point forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.seasonal.cmsfts.ContextualMultiSeasonalFTS.forecast_ahead">
<code class="sig-name descname">forecast_ahead</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">steps</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/cmsfts.html#ContextualMultiSeasonalFTS.forecast_ahead"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.cmsfts.ContextualMultiSeasonalFTS.forecast_ahead" title="Permalink to this definition"></a></dt>
<dd><p>Point forecast from 1 to H steps ahead, where H is given by the steps parameter</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>steps</strong> the number of steps ahead to forecast (default: 1)</p></li>
<li><p><strong>start_at</strong> in the multi step forecasting, the index of the data where to start forecasting (default: 0)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.seasonal.cmsfts.ContextualMultiSeasonalFTS.generate_flrg">
<code class="sig-name descname">generate_flrg</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">flrs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/cmsfts.html#ContextualMultiSeasonalFTS.generate_flrg"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.cmsfts.ContextualMultiSeasonalFTS.generate_flrg" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.seasonal.cmsfts.ContextualMultiSeasonalFTS.get_midpoints">
<code class="sig-name descname">get_midpoints</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">flrg</span></em>, <em class="sig-param"><span class="n">data</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/cmsfts.html#ContextualMultiSeasonalFTS.get_midpoints"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.cmsfts.ContextualMultiSeasonalFTS.get_midpoints" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.seasonal.cmsfts.ContextualMultiSeasonalFTS.train">
<code class="sig-name descname">train</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/cmsfts.html#ContextualMultiSeasonalFTS.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.cmsfts.ContextualMultiSeasonalFTS.train" title="Permalink to this definition"></a></dt>
<dd><p>Method specific parameter fitting</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> training time series data</p></li>
<li><p><strong>kwargs</strong> Method specific parameters</p></li>
</ul>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt id="pyFTS.models.seasonal.cmsfts.ContextualSeasonalFLRG">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.seasonal.cmsfts.</code><code class="sig-name descname">ContextualSeasonalFLRG</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">seasonality</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/cmsfts.html#ContextualSeasonalFLRG"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.cmsfts.ContextualSeasonalFLRG" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#pyFTS.models.seasonal.sfts.SeasonalFLRG" title="pyFTS.models.seasonal.sfts.SeasonalFLRG"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.models.seasonal.sfts.SeasonalFLRG</span></code></a></p>
<p>Contextual Seasonal Fuzzy Logical Relationship Group</p>
<dl class="py method">
<dt id="pyFTS.models.seasonal.cmsfts.ContextualSeasonalFLRG.append_rhs">
<code class="sig-name descname">append_rhs</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">flr</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/cmsfts.html#ContextualSeasonalFLRG.append_rhs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.cmsfts.ContextualSeasonalFLRG.append_rhs" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
</div>
<div class="section" id="module-pyFTS.models.seasonal.common">
<span id="pyfts-models-seasonal-common-module"></span><h2>pyFTS.models.seasonal.common module<a class="headerlink" href="#module-pyFTS.models.seasonal.common" title="Permalink to this headline"></a></h2>
@ -374,8 +452,69 @@
<dd></dd></dl>
</div>
<div class="section" id="pyfts-models-seasonal-msfts-module">
<h2>pyFTS.models.seasonal.msfts module<a class="headerlink" href="#pyfts-models-seasonal-msfts-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.models.seasonal.msfts">
<span id="pyfts-models-seasonal-msfts-module"></span><h2>pyFTS.models.seasonal.msfts module<a class="headerlink" href="#module-pyFTS.models.seasonal.msfts" title="Permalink to this headline"></a></h2>
<dl class="py class">
<dt id="pyFTS.models.seasonal.msfts.MultiSeasonalFTS">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.seasonal.msfts.</code><code class="sig-name descname">MultiSeasonalFTS</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">name</span></em>, <em class="sig-param"><span class="n">indexer</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/msfts.html#MultiSeasonalFTS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.msfts.MultiSeasonalFTS" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#pyFTS.models.seasonal.sfts.SeasonalFTS" title="pyFTS.models.seasonal.sfts.SeasonalFTS"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.models.seasonal.sfts.SeasonalFTS</span></code></a></p>
<p>Multi-Seasonal Fuzzy Time Series</p>
<dl class="py method">
<dt id="pyFTS.models.seasonal.msfts.MultiSeasonalFTS.forecast">
<code class="sig-name descname">forecast</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/msfts.html#MultiSeasonalFTS.forecast"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.msfts.MultiSeasonalFTS.forecast" title="Permalink to this definition"></a></dt>
<dd><p>Point forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.seasonal.msfts.MultiSeasonalFTS.forecast_ahead">
<code class="sig-name descname">forecast_ahead</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">steps</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/msfts.html#MultiSeasonalFTS.forecast_ahead"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.msfts.MultiSeasonalFTS.forecast_ahead" title="Permalink to this definition"></a></dt>
<dd><p>Point forecast from 1 to H steps ahead, where H is given by the steps parameter</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>steps</strong> the number of steps ahead to forecast (default: 1)</p></li>
<li><p><strong>start_at</strong> in the multi step forecasting, the index of the data where to start forecasting (default: 0)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.seasonal.msfts.MultiSeasonalFTS.generate_flrg">
<code class="sig-name descname">generate_flrg</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">flrs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/msfts.html#MultiSeasonalFTS.generate_flrg"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.msfts.MultiSeasonalFTS.generate_flrg" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.seasonal.msfts.MultiSeasonalFTS.train">
<code class="sig-name descname">train</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/msfts.html#MultiSeasonalFTS.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.msfts.MultiSeasonalFTS.train" title="Permalink to this definition"></a></dt>
<dd><p>Method specific parameter fitting</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> training time series data</p></li>
<li><p><strong>kwargs</strong> Method specific parameters</p></li>
</ul>
</dd>
</dl>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="module-pyFTS.models.seasonal.partitioner">
<span id="pyfts-models-seasonal-partitioner-module"></span><h2>pyFTS.models.seasonal.partitioner module<a class="headerlink" href="#module-pyFTS.models.seasonal.partitioner" title="Permalink to this headline"></a></h2>
@ -451,8 +590,79 @@ overlapped fuzzy sets.</p>
</dd></dl>
</div>
<div class="section" id="pyfts-models-seasonal-sfts-module">
<h2>pyFTS.models.seasonal.sfts module<a class="headerlink" href="#pyfts-models-seasonal-sfts-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.models.seasonal.sfts">
<span id="pyfts-models-seasonal-sfts-module"></span><h2>pyFTS.models.seasonal.sfts module<a class="headerlink" href="#module-pyFTS.models.seasonal.sfts" title="Permalink to this headline"></a></h2>
<p>Simple First Order Seasonal Fuzzy Time Series implementation of Song (1999) based of Conventional FTS by Chen (1996)</p>
<ol class="upperalpha simple" start="17">
<li><p>Song, “Seasonal forecasting in fuzzy time series,” Fuzzy sets Syst., vol. 107, pp. 235236, 1999.</p></li>
</ol>
<p>S.-M. Chen, “Forecasting enrollments based on fuzzy time series,” Fuzzy Sets Syst., vol. 81, no. 3, pp. 311319, 1996.</p>
<dl class="py class">
<dt id="pyFTS.models.seasonal.sfts.SeasonalFLRG">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.seasonal.sfts.</code><code class="sig-name descname">SeasonalFLRG</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">seasonality</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/sfts.html#SeasonalFLRG"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.sfts.SeasonalFLRG" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="pyFTS.common.html#pyFTS.common.flrg.FLRG" title="pyFTS.common.flrg.FLRG"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.common.flrg.FLRG</span></code></a></p>
<p>First Order Seasonal Fuzzy Logical Relationship Group</p>
<dl class="py method">
<dt id="pyFTS.models.seasonal.sfts.SeasonalFLRG.append_rhs">
<code class="sig-name descname">append_rhs</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">c</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/sfts.html#SeasonalFLRG.append_rhs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.sfts.SeasonalFLRG.append_rhs" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.seasonal.sfts.SeasonalFLRG.get_key">
<code class="sig-name descname">get_key</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/sfts.html#SeasonalFLRG.get_key"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.sfts.SeasonalFLRG.get_key" title="Permalink to this definition"></a></dt>
<dd><p>Returns a unique identifier for this FLRG</p>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt id="pyFTS.models.seasonal.sfts.SeasonalFTS">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.models.seasonal.sfts.</code><code class="sig-name descname">SeasonalFTS</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/sfts.html#SeasonalFTS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.sfts.SeasonalFTS" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="pyFTS.common.html#pyFTS.common.fts.FTS" title="pyFTS.common.fts.FTS"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.common.fts.FTS</span></code></a></p>
<p>First Order Seasonal Fuzzy Time Series</p>
<dl class="py method">
<dt id="pyFTS.models.seasonal.sfts.SeasonalFTS.forecast">
<code class="sig-name descname">forecast</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/sfts.html#SeasonalFTS.forecast"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.sfts.SeasonalFTS.forecast" title="Permalink to this definition"></a></dt>
<dd><p>Point forecast one step ahead</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> time series data with the minimal length equal to the max_lag of the model</p></li>
<li><p><strong>kwargs</strong> model specific parameters</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a list with the forecasted values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.models.seasonal.sfts.SeasonalFTS.generate_flrg">
<code class="sig-name descname">generate_flrg</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">flrs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/sfts.html#SeasonalFTS.generate_flrg"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.sfts.SeasonalFTS.generate_flrg" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.seasonal.sfts.SeasonalFTS.get_midpoints">
<code class="sig-name descname">get_midpoints</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">flrg</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/sfts.html#SeasonalFTS.get_midpoints"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.sfts.SeasonalFTS.get_midpoints" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.models.seasonal.sfts.SeasonalFTS.train">
<code class="sig-name descname">train</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/seasonal/sfts.html#SeasonalFTS.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.seasonal.sfts.SeasonalFTS.train" title="Permalink to this definition"></a></dt>
<dd><p>Method specific parameter fitting</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> training time series data</p></li>
<li><p><strong>kwargs</strong> Method specific parameters</p></li>
</ul>
</dd>
</dl>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="module-pyFTS.models.seasonal">
<span id="module-contents"></span><h2>Module contents<a class="headerlink" href="#module-pyFTS.models.seasonal" title="Permalink to this headline"></a></h2>
@ -471,11 +681,11 @@ overlapped fuzzy sets.</p>
<li><a class="reference internal" href="#">pyFTS.models.seasonal package</a><ul>
<li><a class="reference internal" href="#submodules">Submodules</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.seasonal.SeasonalIndexer">pyFTS.models.seasonal.SeasonalIndexer module</a></li>
<li><a class="reference internal" href="#pyfts-models-seasonal-cmsfts-module">pyFTS.models.seasonal.cmsfts module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.seasonal.cmsfts">pyFTS.models.seasonal.cmsfts module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.seasonal.common">pyFTS.models.seasonal.common module</a></li>
<li><a class="reference internal" href="#pyfts-models-seasonal-msfts-module">pyFTS.models.seasonal.msfts module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.seasonal.msfts">pyFTS.models.seasonal.msfts module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.seasonal.partitioner">pyFTS.models.seasonal.partitioner module</a></li>
<li><a class="reference internal" href="#pyfts-models-seasonal-sfts-module">pyFTS.models.seasonal.sfts module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.seasonal.sfts">pyFTS.models.seasonal.sfts module</a></li>
<li><a class="reference internal" href="#module-pyFTS.models.seasonal">Module contents</a></li>
</ul>
</li>

View File

@ -465,8 +465,31 @@ Comput. Math. Appl., vol. 56, no. 12, pp. 30523063, Dec. 2008. DOI: 10.1016/j
</dd></dl>
</div>
<div class="section" id="pyfts-partitioners-huarng-module">
<h2>pyFTS.partitioners.Huarng module<a class="headerlink" href="#pyfts-partitioners-huarng-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.partitioners.Huarng">
<span id="pyfts-partitioners-huarng-module"></span><h2>pyFTS.partitioners.Huarng module<a class="headerlink" href="#module-pyFTS.partitioners.Huarng" title="Permalink to this headline"></a></h2>
<p>K. H. Huarng, “Effective lengths of intervals to improve forecasting in fuzzy time series,”
Fuzzy Sets Syst., vol. 123, no. 3, pp. 387394, Nov. 2001.</p>
<dl class="py class">
<dt id="pyFTS.partitioners.Huarng.HuarngPartitioner">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.partitioners.Huarng.</code><code class="sig-name descname">HuarngPartitioner</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/Huarng.html#HuarngPartitioner"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.partitioners.Huarng.HuarngPartitioner" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#pyFTS.partitioners.partitioner.Partitioner" title="pyFTS.partitioners.partitioner.Partitioner"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.partitioners.partitioner.Partitioner</span></code></a></p>
<p>Huarng Empirical Partitioner</p>
<dl class="py method">
<dt id="pyFTS.partitioners.Huarng.HuarngPartitioner.build">
<code class="sig-name descname">build</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/Huarng.html#HuarngPartitioner.build"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.partitioners.Huarng.HuarngPartitioner.build" title="Permalink to this definition"></a></dt>
<dd><p>Perform the partitioning of the Universe of Discourse</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>data</strong> training data</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="module-pyFTS.partitioners.Singleton">
<span id="pyfts-partitioners-singleton-module"></span><h2>pyFTS.partitioners.Singleton module<a class="headerlink" href="#module-pyFTS.partitioners.Singleton" title="Permalink to this headline"></a></h2>
@ -560,11 +583,42 @@ Comput. Math. Appl., vol. 56, no. 12, pp. 30523063, Dec. 2008. DOI: 10.1016/j
<dd></dd></dl>
</div>
<div class="section" id="pyfts-partitioners-util-module">
<h2>pyFTS.partitioners.Util module<a class="headerlink" href="#pyfts-partitioners-util-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.partitioners.Util">
<span id="pyfts-partitioners-util-module"></span><h2>pyFTS.partitioners.Util module<a class="headerlink" href="#module-pyFTS.partitioners.Util" title="Permalink to this headline"></a></h2>
<p>Facility methods for pyFTS partitioners module</p>
<dl class="py function">
<dt id="pyFTS.partitioners.Util.explore_partitioners">
<code class="sig-prename descclassname">pyFTS.partitioners.Util.</code><code class="sig-name descname">explore_partitioners</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">npart</span></em>, <em class="sig-param"><span class="n">methods</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">mf</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">transformation</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">size</span><span class="o">=</span><span class="default_value">[12, 10]</span></em>, <em class="sig-param"><span class="n">save</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">file</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/Util.html#explore_partitioners"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.partitioners.Util.explore_partitioners" title="Permalink to this definition"></a></dt>
<dd><p>Create partitioners for the mf membership functions and npart partitions and show the partitioning images.
:data: Time series data
:npart: Maximum number of partitions of the universe of discourse
:methods: A list with the partitioning methods to be used
:mf: A list with the membership functions to be used
:transformation: a transformation to be used in partitioner
:size: list, the size of the output image [width, height]
:save: boolean, if the image will be saved on disk
:file: string, the file path to save the image
:return: the list of the built partitioners</p>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.partitioners.Util.plot_partitioners">
<code class="sig-prename descclassname">pyFTS.partitioners.Util.</code><code class="sig-name descname">plot_partitioners</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">objs</span></em>, <em class="sig-param"><span class="n">tam</span><span class="o">=</span><span class="default_value">[12, 10]</span></em>, <em class="sig-param"><span class="n">save</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">file</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">axis</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/Util.html#plot_partitioners"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.partitioners.Util.plot_partitioners" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="pyFTS.partitioners.Util.plot_sets">
<code class="sig-prename descclassname">pyFTS.partitioners.Util.</code><code class="sig-name descname">plot_sets</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">sets</span></em>, <em class="sig-param"><span class="n">titles</span></em>, <em class="sig-param"><span class="n">size</span><span class="o">=</span><span class="default_value">[12, 10]</span></em>, <em class="sig-param"><span class="n">save</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">file</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">axis</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/Util.html#plot_sets"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.partitioners.Util.plot_sets" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</div>
<div class="section" id="pyfts-partitioners-parallel-util-module">
<h2>pyFTS.partitioners.parallel_util module<a class="headerlink" href="#pyfts-partitioners-parallel-util-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.partitioners.parallel_util">
<span id="pyfts-partitioners-parallel-util-module"></span><h2>pyFTS.partitioners.parallel_util module<a class="headerlink" href="#module-pyFTS.partitioners.parallel_util" title="Permalink to this headline"></a></h2>
<dl class="py function">
<dt id="pyFTS.partitioners.parallel_util.explore_partitioners">
<code class="sig-prename descclassname">pyFTS.partitioners.parallel_util.</code><code class="sig-name descname">explore_partitioners</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">npart</span></em>, <em class="sig-param"><span class="n">methods</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">mf</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">tam</span><span class="o">=</span><span class="default_value">[12, 10]</span></em>, <em class="sig-param"><span class="n">save</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">file</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/parallel_util.html#explore_partitioners"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.partitioners.parallel_util.explore_partitioners" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</div>
</div>
@ -585,12 +639,12 @@ Comput. Math. Appl., vol. 56, no. 12, pp. 30523063, Dec. 2008. DOI: 10.1016/j
<li><a class="reference internal" href="#module-pyFTS.partitioners.Entropy">pyFTS.partitioners.Entropy module</a></li>
<li><a class="reference internal" href="#module-pyFTS.partitioners.FCM">pyFTS.partitioners.FCM module</a></li>
<li><a class="reference internal" href="#module-pyFTS.partitioners.Grid">pyFTS.partitioners.Grid module</a></li>
<li><a class="reference internal" href="#pyfts-partitioners-huarng-module">pyFTS.partitioners.Huarng module</a></li>
<li><a class="reference internal" href="#module-pyFTS.partitioners.Huarng">pyFTS.partitioners.Huarng module</a></li>
<li><a class="reference internal" href="#module-pyFTS.partitioners.Singleton">pyFTS.partitioners.Singleton module</a></li>
<li><a class="reference internal" href="#module-pyFTS.partitioners.Simple">pyFTS.partitioners.Simple module</a></li>
<li><a class="reference internal" href="#module-pyFTS.partitioners.SubClust">pyFTS.partitioners.SubClust module</a></li>
<li><a class="reference internal" href="#pyfts-partitioners-util-module">pyFTS.partitioners.Util module</a></li>
<li><a class="reference internal" href="#pyfts-partitioners-parallel-util-module">pyFTS.partitioners.parallel_util module</a></li>
<li><a class="reference internal" href="#module-pyFTS.partitioners.Util">pyFTS.partitioners.Util module</a></li>
<li><a class="reference internal" href="#module-pyFTS.partitioners.parallel_util">pyFTS.partitioners.parallel_util module</a></li>
</ul>
</li>
</ul>

View File

@ -68,11 +68,304 @@
<div class="section" id="submodules">
<h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this headline"></a></h2>
</div>
<div class="section" id="pyfts-probabilistic-probabilitydistribution-module">
<h2>pyFTS.probabilistic.ProbabilityDistribution module<a class="headerlink" href="#pyfts-probabilistic-probabilitydistribution-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.probabilistic.ProbabilityDistribution">
<span id="pyfts-probabilistic-probabilitydistribution-module"></span><h2>pyFTS.probabilistic.ProbabilityDistribution module<a class="headerlink" href="#module-pyFTS.probabilistic.ProbabilityDistribution" title="Permalink to this headline"></a></h2>
<dl class="py class">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.probabilistic.ProbabilityDistribution.</code><code class="sig-name descname">ProbabilityDistribution</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">type</span><span class="o">=</span><span class="default_value">'KDE'</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a></p>
<p>Represents a discrete or continous probability distribution
If type is histogram, the PDF is discrete
If type is KDE the PDF is continuous</p>
<dl class="py method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.append">
<code class="sig-name descname">append</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">values</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.append"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.append" title="Permalink to this definition"></a></dt>
<dd><p>Increment the frequency count for the values</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>values</strong> A list of values to account the frequency</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.append_interval">
<code class="sig-name descname">append_interval</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">intervals</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.append_interval"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.append_interval" title="Permalink to this definition"></a></dt>
<dd><p>Increment the frequency count for all values inside an interval</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>intervals</strong> A list of intervals do increment the frequency</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.averageloglikelihood">
<code class="sig-name descname">averageloglikelihood</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.averageloglikelihood"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.averageloglikelihood" title="Permalink to this definition"></a></dt>
<dd><p>Average log likelihood of the probability distribution with respect to data</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>data</strong> </p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.bins">
<code class="sig-name descname">bins</code><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.bins" title="Permalink to this definition"></a></dt>
<dd><p>Number of bins on a discrete PDF</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.build_cdf_qtl">
<code class="sig-name descname">build_cdf_qtl</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.build_cdf_qtl"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.build_cdf_qtl" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.crossentropy">
<code class="sig-name descname">crossentropy</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">q</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.crossentropy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.crossentropy" title="Permalink to this definition"></a></dt>
<dd><p>Cross entropy between the actual probability distribution and the informed one,
H(P,Q) = - ∑ P(x) log ( Q(x) )</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>q</strong> a probabilistic.ProbabilityDistribution object</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Cross entropy between this probability distribution and the given distribution</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.cumulative">
<code class="sig-name descname">cumulative</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">values</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.cumulative"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.cumulative" title="Permalink to this definition"></a></dt>
<dd><p>Return the cumulative probability densities for the input values,
such that F(x) = P(X &lt;= x)</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>values</strong> A list of input values</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>The cumulative probability densities for the input values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.density">
<code class="sig-name descname">density</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">values</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.density"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.density" title="Permalink to this definition"></a></dt>
<dd><p>Return the probability densities for the input values</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>values</strong> List of values to return the densities</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>List of probability densities for the input values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.differential_offset">
<code class="sig-name descname">differential_offset</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">value</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.differential_offset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.differential_offset" title="Permalink to this definition"></a></dt>
<dd><p>Auxiliary function for probability distributions of differentiated data</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>value</strong> </p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.empiricalloglikelihood">
<code class="sig-name descname">empiricalloglikelihood</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.empiricalloglikelihood"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.empiricalloglikelihood" title="Permalink to this definition"></a></dt>
<dd><p>Empirical Log Likelihood of the probability distribution, L(P) = ∑ log( P(x) )</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.entropy">
<code class="sig-name descname">entropy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.entropy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.entropy" title="Permalink to this definition"></a></dt>
<dd><p>Return the entropy of the probability distribution, H(P) = E[ -ln P(X) ] = - ∑ P(x) log ( P(x) )</p>
<p>:return:the entropy of the probability distribution</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.expected_value">
<code class="sig-name descname">expected_value</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.expected_value"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.expected_value" title="Permalink to this definition"></a></dt>
<dd><p>Return the expected value of the distribution, as E[X] = ∑ x * P(x)</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>The expected value of the distribution</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.kullbackleiblerdivergence">
<code class="sig-name descname">kullbackleiblerdivergence</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">q</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.kullbackleiblerdivergence"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.kullbackleiblerdivergence" title="Permalink to this definition"></a></dt>
<dd><p>Kullback-Leibler divergence between the actual probability distribution and the informed one.
DKL(P || Q) = - ∑ P(x) log( P(X) / Q(x) )</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>q</strong> a probabilistic.ProbabilityDistribution object</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Kullback-Leibler divergence</p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.labels">
<code class="sig-name descname">labels</code><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.labels" title="Permalink to this definition"></a></dt>
<dd><p>Bins labels on a discrete PDF</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.plot">
<code class="sig-name descname">plot</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">axis</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">color</span><span class="o">=</span><span class="default_value">'black'</span></em>, <em class="sig-param"><span class="n">tam</span><span class="o">=</span><span class="default_value">[10, 6]</span></em>, <em class="sig-param"><span class="n">title</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.plot"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.plot" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.pseudologlikelihood">
<code class="sig-name descname">pseudologlikelihood</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.pseudologlikelihood"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.pseudologlikelihood" title="Permalink to this definition"></a></dt>
<dd><p>Pseudo log likelihood of the probability distribution with respect to data</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>data</strong> </p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.quantile">
<code class="sig-name descname">quantile</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">values</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.quantile"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.quantile" title="Permalink to this definition"></a></dt>
<dd><p>Return the Universe of Discourse values in relation to the quantile input values,
such that Q(tau) = min( {x | F(x) &gt;= tau })</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>values</strong> input values</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>The list of the quantile values for the input values</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.set">
<code class="sig-name descname">set</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">value</span></em>, <em class="sig-param"><span class="n">density</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.set"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.set" title="Permalink to this definition"></a></dt>
<dd><p>Assert a probability density for a certain value value, such that P(value) = density</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>value</strong> A value in the universe of discourse from the distribution</p></li>
<li><p><strong>density</strong> The probability density to assign to the value</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.type">
<code class="sig-name descname">type</code><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.type" title="Permalink to this definition"></a></dt>
<dd><p>If type is histogram, the PDF is discrete
If type is KDE the PDF is continuous</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.uod">
<code class="sig-name descname">uod</code><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.uod" title="Permalink to this definition"></a></dt>
<dd><p>Universe of discourse</p>
</dd></dl>
</dd></dl>
<dl class="py function">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.from_point">
<code class="sig-prename descclassname">pyFTS.probabilistic.ProbabilityDistribution.</code><code class="sig-name descname">from_point</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#from_point"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.from_point" title="Permalink to this definition"></a></dt>
<dd><p>Create a probability distribution from a scalar value</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> scalar value</p></li>
<li><p><strong>kwargs</strong> common parameters of the distribution</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>the ProbabilityDistribution object</p>
</dd>
</dl>
</dd></dl>
</div>
<div class="section" id="pyfts-probabilistic-kde-module">
<h2>pyFTS.probabilistic.kde module<a class="headerlink" href="#pyfts-probabilistic-kde-module" title="Permalink to this headline"></a></h2>
<div class="section" id="module-pyFTS.probabilistic.kde">
<span id="pyfts-probabilistic-kde-module"></span><h2>pyFTS.probabilistic.kde module<a class="headerlink" href="#module-pyFTS.probabilistic.kde" title="Permalink to this headline"></a></h2>
<p>Kernel Density Estimation</p>
<dl class="py class">
<dt id="pyFTS.probabilistic.kde.KernelSmoothing">
<em class="property">class </em><code class="sig-prename descclassname">pyFTS.probabilistic.kde.</code><code class="sig-name descname">KernelSmoothing</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/kde.html#KernelSmoothing"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.kde.KernelSmoothing" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a></p>
<p>Kernel Density Estimation</p>
<dl class="py attribute">
<dt id="pyFTS.probabilistic.kde.KernelSmoothing.h">
<code class="sig-name descname">h</code><a class="headerlink" href="#pyFTS.probabilistic.kde.KernelSmoothing.h" title="Permalink to this definition"></a></dt>
<dd><p>Width parameter</p>
</dd></dl>
<dl class="py attribute">
<dt id="pyFTS.probabilistic.kde.KernelSmoothing.kernel">
<code class="sig-name descname">kernel</code><a class="headerlink" href="#pyFTS.probabilistic.kde.KernelSmoothing.kernel" title="Permalink to this definition"></a></dt>
<dd><p>Kernel function</p>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.probabilistic.kde.KernelSmoothing.kernel_function">
<code class="sig-name descname">kernel_function</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">u</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/kde.html#KernelSmoothing.kernel_function"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.kde.KernelSmoothing.kernel_function" title="Permalink to this definition"></a></dt>
<dd><p>Apply the kernel</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>u</strong> </p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pyFTS.probabilistic.kde.KernelSmoothing.probability">
<code class="sig-name descname">probability</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/kde.html#KernelSmoothing.probability"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.kde.KernelSmoothing.probability" title="Permalink to this definition"></a></dt>
<dd><p>Probability of the point x on data</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> </p></li>
<li><p><strong>data</strong> </p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
</dd></dl>
</div>
</div>
@ -88,8 +381,8 @@
<li><a class="reference internal" href="#">pyFTS.probabilistic package</a><ul>
<li><a class="reference internal" href="#module-pyFTS.probabilistic">Module contents</a></li>
<li><a class="reference internal" href="#submodules">Submodules</a></li>
<li><a class="reference internal" href="#pyfts-probabilistic-probabilitydistribution-module">pyFTS.probabilistic.ProbabilityDistribution module</a></li>
<li><a class="reference internal" href="#pyfts-probabilistic-kde-module">pyFTS.probabilistic.kde module</a></li>
<li><a class="reference internal" href="#module-pyFTS.probabilistic.ProbabilityDistribution">pyFTS.probabilistic.ProbabilityDistribution module</a></li>
<li><a class="reference internal" href="#module-pyFTS.probabilistic.kde">pyFTS.probabilistic.kde module</a></li>
</ul>
</li>
</ul>

File diff suppressed because one or more lines are too long

View File

@ -52,14 +52,6 @@ pyFTS.common.SortedCollection module
:undoc-members:
:show-inheritance:
pyFTS.common.transformations module
-----------------------------------
.. automodule:: pyFTS.common.Transformations
:members:
:undoc-members:
:show-inheritance:
pyFTS.common.Util module
------------------------

View File

@ -60,6 +60,14 @@ pyFTS.common.transformations.scale module
:undoc-members:
:show-inheritance:
pyFTS.common.transformations.smoothing module
---------------------------------------------
.. automodule:: pyFTS.common.transformations.smoothing
:members:
:undoc-members:
:show-inheritance:
pyFTS.common.transformations.som module
---------------------------------------

View File

@ -5,15 +5,15 @@ Common data transformation used on pre and post processing of the FTS
import numpy as np
import pandas as pd
import math
from pyFTS.common.transformations.transformation import Transformation
from pyFTS.common.transformations.differential import Differential
from pyFTS.common.transformations.scale import Scale
from pyFTS.common.transformations.adaptiveexpectation import AdaptiveExpectation
from pyFTS.common.transformations.boxcox import BoxCox
from pyFTS.common.transformations.roi import ROI
from pyFTS.common.transformations.trend import LinearTrend
from pyFTS.common.transformations.som import SOMTransformation
from pyFTS.common.transformations.normalization import Normalization
#from pyFTS.common.transformations.transformation import Transformation
#from pyFTS.common.transformations.differential import Differential
#from pyFTS.common.transformations.scale import Scale
#from pyFTS.common.transformations.adaptiveexpectation import AdaptiveExpectation
#from pyFTS.common.transformations.boxcox import BoxCox
#from pyFTS.common.transformations.roi import ROI
#from pyFTS.common.transformations.trend import LinearTrend
#from pyFTS.common.transformations.som import SOMTransformation
#from pyFTS.common.transformations.normalization import Normalization

View File

@ -2,7 +2,6 @@
Kohonen Self Organizing Maps for Fuzzy Time Series
"""
import pandas as pd
import SimpSOM as sps
from pyFTS.models.multivariate import wmvfts
from typing import Tuple
from pyFTS.common.Transformations import Transformation
@ -14,6 +13,9 @@ class SOMTransformation(Transformation):
def __init__(self,
grid_dimension: Tuple,
**kwargs):
import SimpSOM as sps
# SOM attributes
self.load_file = kwargs.get('loadFile')
self.net: sps.somNet = None