Documentation update

This commit is contained in:
Petrônio Cândido 2018-10-29 16:48:05 -03:00
parent c42dea2aca
commit 0b63ed118a
35 changed files with 478 additions and 115 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -167,6 +167,7 @@
<span class="sd"> :keyword start: in the multi step forecasting, the index of the data where to start forecasting</span> <span class="sd"> :keyword start: in the multi step forecasting, the index of the data where to start forecasting</span>
<span class="sd"> :keyword distributed: boolean, indicate if the forecasting procedure will be distributed in a dispy cluster</span> <span class="sd"> :keyword distributed: boolean, indicate if the forecasting 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"> :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.</span>
<span class="sd"> :return: a numpy array with the forecasted data</span> <span class="sd"> :return: a numpy array with the forecasted data</span>
<span class="sd"> &quot;&quot;&quot;</span> <span class="sd"> &quot;&quot;&quot;</span>
@ -416,6 +417,7 @@
<span class="k">if</span> <span class="n">save</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> <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> <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">&quot;&quot;&quot;</span>
<span class="sd"> Import the parameters values from other model</span> <span class="sd"> Import the parameters values from other model</span>

View File

@ -130,22 +130,36 @@
<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> <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">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">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="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="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">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">sets</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">sets</span><span class="p">)</span> <span class="c1">#self.sets[np.argwhere(mv == max(mv))[0, 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;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="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="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="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">_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">ret</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">sets</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">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> <span class="k">return</span> <span class="n">ret</span></div></div>
</pre></div> </pre></div>

View File

@ -136,7 +136,7 @@
<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">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> <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> <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">lags</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">flrgs</span> <span class="o">=</span> <span class="p">[]</span> <span class="n">flrgs</span> <span class="o">=</span> <span class="p">[]</span>
@ -145,6 +145,9 @@
<span class="n">lhs</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">fuzzyfy</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">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">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">lhs</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">fuzzyfy</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">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">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">lags</span><span class="p">[</span><span class="n">ct</span><span class="p">]</span> <span class="o">=</span> <span class="n">lhs</span> <span class="n">lags</span><span class="p">[</span><span class="n">ct</span><span class="p">]</span> <span class="o">=</span> <span class="n">lhs</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="n">root</span> <span class="o">=</span> <span class="n">tree</span><span class="o">.</span><span class="n">FLRGTreeNode</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span> <span class="n">root</span> <span class="o">=</span> <span class="n">tree</span><span class="o">.</span><span class="n">FLRGTreeNode</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span>
<span class="n">tree</span><span class="o">.</span><span class="n">build_tree_without_order</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">lags</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="n">tree</span><span class="o">.</span><span class="n">build_tree_without_order</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">lags</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
@ -185,27 +188,50 @@
<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> <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">ret</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">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">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">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">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="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">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">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="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="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">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">explain</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="n">tmp</span> <span class="o">=</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">flrg</span> <span class="ow">in</span> <span class="n">flrgs</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="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="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">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">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="p">)</span> <span class="n">mp</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">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">tmp</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;</span><span class="se">\t</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="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="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="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">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">tmp</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">sets</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">sets</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">mp</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">tmp</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">\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="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">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">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;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> <span class="k">return</span> <span class="n">ret</span></div></div>
</pre></div> </pre></div>

View File

@ -148,7 +148,7 @@
<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">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="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="c1"># achar o os bounds de cada FLRG, ponderados pela pertinência</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">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">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">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">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>

View File

@ -131,7 +131,7 @@
<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="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="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="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">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> <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> <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>
@ -141,7 +141,8 @@
<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> <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> <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">l</span> <span class="o">=</span> <span class="mi">1</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="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="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>
@ -149,7 +150,8 @@
<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">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">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">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">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="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
@ -157,13 +159,28 @@
<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">sets</span><span class="p">,</span> <span class="n">ordered_sets</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">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="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="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="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">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">sets</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">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="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">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> <span class="k">return</span> <span class="n">ret</span></div></div>
</pre></div> </pre></div>

View File

@ -129,7 +129,7 @@
<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> <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">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="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="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="k">if</span> <span class="n">axes</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
@ -151,11 +151,11 @@
<span class="k">else</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="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="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="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_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">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="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">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="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>

View File

@ -196,7 +196,7 @@
<span class="k">else</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</span><span class="p">(</span><span class="n">data</span><span class="p">)</span></div> <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></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> <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="n">lags</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">flrgs</span> <span class="o">=</span> <span class="p">[]</span> <span class="n">flrgs</span> <span class="o">=</span> <span class="p">[]</span>
@ -206,6 +206,9 @@
<span class="n">lags</span><span class="p">[</span><span class="n">ct</span><span class="p">]</span> <span class="o">=</span> <span class="n">lhs</span> <span class="n">lags</span><span class="p">[</span><span class="n">ct</span><span class="p">]</span> <span class="o">=</span> <span class="n">lhs</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="n">root</span> <span class="o">=</span> <span class="n">tree</span><span class="o">.</span><span class="n">FLRGTreeNode</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span> <span class="n">root</span> <span class="o">=</span> <span class="n">tree</span><span class="o">.</span><span class="n">FLRGTreeNode</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span>
<span class="n">tree</span><span class="o">.</span><span class="n">build_tree_without_order</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">lags</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="n">tree</span><span class="o">.</span><span class="n">build_tree_without_order</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">lags</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
@ -300,9 +303,6 @@
<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">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="nb">sum</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="n">ret</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">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="k">else</span><span class="p">:</span>
<span class="c1">##########################################</span>
<span class="c1"># this may be the problem! TEST IT!!!</span>
<span class="c1">##########################################</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">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="nb">sum</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">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="n">ret</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">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">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> <span class="k">return</span> <span class="n">ret</span></div>
@ -346,27 +346,48 @@
<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> <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">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="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="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="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="n">mp</span> <span class="o">=</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="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">for</span> <span class="n">flrg</span> <span class="ow">in</span> <span class="n">flrgs</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="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">if</span> <span class="n">norm</span> <span class="o">==</span> <span class="mi">0</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">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">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">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="nb">sum</span><span class="p">(</span><span class="n">norms</span><span class="p">)</span> <span class="n">norm</span> <span class="o">=</span> <span class="nb">sum</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="mi">0</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</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="n">norm</span></div>
<span class="n">final</span> <span class="o">=</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="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.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> <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="k">return</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="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">expected_value</span><span class="p">()</span></div> <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="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> <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>

View File

@ -145,7 +145,8 @@
<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> <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> <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">l</span> <span class="o">=</span> <span class="mi">1</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="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="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>
@ -162,13 +163,28 @@
<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">sets</span><span class="p">,</span> <span class="n">ordered_sets</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">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="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="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="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">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">sets</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">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="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">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> <span class="k">return</span> <span class="n">ret</span></div></div>
</pre></div> </pre></div>

View File

@ -138,6 +138,8 @@
<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> <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="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="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="k">else</span><span class="p">:</span>
@ -145,7 +147,7 @@
<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">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">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="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
@ -153,13 +155,28 @@
<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">sets</span><span class="p">,</span> <span class="n">ordered_sets</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">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="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="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="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">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">sets</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">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="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">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">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> <span class="k">return</span> <span class="n">ret</span></div></div>
</pre></div> </pre></div>

View File

@ -150,19 +150,35 @@
<span class="k">pass</span></div> <span class="k">pass</span></div>
<div class="viewcode-block" id="Partitioner.get_name"><a class="viewcode-back" href="../../../pyFTS.partitioners.html#pyFTS.partitioners.partitioner.Partitioner.get_name">[docs]</a> <span class="k">def</span> <span class="nf">get_name</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">counter</span><span class="p">):</span> <div class="viewcode-block" id="Partitioner.get_name"><a class="viewcode-back" href="../../../pyFTS.partitioners.html#pyFTS.partitioners.partitioner.Partitioner.get_name">[docs]</a> <span class="k">def</span> <span class="nf">get_name</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">counter</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Find the name of the fuzzy set given its counter id.</span>
<span class="sd"> :param counter: The number of the fuzzy set</span>
<span class="sd"> :return: String</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">prefix</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">counter</span><span class="p">)</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">setnames</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">setnames</span><span class="p">[</span><span class="n">counter</span><span class="p">]</span></div> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">prefix</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">counter</span><span class="p">)</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">setnames</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">setnames</span><span class="p">[</span><span class="n">counter</span><span class="p">]</span></div>
<div class="viewcode-block" id="Partitioner.lower_set"><a class="viewcode-back" href="../../../pyFTS.partitioners.html#pyFTS.partitioners.partitioner.Partitioner.lower_set">[docs]</a> <span class="k">def</span> <span class="nf">lower_set</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <div class="viewcode-block" id="Partitioner.lower_set"><a class="viewcode-back" href="../../../pyFTS.partitioners.html#pyFTS.partitioners.partitioner.Partitioner.lower_set">[docs]</a> <span class="k">def</span> <span class="nf">lower_set</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 fuzzy set on lower bound of the universe of discourse.</span>
<span class="sd"> :return: Fuzzy Set</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</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">ordered_sets</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span></div> <span class="k">return</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">ordered_sets</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span></div>
<div class="viewcode-block" id="Partitioner.upper_set"><a class="viewcode-back" href="../../../pyFTS.partitioners.html#pyFTS.partitioners.partitioner.Partitioner.upper_set">[docs]</a> <span class="k">def</span> <span class="nf">upper_set</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <div class="viewcode-block" id="Partitioner.upper_set"><a class="viewcode-back" href="../../../pyFTS.partitioners.html#pyFTS.partitioners.partitioner.Partitioner.upper_set">[docs]</a> <span class="k">def</span> <span class="nf">upper_set</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 fuzzy set on upper bound of the universe of discourse.</span>
<span class="sd"> :return: Fuzzy Set</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</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">ordered_sets</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span></div> <span class="k">return</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">ordered_sets</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span></div>
<div class="viewcode-block" id="Partitioner.plot"><a class="viewcode-back" href="../../../pyFTS.partitioners.html#pyFTS.partitioners.partitioner.Partitioner.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">ax</span><span class="p">):</span> <div class="viewcode-block" id="Partitioner.plot"><a class="viewcode-back" href="../../../pyFTS.partitioners.html#pyFTS.partitioners.partitioner.Partitioner.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">ax</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span> <span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Plot the </span> <span class="sd"> Plot the partitioning using the Matplotlib axis ax</span>
<span class="sd"> :param ax: </span>
<span class="sd"> :return: </span> <span class="sd"> :param ax: Matplotlib axis</span>
<span class="sd"> &quot;&quot;&quot;</span> <span class="sd"> &quot;&quot;&quot;</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_title</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="n">ax</span><span class="o">.</span><span class="n">set_title</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="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="mi">1</span><span class="p">])</span> <span class="n">ax</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
@ -182,6 +198,12 @@
<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></div> <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></div>
<div class="viewcode-block" id="Partitioner.plot_set"><a class="viewcode-back" href="../../../pyFTS.partitioners.html#pyFTS.partitioners.partitioner.Partitioner.plot_set">[docs]</a> <span class="k">def</span> <span class="nf">plot_set</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">,</span> <span class="n">s</span><span class="p">):</span> <div class="viewcode-block" id="Partitioner.plot_set"><a class="viewcode-back" href="../../../pyFTS.partitioners.html#pyFTS.partitioners.partitioner.Partitioner.plot_set">[docs]</a> <span class="k">def</span> <span class="nf">plot_set</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">,</span> <span class="n">s</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Plot an isolate fuzzy set on Matplotlib axis</span>
<span class="sd"> :param ax: Matplotlib axis</span>
<span class="sd"> :param s: Fuzzy Set</span>
<span class="sd"> &quot;&quot;&quot;</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="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="n">s</span><span class="o">.</span><span class="n">parameters</span><span class="p">[</span><span class="mi">1</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">2</span><span class="p">]],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">alpha</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">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="n">s</span><span class="o">.</span><span class="n">parameters</span><span class="p">[</span><span class="mi">1</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">2</span><span class="p">]],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">alpha</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="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>
@ -191,12 +213,24 @@
<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="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="n">s</span><span class="o">.</span><span class="n">alpha</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">alpha</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span></div> <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="n">s</span><span class="o">.</span><span class="n">alpha</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">alpha</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span></div>
<span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">def</span> <span class="nf">__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"> Return a string representation of the partitioner, the list of fuzzy sets and their parameters</span>
<span class="sd"> :return:</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="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">key</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="o">.</span><span class="n">keys</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">sets</span><span class="o">.</span><span class="n">keys</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">sets</span><span class="p">[</span><span class="n">key</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">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">sets</span><span class="p">[</span><span class="n">key</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> <span class="k">return</span> <span class="n">tmp</span>
<span class="k">def</span> <span class="nf">__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"> Return the number of partitions</span>
<span class="sd"> :return: number of partitions</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitions</span></div>
</pre></div> </pre></div>
</div> </div>

View File

@ -1818,6 +1818,7 @@ needed to forecast a single step ahead</p>
<li><strong>start</strong> in the multi step forecasting, the index of the data where to start forecasting</li> <li><strong>start</strong> in the multi step forecasting, the index of the data where to start forecasting</li>
<li><strong>distributed</strong> boolean, indicate if the forecasting procedure will be distributed in a dispy cluster</li> <li><strong>distributed</strong> boolean, indicate if the forecasting procedure will be distributed in a dispy cluster</li>
<li><strong>nodes</strong> a list with the dispy cluster nodes addresses</li> <li><strong>nodes</strong> a list with the dispy cluster nodes addresses</li>
<li><strong>explain</strong> try to explain, step by step, the one-step-ahead point forecasting result given the input data.</li>
</ul> </ul>
</td> </td>
</tr> </tr>

View File

@ -239,7 +239,7 @@
</ul> </ul>
</td> </td>
</tr> </tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the forecasted Probability Distributions</p> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with probabilistic.ProbabilityDistribution objects representing the forecasted Probability Distributions</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -260,7 +260,7 @@
</ul> </ul>
</td> </td>
</tr> </tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the forecasted intervals</p> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the prediction intervals</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -345,7 +345,7 @@
</ul> </ul>
</td> </td>
</tr> </tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the forecasted Probability Distributions</p> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with probabilistic.ProbabilityDistribution objects representing the forecasted Probability Distributions</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View File

@ -471,7 +471,7 @@ using Fuzzy Time Series. 2017 IEEE International Conference on Fuzzy Systems. DO
<dl class="method"> <dl class="method">
<dt id="pyFTS.models.hofts.HighOrderFTS.generate_lhs_flrg"> <dt id="pyFTS.models.hofts.HighOrderFTS.generate_lhs_flrg">
<code class="descname">generate_lhs_flrg</code><span class="sig-paren">(</span><em>sample</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/hofts.html#HighOrderFTS.generate_lhs_flrg"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.hofts.HighOrderFTS.generate_lhs_flrg" title="Permalink to this definition"></a></dt> <code class="descname">generate_lhs_flrg</code><span class="sig-paren">(</span><em>sample</em>, <em>explain=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/hofts.html#HighOrderFTS.generate_lhs_flrg"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.hofts.HighOrderFTS.generate_lhs_flrg" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd></dd></dl>
<dl class="method"> <dl class="method">
@ -575,7 +575,7 @@ In: Computational Intelligence (SSCI), 2016 IEEE Symposium Series on. IEEE, 2016
</ul> </ul>
</td> </td>
</tr> </tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the forecasted intervals</p> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the prediction intervals</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -893,7 +893,7 @@ US Dollar to Ringgit Malaysia,” Int. J. Comput. Intell. Appl., vol. 12, no. 1,
</ul> </ul>
</td> </td>
</tr> </tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the forecasted Probability Distributions</p> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with probabilistic.ProbabilityDistribution objects representing the forecasted Probability Distributions</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -914,7 +914,7 @@ US Dollar to Ringgit Malaysia,” Int. J. Comput. Intell. Appl., vol. 12, no. 1,
</ul> </ul>
</td> </td>
</tr> </tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the forecasted intervals</p> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the prediction intervals</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -928,7 +928,7 @@ US Dollar to Ringgit Malaysia,” Int. J. Comput. Intell. Appl., vol. 12, no. 1,
<dl class="method"> <dl class="method">
<dt id="pyFTS.models.pwfts.ProbabilisticWeightedFTS.generate_lhs_flrg"> <dt id="pyFTS.models.pwfts.ProbabilisticWeightedFTS.generate_lhs_flrg">
<code class="descname">generate_lhs_flrg</code><span class="sig-paren">(</span><em>sample</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/pwfts.html#ProbabilisticWeightedFTS.generate_lhs_flrg"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.pwfts.ProbabilisticWeightedFTS.generate_lhs_flrg" title="Permalink to this definition"></a></dt> <code class="descname">generate_lhs_flrg</code><span class="sig-paren">(</span><em>sample</em>, <em>explain=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/pwfts.html#ProbabilisticWeightedFTS.generate_lhs_flrg"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.pwfts.ProbabilisticWeightedFTS.generate_lhs_flrg" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd></dd></dl>
<dl class="method"> <dl class="method">

View File

@ -299,7 +299,7 @@ IEEE Transactions on Fuzzy Systems, v. 16, n. 4, p. 1072-1086, 2008.</p>
</ul> </ul>
</td> </td>
</tr> </tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the forecasted intervals</p> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the prediction intervals</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -507,7 +507,7 @@ IEEE Transactions on Fuzzy Systems, v. 16, n. 4, p. 1072-1086, 2008.</p>
</ul> </ul>
</td> </td>
</tr> </tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the forecasted intervals</p> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the prediction intervals</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -605,7 +605,7 @@ IEEE Transactions on Fuzzy Systems, v. 16, n. 4, p. 1072-1086, 2008.</p>
</ul> </ul>
</td> </td>
</tr> </tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the forecasted intervals</p> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the prediction intervals</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -745,7 +745,7 @@ IEEE Transactions on Fuzzy Systems, v. 16, n. 4, p. 1072-1086, 2008.</p>
<dl class="function"> <dl class="function">
<dt id="pyFTS.models.nonstationary.util.plot_sets_conditional"> <dt id="pyFTS.models.nonstationary.util.plot_sets_conditional">
<code class="descclassname">pyFTS.models.nonstationary.util.</code><code class="descname">plot_sets_conditional</code><span class="sig-paren">(</span><em>model, data, step=1, size=[5, 5], colors=None, save=False, file=None, axes=None</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> <code class="descclassname">pyFTS.models.nonstationary.util.</code><code class="descname">plot_sets_conditional</code><span class="sig-paren">(</span><em>model, data, step=1, size=[5, 5], colors=None, save=False, file=None, axes=None, fig=None</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> <dd></dd></dl>
</div> </div>

View File

@ -146,12 +146,32 @@
<dl class="method"> <dl class="method">
<dt id="pyFTS.partitioners.partitioner.Partitioner.get_name"> <dt id="pyFTS.partitioners.partitioner.Partitioner.get_name">
<code class="descname">get_name</code><span class="sig-paren">(</span><em>counter</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/partitioner.html#Partitioner.get_name"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.partitioners.partitioner.Partitioner.get_name" title="Permalink to this definition"></a></dt> <code class="descname">get_name</code><span class="sig-paren">(</span><em>counter</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/partitioner.html#Partitioner.get_name"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.partitioners.partitioner.Partitioner.get_name" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd><p>Find the name of the fuzzy set given its counter id.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>counter</strong> The number of the fuzzy set</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">String</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method"> <dl class="method">
<dt id="pyFTS.partitioners.partitioner.Partitioner.lower_set"> <dt id="pyFTS.partitioners.partitioner.Partitioner.lower_set">
<code class="descname">lower_set</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/partitioner.html#Partitioner.lower_set"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.partitioners.partitioner.Partitioner.lower_set" title="Permalink to this definition"></a></dt> <code class="descname">lower_set</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/partitioner.html#Partitioner.lower_set"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.partitioners.partitioner.Partitioner.lower_set" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd><p>Return the fuzzy set on lower bound of the universe of discourse.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Fuzzy Set</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="attribute"> <dl class="attribute">
<dt id="pyFTS.partitioners.partitioner.Partitioner.membership_function"> <dt id="pyFTS.partitioners.partitioner.Partitioner.membership_function">
@ -174,15 +194,34 @@
<dl class="method"> <dl class="method">
<dt id="pyFTS.partitioners.partitioner.Partitioner.plot"> <dt id="pyFTS.partitioners.partitioner.Partitioner.plot">
<code class="descname">plot</code><span class="sig-paren">(</span><em>ax</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/partitioner.html#Partitioner.plot"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.partitioners.partitioner.Partitioner.plot" title="Permalink to this definition"></a></dt> <code class="descname">plot</code><span class="sig-paren">(</span><em>ax</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/partitioner.html#Partitioner.plot"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.partitioners.partitioner.Partitioner.plot" title="Permalink to this definition"></a></dt>
<dd><p>Plot the <dd><p>Plot the partitioning using the Matplotlib axis ax</p>
:param ax: <table class="docutils field-list" frame="void" rules="none">
:return:</p> <col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>ax</strong> Matplotlib axis</td>
</tr>
</tbody>
</table>
</dd></dl> </dd></dl>
<dl class="method"> <dl class="method">
<dt id="pyFTS.partitioners.partitioner.Partitioner.plot_set"> <dt id="pyFTS.partitioners.partitioner.Partitioner.plot_set">
<code class="descname">plot_set</code><span class="sig-paren">(</span><em>ax</em>, <em>s</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/partitioner.html#Partitioner.plot_set"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.partitioners.partitioner.Partitioner.plot_set" title="Permalink to this definition"></a></dt> <code class="descname">plot_set</code><span class="sig-paren">(</span><em>ax</em>, <em>s</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/partitioner.html#Partitioner.plot_set"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.partitioners.partitioner.Partitioner.plot_set" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd><p>Plot an isolate fuzzy set on Matplotlib axis</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>ax</strong> Matplotlib axis</li>
<li><strong>s</strong> Fuzzy Set</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="attribute"> <dl class="attribute">
<dt id="pyFTS.partitioners.partitioner.Partitioner.prefix"> <dt id="pyFTS.partitioners.partitioner.Partitioner.prefix">
@ -205,7 +244,16 @@
<dl class="method"> <dl class="method">
<dt id="pyFTS.partitioners.partitioner.Partitioner.upper_set"> <dt id="pyFTS.partitioners.partitioner.Partitioner.upper_set">
<code class="descname">upper_set</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/partitioner.html#Partitioner.upper_set"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.partitioners.partitioner.Partitioner.upper_set" title="Permalink to this definition"></a></dt> <code class="descname">upper_set</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/partitioner.html#Partitioner.upper_set"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.partitioners.partitioner.Partitioner.upper_set" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd><p>Return the fuzzy set on upper bound of the universe of discourse.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Fuzzy Set</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl> </dd></dl>

File diff suppressed because one or more lines are too long

View File

@ -93,6 +93,7 @@ class FTS(object):
:keyword start: in the multi step forecasting, the index of the data where to start forecasting :keyword start: in the multi step forecasting, the index of the data where to start forecasting
:keyword distributed: boolean, indicate if the forecasting procedure will be distributed in a dispy cluster :keyword distributed: boolean, indicate if the forecasting procedure will be distributed in a dispy cluster
:keyword nodes: a list with the dispy cluster nodes addresses :keyword nodes: a list with the dispy cluster nodes addresses
:keyword explain: try to explain, step by step, the one-step-ahead point forecasting result given the input data.
:return: a numpy array with the forecasted data :return: a numpy array with the forecasted data
""" """
@ -342,6 +343,7 @@ class FTS(object):
if save: if save:
Util.persist_obj(self, file_path) Util.persist_obj(self, file_path)
def clone_parameters(self, model): def clone_parameters(self, model):
""" """
Import the parameters values from other model Import the parameters values from other model

View File

@ -56,21 +56,35 @@ class ConventionalFTS(fts.FTS):
def forecast(self, ndata, **kwargs): def forecast(self, ndata, **kwargs):
l = len(ndata) explain = kwargs.get('explain',False)
l = len(ndata) if not explain else 1
ret = [] ret = []
for k in np.arange(0, l): for k in np.arange(0, l):
mv = FuzzySet.fuzzyfy_instance(ndata[k], self.sets) actual = FuzzySet.get_maximum_membership_fuzzyset(ndata[k], self.sets)
actual = FuzzySet.get_maximum_membership_fuzzyset(ndata[k], self.sets) #self.sets[np.argwhere(mv == max(mv))[0, 0]] if explain:
print("Fuzzyfication:\n\n {} -> {} \n".format(ndata[k], actual.name))
if actual.name not in self.flrgs: if actual.name not in self.flrgs:
ret.append(actual.centroid) ret.append(actual.centroid)
if explain:
print("Rules:\n\n {} -> {} (Naïve)\t Midpoint: {} \n\n".format(actual.name, actual.name,actual.centroid))
else: else:
_flrg = self.flrgs[actual.name] _flrg = self.flrgs[actual.name]
ret.append(_flrg.get_midpoint(self.sets)) mp = _flrg.get_midpoint(self.sets)
ret.append(mp)
if explain:
print("Rules:\n\n {} \t Midpoint: {} \n".format(str(_flrg), mp))
print("Deffuzyfied value: {} \n".format(mp))
return ret return ret

View File

@ -62,7 +62,7 @@ class HighOrderFTS(fts.FTS):
self.max_lag = self.order self.max_lag = self.order
self.lags = np.arange(1, self.order+1) self.lags = np.arange(1, self.order+1)
def generate_lhs_flrg(self, sample): def generate_lhs_flrg(self, sample, explain=False):
lags = {} lags = {}
flrgs = [] flrgs = []
@ -71,6 +71,9 @@ class HighOrderFTS(fts.FTS):
lhs = FuzzySet.fuzzyfy(sample[o-1], partitioner=self.partitioner, mode="sets", alpha_cut=self.alpha_cut) lhs = FuzzySet.fuzzyfy(sample[o-1], partitioner=self.partitioner, mode="sets", alpha_cut=self.alpha_cut)
lags[ct] = lhs lags[ct] = lhs
if explain:
print("\t (Lag {}) {} -> {} \n".format(o, sample[o-1], lhs))
root = tree.FLRGTreeNode(None) root = tree.FLRGTreeNode(None)
tree.build_tree_without_order(root, lags, 0) tree.build_tree_without_order(root, lags, 0)
@ -111,26 +114,49 @@ class HighOrderFTS(fts.FTS):
def forecast(self, ndata, **kwargs): def forecast(self, ndata, **kwargs):
explain = kwargs.get('explain', False)
ret = [] ret = []
l = len(ndata) l = len(ndata) if not explain else self.max_lag + 1
if l < self.max_lag: if l < self.max_lag:
return ndata return ndata
for k in np.arange(self.max_lag, l+1): for k in np.arange(self.max_lag, l+1):
flrgs = self.generate_lhs_flrg(ndata[k - self.max_lag: k])
if explain:
print("Fuzzyfication \n")
flrgs = self.generate_lhs_flrg(ndata[k - self.max_lag: k], explain)
if explain:
print("Rules:\n")
tmp = [] tmp = []
for flrg in flrgs: for flrg in flrgs:
if flrg.get_key() not in self.flrgs: if flrg.get_key() not in self.flrgs:
if len(flrg.LHS) > 0: if len(flrg.LHS) > 0:
tmp.append(self.sets[flrg.LHS[-1]].centroid) mp = self.sets[flrg.LHS[-1]].centroid
tmp.append(mp)
if explain:
print("\t {} -> {} (Naïve)\t Midpoint: {}\n".format(str(flrg.LHS), flrg.LHS[-1],
mp))
else: else:
flrg = self.flrgs[flrg.get_key()] flrg = self.flrgs[flrg.get_key()]
tmp.append(flrg.get_midpoint(self.sets)) mp = flrg.get_midpoint(self.sets)
tmp.append(mp)
ret.append(np.nanmean(tmp)) if explain:
print("\t {} \t Midpoint: {}\n".format(str(flrg), mp))
final = np.nanmean(tmp)
ret.append(final)
if explain:
print("Deffuzyfied value: {} \n".format(final))
return ret return ret

View File

@ -74,7 +74,7 @@ class IntervalFTS(hofts.HighOrderFTS):
for flrg in flrgs: for flrg in flrgs:
if len(flrg.LHS) > 0: if len(flrg.LHS) > 0:
# achar o os bounds de cada FLRG, ponderados pela pertinência
mv = flrg.get_membership(sample, self.sets) mv = flrg.get_membership(sample, self.sets)
up.append(mv * self.get_upper(flrg)) up.append(mv * self.get_upper(flrg))
lo.append(mv * self.get_lower(flrg)) lo.append(mv * self.get_lower(flrg))

View File

@ -57,7 +57,7 @@ class ImprovedWeightedFTS(fts.FTS):
if flr.LHS in self.flrgs: if flr.LHS in self.flrgs:
self.flrgs[flr.LHS].append_rhs(flr.RHS) self.flrgs[flr.LHS].append_rhs(flr.RHS)
else: else:
self.flrgs[flr.LHS] = ImprovedWeightedFLRG(flr.LHS); self.flrgs[flr.LHS] = ImprovedWeightedFLRG(flr.LHS)
self.flrgs[flr.LHS].append_rhs(flr.RHS) self.flrgs[flr.LHS].append_rhs(flr.RHS)
def train(self, ndata, **kwargs): def train(self, ndata, **kwargs):
@ -67,7 +67,8 @@ class ImprovedWeightedFTS(fts.FTS):
self.generate_flrg(flrs) self.generate_flrg(flrs)
def forecast(self, ndata, **kwargs): def forecast(self, ndata, **kwargs):
l = 1
explain = kwargs.get('explain', False)
if self.partitioner is not None: if self.partitioner is not None:
ordered_sets = self.partitioner.ordered_sets ordered_sets = self.partitioner.ordered_sets
@ -75,7 +76,8 @@ class ImprovedWeightedFTS(fts.FTS):
ordered_sets = FuzzySet.set_ordered(self.sets) ordered_sets = FuzzySet.set_ordered(self.sets)
ndata = np.array(ndata) ndata = np.array(ndata)
l = len(ndata)
l = len(ndata) if not explain else 1
ret = [] ret = []
@ -83,12 +85,27 @@ class ImprovedWeightedFTS(fts.FTS):
actual = FuzzySet.get_maximum_membership_fuzzyset(ndata[k], self.sets, ordered_sets) actual = FuzzySet.get_maximum_membership_fuzzyset(ndata[k], self.sets, ordered_sets)
if explain:
print("Fuzzyfication:\n\n {} -> {} \n".format(ndata[k], actual.name))
if actual.name not in self.flrgs: if actual.name not in self.flrgs:
ret.append(actual.centroid) ret.append(actual.centroid)
if explain:
print("Rules:\n\n {} -> {} (Naïve)\t Midpoint: {} \n\n".format(actual.name, actual.name,actual.centroid))
else: else:
flrg = self.flrgs[actual.name] flrg = self.flrgs[actual.name]
mp = flrg.get_midpoints(self.sets) mp = flrg.get_midpoints(self.sets)
ret.append(mp.dot(flrg.weights())) final = mp.dot(flrg.weights())
ret.append(final)
if explain:
print("Rules:\n\n {} \n\n ".format(str(flrg)))
print("Midpoints: \n\n {}\n\n".format(mp))
print("Deffuzyfied value: {} \n".format(final))
return ret return ret

View File

@ -55,7 +55,7 @@ def plot_sets(partitioner, start=0, end=10, step=1, tam=[5, 5], colors=None,
def plot_sets_conditional(model, data, step=1, size=[5, 5], colors=None, def plot_sets_conditional(model, data, step=1, size=[5, 5], colors=None,
save=False, file=None, axes=None): save=False, file=None, axes=None, fig=None):
range = np.arange(0, len(data), step) range = np.arange(0, len(data), step)
ticks = [] ticks = []
if axes is None: if axes is None:
@ -77,11 +77,11 @@ def plot_sets_conditional(model, data, step=1, size=[5, 5], colors=None,
else: else:
axes.plot([t, t + 1, t], param,c=set.metadata['color']) axes.plot([t, t + 1, t], param,c=set.metadata['color'])
ticks.extend(["t+"+str(t),""]) #ticks.extend(["t+"+str(t),""])
axes.set_ylabel("Universe of Discourse") axes.set_ylabel("Universe of Discourse")
axes.set_xlabel("Time") axes.set_xlabel("Time")
plt.xticks([k for k in range], ticks, rotation='vertical') #plt.xticks([k for k in range], ticks, rotation='vertical')
handles0, labels0 = axes.get_legend_handles_labels() handles0, labels0 = axes.get_legend_handles_labels()
lgd = axes.legend(handles0, labels0, loc=2, bbox_to_anchor=(1, 1)) lgd = axes.legend(handles0, labels0, loc=2, bbox_to_anchor=(1, 1))

View File

@ -122,7 +122,7 @@ class ProbabilisticWeightedFTS(ifts.IntervalFTS):
else: else:
self.generate_flrg(data) self.generate_flrg(data)
def generate_lhs_flrg(self, sample): def generate_lhs_flrg(self, sample, explain=False):
lags = {} lags = {}
flrgs = [] flrgs = []
@ -132,6 +132,9 @@ class ProbabilisticWeightedFTS(ifts.IntervalFTS):
lags[ct] = lhs lags[ct] = lhs
if explain:
print("\t (Lag {}) {} -> {} \n".format(o, sample[o-1], lhs))
root = tree.FLRGTreeNode(None) root = tree.FLRGTreeNode(None)
tree.build_tree_without_order(root, lags, 0) tree.build_tree_without_order(root, lags, 0)
@ -226,9 +229,6 @@ class ProbabilisticWeightedFTS(ifts.IntervalFTS):
cond.append(tmp) cond.append(tmp)
ret = sum(np.array(cond)) ret = sum(np.array(cond))
else: else:
##########################################
# this may be the problem! TEST IT!!!
##########################################
pi = 1 / len(flrg.LHS) pi = 1 / len(flrg.LHS)
ret = sum(np.array([pi * self.sets[s].membership(x) for s in flrg.LHS])) ret = sum(np.array([pi * self.sets[s].membership(x) for s in flrg.LHS]))
return ret return ret
@ -272,27 +272,48 @@ class ProbabilisticWeightedFTS(ifts.IntervalFTS):
def point_heuristic(self, sample, **kwargs): def point_heuristic(self, sample, **kwargs):
flrgs = self.generate_lhs_flrg(sample) explain = kwargs.get('explain', False)
if explain:
print("Fuzzyfication \n")
flrgs = self.generate_lhs_flrg(sample, explain)
mp = [] mp = []
norms = [] norms = []
if explain:
print("Rules:\n")
for flrg in flrgs: for flrg in flrgs:
norm = self.flrg_lhs_conditional_probability(sample, flrg) norm = self.flrg_lhs_conditional_probability(sample, flrg)
if norm == 0: if norm == 0:
norm = self.flrg_lhs_unconditional_probability(flrg) norm = self.flrg_lhs_unconditional_probability(flrg)
if explain:
print("\t {} \t Midpoint: {}\t Norm: {}\n".format(str(self.flrgs[flrg.get_key()]),
self.get_midpoint(flrg), norm))
mp.append(norm * self.get_midpoint(flrg)) mp.append(norm * self.get_midpoint(flrg))
norms.append(norm) norms.append(norm)
norm = sum(norms) norm = sum(norms)
if norm == 0:
return 0
else:
return sum(mp) / norm
final = sum(mp) / norm if norm != 0 else 0
if explain:
print("Deffuzyfied value: {} \n".format(final))
return final
def point_expected_value(self, sample, **kwargs): def point_expected_value(self, sample, **kwargs):
return self.forecast_distribution(sample)[0].expected_value() explain = kwargs.get('explain', False)
dist = self.forecast_distribution(sample)[0]
final = dist.expected_value()
return final
def forecast_interval(self, ndata, **kwargs): def forecast_interval(self, ndata, **kwargs):

View File

@ -71,7 +71,8 @@ class ExponentialyWeightedFTS(fts.FTS):
self.generate_flrg(flrs, self.c) self.generate_flrg(flrs, self.c)
def forecast(self, ndata, **kwargs): def forecast(self, ndata, **kwargs):
l = 1
explain = kwargs.get('explain', False)
if self.partitioner is not None: if self.partitioner is not None:
ordered_sets = self.partitioner.ordered_sets ordered_sets = self.partitioner.ordered_sets
@ -88,12 +89,27 @@ class ExponentialyWeightedFTS(fts.FTS):
actual = FuzzySet.get_maximum_membership_fuzzyset(ndata[k], self.sets, ordered_sets) actual = FuzzySet.get_maximum_membership_fuzzyset(ndata[k], self.sets, ordered_sets)
if explain:
print("Fuzzyfication:\n\n {} -> {} \n".format(ndata[k], actual.name))
if actual.name not in self.flrgs: if actual.name not in self.flrgs:
ret.append(actual.centroid) ret.append(actual.centroid)
if explain:
print("Rules:\n\n {} -> {} (Naïve)\t Midpoint: {} \n\n".format(actual.name, actual.name,actual.centroid))
else: else:
flrg = self.flrgs[actual.name] flrg = self.flrgs[actual.name]
mp = flrg.get_midpoints(self.sets) mp = flrg.get_midpoints(self.sets)
ret.append(mp.dot(flrg.weights())) final = mp.dot(flrg.weights())
ret.append(final)
if explain:
print("Rules:\n\n {} \n\n ".format(str(flrg)))
print("Midpoints: \n\n {}\n\n".format(mp))
print("Deffuzyfied value: {} \n".format(final))
return ret return ret

View File

@ -64,6 +64,8 @@ class WeightedFTS(fts.FTS):
def forecast(self, ndata, **kwargs): def forecast(self, ndata, **kwargs):
explain = kwargs.get('explain', False)
if self.partitioner is not None: if self.partitioner is not None:
ordered_sets = self.partitioner.ordered_sets ordered_sets = self.partitioner.ordered_sets
else: else:
@ -71,7 +73,7 @@ class WeightedFTS(fts.FTS):
ndata = np.array(ndata) ndata = np.array(ndata)
l = len(ndata) l = len(ndata) if not explain else 1
ret = [] ret = []
@ -79,12 +81,27 @@ class WeightedFTS(fts.FTS):
actual = FuzzySet.get_maximum_membership_fuzzyset(ndata[k], self.sets, ordered_sets) actual = FuzzySet.get_maximum_membership_fuzzyset(ndata[k], self.sets, ordered_sets)
if explain:
print("Fuzzyfication:\n\n {} -> {} \n\n".format(ndata[k], actual.name))
if actual.name not in self.flrgs: if actual.name not in self.flrgs:
ret.append(actual.centroid) ret.append(actual.centroid)
if explain:
print("Rules:\n\n {} -> {} (Naïve)\t Midpoint: {} \n\n".format(actual.name, actual.name,actual.centroid))
else: else:
flrg = self.flrgs[actual.name] flrg = self.flrgs[actual.name]
mp = flrg.get_midpoints(self.sets) mp = flrg.get_midpoints(self.sets)
ret.append(mp.dot(flrg.weights(self.sets))) final = mp.dot(flrg.weights(self.sets))
ret.append(final)
if explain:
print("Rules:\n\n {} \n\n ".format(str(flrg)))
print("Midpoints: \n\n {}\n\n".format(mp))
print("Deffuzyfied value: {} \n".format(final))
return ret return ret

View File

@ -76,19 +76,35 @@ class Partitioner(object):
pass pass
def get_name(self, counter): def get_name(self, counter):
"""
Find the name of the fuzzy set given its counter id.
:param counter: The number of the fuzzy set
:return: String
"""
return self.prefix + str(counter) if self.setnames is None else self.setnames[counter] return self.prefix + str(counter) if self.setnames is None else self.setnames[counter]
def lower_set(self): def lower_set(self):
"""
Return the fuzzy set on lower bound of the universe of discourse.
:return: Fuzzy Set
"""
return self.sets[self.ordered_sets[0]] return self.sets[self.ordered_sets[0]]
def upper_set(self): def upper_set(self):
"""
Return the fuzzy set on upper bound of the universe of discourse.
:return: Fuzzy Set
"""
return self.sets[self.ordered_sets[-1]] return self.sets[self.ordered_sets[-1]]
def plot(self, ax): def plot(self, ax):
""" """
Plot the Plot the partitioning using the Matplotlib axis ax
:param ax:
:return: :param ax: Matplotlib axis
""" """
ax.set_title(self.name) ax.set_title(self.name)
ax.set_ylim([0, 1]) ax.set_ylim([0, 1])
@ -108,6 +124,12 @@ class Partitioner(object):
ax.xaxis.set_ticks(x) ax.xaxis.set_ticks(x)
def plot_set(self, ax, s): def plot_set(self, ax, s):
"""
Plot an isolate fuzzy set on Matplotlib axis
:param ax: Matplotlib axis
:param s: Fuzzy Set
"""
if s.mf == Membership.trimf: if s.mf == Membership.trimf:
ax.plot([s.parameters[0], s.parameters[1], s.parameters[2]], [0, s.alpha, 0]) ax.plot([s.parameters[0], s.parameters[1], s.parameters[2]], [0, s.alpha, 0])
elif s.mf == Membership.gaussmf: elif s.mf == Membership.gaussmf:
@ -117,9 +139,21 @@ class Partitioner(object):
elif s.mf == Membership.trapmf: elif s.mf == Membership.trapmf:
ax.plot(s.parameters, [0, s.alpha, s.alpha, 0]) ax.plot(s.parameters, [0, s.alpha, s.alpha, 0])
def __str__(self): def __str__(self):
"""
Return a string representation of the partitioner, the list of fuzzy sets and their parameters
:return:
"""
tmp = self.name + ":\n" tmp = self.name + ":\n"
for key in self.sets.keys(): for key in self.sets.keys():
tmp += str(self.sets[key])+ "\n" tmp += str(self.sets[key])+ "\n"
return tmp return tmp
def __len__(self):
"""
Return the number of partitions
:return: number of partitions
"""
return self.partitions

View File

@ -11,7 +11,7 @@ import pandas as pd
from pyFTS.common import Util as cUtil, FuzzySet from pyFTS.common import Util as cUtil, FuzzySet
from pyFTS.partitioners import Grid, Util as pUtil from pyFTS.partitioners import Grid, Util as pUtil
from pyFTS.benchmarks import benchmarks as bchmk from pyFTS.benchmarks import benchmarks as bchmk
from pyFTS.models import chen from pyFTS.models import chen, yu, cheng, ismailefendi, hofts, pwfts
from pyFTS.common import Transformations from pyFTS.common import Transformations
tdiff = Transformations.Differential(1) tdiff = Transformations.Differential(1)
@ -19,15 +19,18 @@ tdiff = Transformations.Differential(1)
from pyFTS.data import TAIEX, SP500, NASDAQ from pyFTS.data import TAIEX, SP500, NASDAQ
dataset = TAIEX.get_data() dataset = TAIEX.get_data()
'''
partitioner = Grid.GridPartitioner(data=dataset[:800], npart=3, transformation=tdiff)
model = chen.ConventionalFTS(partitioner=partitioner) partitioner = Grid.GridPartitioner(data=dataset[:800], npart=30) #, transformation=tdiff)
model.append_transformation(tdiff)
model.fit([0, 90.00]) model = pwfts.ProbabilisticWeightedFTS(partitioner=partitioner, order=2)
#model.append_transformation(tdiff)
model.fit(dataset[:800])
print(model) print(model)
ret = model.predict([5000.00, 5200.00, 5400.00], explain=True)
''' '''
#dataset = SP500.get_data()[11500:16000] #dataset = SP500.get_data()[11500:16000]
#dataset = NASDAQ.get_data() #dataset = NASDAQ.get_data()
@ -57,7 +60,7 @@ bchmk.sliding_window_benchmarks(dataset, 1000, train=0.8, inc=0.2,
#steps_ahead=[1,2,4,6,8,10], #steps_ahead=[1,2,4,6,8,10],
distributed=False, nodes=['192.168.0.110', '192.168.0.107', '192.168.0.106'], distributed=False, nodes=['192.168.0.110', '192.168.0.107', '192.168.0.106'],
file="benchmarks.db", dataset="NASDAQ", tag="comparisons") file="benchmarks.db", dataset="NASDAQ", tag="comparisons")
'''
''' '''
''' '''
from pyFTS.partitioners import Grid, Util as pUtil from pyFTS.partitioners import Grid, Util as pUtil

View File

@ -10,7 +10,7 @@ import pandas as pd
from pyFTS.data import TAIEX, NASDAQ, SP500, artificial, mackey_glass from pyFTS.data import TAIEX, NASDAQ, SP500, artificial, mackey_glass
mackey_glass.get_data() #mackey_glass.get_data()
datasets = { datasets = {
"TAIEX": TAIEX.get_data()[:4000], "TAIEX": TAIEX.get_data()[:4000],
@ -54,14 +54,31 @@ partitions = {'CMIV': {'BoxCox(0)': 36, 'Differential(1)': 11, 'None': 8},
'TAIEX': {'BoxCox(0)': 39, 'Differential(1)': 31, 'None': 33}} 'TAIEX': {'BoxCox(0)': 39, 'Differential(1)': 31, 'None': 33}}
from pyFTS.models.nonstationary import partitioners as nspart, cvfts, util as nsUtil from pyFTS.models.nonstationary import partitioners as nspart, cvfts, util as nsUtil
'''
#fs = nspart.simplenonstationary_gridpartitioner_builder(data=datasets['SP500'][:300],
# npart=partitions['SP500']['None'],
# transformation=None)
fs = Grid.GridPartitioner(data=datasets['SP500'][:300],
npart=15,
transformation=None)
fig, axes = plt.subplots(nrows=1, ncols=1, figsize=[15, 5])
fs.plot(axes)
from pyFTS.common import Util
Util.show_and_save_image(fig, "fig2.png", True)
#nsUtil.plot_sets(fs)
'''
def model_details(ds, tf, train_split, test_split): def model_details(ds, tf, train_split, test_split):
data = datasets[ds] data = datasets[ds]
train = data[:train_split] train = data[:train_split]
test = data[train_split:test_split] test = data[train_split:test_split]
transformation = transformations[tf] transformation = transformations[tf]
fs = nspart.simplenonstationary_gridpartitioner_builder(data=train, npart=partitions[ds][tf], fs = nspart.simplenonstationary_gridpartitioner_builder(data=train, npart=15, #partitions[ds][tf],
transformation=transformation) transformation=transformation)
model = nsfts.NonStationaryFTS(partitioner=fs) model = nsfts.NonStationaryFTS(partitioner=fs)
model.fit(train) model.fit(train)
@ -69,21 +86,24 @@ def model_details(ds, tf, train_split, test_split):
forecasts = model.predict(test) forecasts = model.predict(test)
residuals = np.array(test[1:]) - np.array(forecasts[:-1]) residuals = np.array(test[1:]) - np.array(forecasts[:-1])
fig, axes = plt.subplots(nrows=2, ncols=1, figsize=[15, 10]) fig, axes = plt.subplots(nrows=3, ncols=1, figsize=[15, 10])
axes[0].plot(test[1:], label="Original") axes[0].plot(test[1:], label="Original")
axes[0].plot(forecasts[:-1], label="Forecasts") axes[0].plot(forecasts[:-1], label="Forecasts")
axes[0].set_ylabel("Univ. of Discourse")
axes[1].set_title("Residuals") #axes[1].set_title("Residuals")
axes[1].plot(residuals) axes[1].plot(residuals)
axes[1].set_ylabel("Error")
handles0, labels0 = axes[0].get_legend_handles_labels() handles0, labels0 = axes[0].get_legend_handles_labels()
lgd = axes[0].legend(handles0, labels0, loc=2) lgd = axes[0].legend(handles0, labels0, loc=2)
nsUtil.plot_sets_conditional(model, test, step=10, size=[12, 5]) nsUtil.plot_sets_conditional(model, test, step=10, size=[10, 7],
save=True,file="fig.png", axes=axes[2], fig=fig)
model_details('NASDAQ','None',200,2000)
model_details('SP500','None',200,400)
#'''
print("ts")
''' '''
tag = 'benchmarks' tag = 'benchmarks'

View File

@ -5,16 +5,12 @@ setup(
packages=['pyFTS', 'pyFTS.benchmarks', 'pyFTS.common', 'pyFTS.data', 'pyFTS.models.ensemble', packages=['pyFTS', 'pyFTS.benchmarks', 'pyFTS.common', 'pyFTS.data', 'pyFTS.models.ensemble',
'pyFTS.models', 'pyFTS.models.seasonal', 'pyFTS.partitioners', 'pyFTS.probabilistic', 'pyFTS.models', 'pyFTS.models.seasonal', 'pyFTS.partitioners', 'pyFTS.probabilistic',
'pyFTS.tests', 'pyFTS.models.nonstationary', 'pyFTS.models.multivariate'], 'pyFTS.tests', 'pyFTS.models.nonstationary', 'pyFTS.models.multivariate'],
#package_dir={} version='1.2.3',
#package_data={'pyFTS.data': ['*.csv','*.csv.bz2']},
#data_files=[('data', ['pyFTS/data/Enrollments.csv', 'pyFTS/data/AirPassengers.csv'])],
#include_package_data=True,
version='1.2.2',
description='Fuzzy Time Series for Python', description='Fuzzy Time Series for Python',
author='Petronio Candido L. e Silva', author='Petronio Candido L. e Silva',
author_email='petronio.candido@gmail.com', author_email='petronio.candido@gmail.com',
url='https://github.com/petroniocandido/pyFTS', url='https://pyfts.github.io/pyFTS/',
download_url='https://github.com/petroniocandido/pyFTS/archive/pkg1.2.3.tar.gz', download_url='https://github.com/PYFTS/pyFTS/archive/docSphinx.tar.gz',
keywords=['forecasting', 'fuzzy time series', 'fuzzy', 'time series forecasting'], keywords=['forecasting', 'fuzzy time series', 'fuzzy', 'time series forecasting'],
classifiers=[ classifiers=[
'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3',
@ -22,4 +18,5 @@ setup(
'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.6',
], ],
install_requires=['dill'],
) )