Single partitioner; documentation update

This commit is contained in:
Petrônio Cândido 2018-12-12 19:35:02 -02:00
parent 358a6ea287
commit 2e186605f7
26 changed files with 243 additions and 50 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -101,12 +101,18 @@
<span class="sd">&quot;&quot;&quot;In multivariate time series, indicate for which variable this fuzzy set belogs&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">Z</span> <span class="o">=</span> <span class="kc">None</span>
<span class="sd">&quot;&quot;&quot;Partition function in respect to the membership function&quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</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="bp">self</span><span class="o">.</span><span class="n">lower</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">parameters</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">upper</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">parameters</span><span class="p">)</span>
<span class="k">elif</span> <span class="bp">self</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">if</span> <span class="bp">self</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="bp">self</span><span class="o">.</span><span class="n">lower</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="o">-</span> <span class="n">parameters</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="mi">3</span>
<span class="bp">self</span><span class="o">.</span><span class="n">upper</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="o">+</span> <span class="n">parameters</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="mi">3</span>
<span class="k">elif</span> <span class="bp">self</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">sigmf</span><span class="p">:</span>
<span class="n">k</span> <span class="o">=</span> <span class="p">(</span><span class="n">parameters</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">/</span> <span class="p">(</span><span class="mi">2</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="bp">self</span><span class="o">.</span><span class="n">lower</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="o">-</span> <span class="n">k</span>
<span class="bp">self</span><span class="o">.</span><span class="n">upper</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="o">+</span> <span class="n">k</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">lower</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">parameters</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">upper</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">parameters</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">metadata</span> <span class="o">=</span> <span class="p">{}</span>
<div class="viewcode-block" id="FuzzySet.transform"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.FuzzySet.FuzzySet.transform">[docs]</a> <span class="k">def</span> <span class="nf">transform</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>

View File

@ -161,7 +161,7 @@
<span class="sd"> :param parameters: a list with one real value</span>
<span class="sd"> :returns</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">x</span> <span class="o">==</span> <span class="n">parameters</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></div>
<span class="k">return</span> <span class="mi">1</span> <span class="k">if</span> <span class="n">x</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="k">else</span> <span class="mi">0</span></div>
</pre></div>
</div>

View File

@ -178,8 +178,12 @@
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">upper</span></div>
<span class="k">def</span> <span class="nf">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div>
<span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span>
<div class="viewcode-block" id="FLRG.reset_calculated_values"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.flrg.FLRG.reset_calculated_values">[docs]</a> <span class="k">def</span> <span class="nf">reset_calculated_values</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">midpoint</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">upper</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">lower</span> <span class="o">=</span> <span class="kc">None</span></div></div>
</pre></div>

View File

@ -581,8 +581,22 @@
<span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">)</span>
<div class="viewcode-block" id="FTS.len_total"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.len_total">[docs]</a> <span class="k">def</span> <span class="nf">len_total</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="nb">sum</span><span class="p">([</span><span class="nb">len</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">])</span></div></div>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Total length of the model, adding the number of terms in all rules</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="nb">sum</span><span class="p">([</span><span class="nb">len</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">])</span></div>
<div class="viewcode-block" id="FTS.reset_calculated_values"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.fts.FTS.reset_calculated_values">[docs]</a> <span class="k">def</span> <span class="nf">reset_calculated_values</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Reset all pre-calculated values on the FLRG&#39;s</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">for</span> <span class="n">flrg</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="p">]</span><span class="o">.</span><span class="n">reset_calculated_values</span><span class="p">()</span></div></div>

View File

@ -156,11 +156,15 @@
<span class="n">ret</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">var</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">explanatory_variables</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cluster</span><span class="o">.</span><span class="n">change_target_variable</span><span class="p">(</span><span class="n">var</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">name</span> <span class="o">!=</span> <span class="n">var</span><span class="o">.</span><span class="n">name</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span> <span class="o">=</span> <span class="n">var</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cluster</span><span class="o">.</span><span class="n">change_target_variable</span><span class="p">(</span><span class="n">var</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">partitioner</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cluster</span>
<span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">reset_calculated_values</span><span class="p">()</span>
<span class="n">ret</span><span class="p">[</span><span class="n">var</span><span class="o">.</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">forecast</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">fuzzyfied</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">pre_fuzzyfy</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">columns</span> <span class="o">=</span> <span class="n">ret</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
<span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">ret</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="n">columns</span><span class="p">)</span></div>
<span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">ret</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="n">ret</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span></div>
<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;String representation of the model&quot;&quot;&quot;</span>

View File

@ -102,6 +102,12 @@
<span class="k">if</span> <span class="n">variable</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span><span class="o">.</span><span class="n">name</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">centroid</span> <span class="o">=</span> <span class="nb">set</span><span class="o">.</span><span class="n">centroid</span></div>
<div class="viewcode-block" id="MultivariateFuzzySet.set_target_variable"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.common.MultivariateFuzzySet.set_target_variable">[docs]</a> <span class="k">def</span> <span class="nf">set_target_variable</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">variable</span><span class="p">):</span>
<span class="c1">#print(self.target_variable, variable)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">target_variable</span> <span class="o">=</span> <span class="n">variable</span>
<span class="c1">#print(self.centroid,self.sets[variable.name].centroid)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">centroid</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">variable</span><span class="o">.</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span></div>
<div class="viewcode-block" id="MultivariateFuzzySet.membership"><a class="viewcode-back" href="../../../../pyFTS.models.multivariate.html#pyFTS.models.multivariate.common.MultivariateFuzzySet.membership">[docs]</a> <span class="k">def</span> <span class="nf">membership</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
<span class="n">mv</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">var</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>

View File

@ -276,18 +276,18 @@
<span class="c1">#return self.flrg_lhs_unconditional_probability(flrg)</span>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.flrg_lhs_conditional_probability"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.flrg_lhs_conditional_probability">[docs]</a> <span class="k">def</span> <span class="nf">flrg_lhs_conditional_probability</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">flrg</span><span class="p">):</span>
<span class="n">mv</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_membership</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">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">x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">pb</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrg_lhs_unconditional_probability</span><span class="p">(</span><span class="n">flrg</span><span class="p">)</span>
<span class="k">return</span> <span class="n">mv</span> <span class="o">*</span> <span class="n">pb</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.get_midpoint"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.get_midpoint">[docs]</a> <span class="k">def</span> <span class="nf">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrg</span><span class="p">):</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">tmp</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span> <span class="c1">#sum(np.array([tmp.rhs_unconditional_probability(s) * self.setsDict[s].centroid for s in tmp.RHS]))</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">tmp</span><span class="o">.</span><span class="n">get_midpoint</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span> <span class="c1">#sum(np.array([tmp.rhs_unconditional_probability(s) * self.setsDict[s].centroid for s in tmp.RHS]))</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">pi</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="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">centroid</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">]))</span>
<span class="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">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">]))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>
<span class="k">return</span> <span class="n">ret</span></div>
@ -298,19 +298,19 @@
<span class="n">_flrg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span>
<span class="n">cond</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">_flrg</span><span class="o">.</span><span class="n">RHS</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="n">_set</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span>
<span class="n">_set</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">_flrg</span><span class="o">.</span><span class="n">rhs_unconditional_probability</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">_set</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">/</span> <span class="n">_set</span><span class="o">.</span><span class="n">partition_function</span><span class="p">(</span><span class="n">uod</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">get_UoD</span><span class="p">()))</span>
<span class="n">cond</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="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="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">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">flrg</span><span class="o">.</span><span class="n">LHS</span><span class="p">]))</span>
<span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="ProbabilisticWeightedFTS.get_upper"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.get_upper">[docs]</a> <span class="k">def</span> <span class="nf">get_upper</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrg</span><span class="p">):</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">tmp</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">tmp</span><span class="o">.</span><span class="n">get_upper</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">return</span> <span class="n">ret</span></div>
@ -318,7 +318,7 @@
<div class="viewcode-block" id="ProbabilisticWeightedFTS.get_lower"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.pwfts.ProbabilisticWeightedFTS.get_lower">[docs]</a> <span class="k">def</span> <span class="nf">get_lower</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flrg</span><span class="p">):</span>
<span class="k">if</span> <span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flrg</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">tmp</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">tmp</span><span class="o">.</span><span class="n">get_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">return</span> <span class="n">ret</span></div>
@ -472,8 +472,8 @@
<span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">flrgs</span><span class="p">:</span>
<span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">get_key</span><span class="p">()</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">:</span>
<span class="n">flrg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">get_key</span><span class="p">()]</span>
<span class="n">pk</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">lhs_conditional_probability</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">global_frequency_count</span><span class="p">,</span> <span class="n">uod</span><span class="p">,</span> <span class="n">nbins</span><span class="p">)</span>
<span class="n">wi</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">rhs_conditional_probability</span><span class="p">(</span><span class="nb">bin</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">uod</span><span class="p">,</span> <span class="n">nbins</span><span class="p">)</span>
<span class="n">pk</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">lhs_conditional_probability</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">global_frequency_count</span><span class="p">,</span> <span class="n">uod</span><span class="p">,</span> <span class="n">nbins</span><span class="p">)</span>
<span class="n">wi</span> <span class="o">=</span> <span class="n">flrg</span><span class="o">.</span><span class="n">rhs_conditional_probability</span><span class="p">(</span><span class="nb">bin</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">uod</span><span class="p">,</span> <span class="n">nbins</span><span class="p">)</span>
<span class="n">num</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">wi</span> <span class="o">*</span> <span class="n">pk</span><span class="p">)</span>
<span class="n">den</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pk</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>

View File

@ -107,6 +107,7 @@
<span class="bp">self</span><span class="o">.</span><span class="n">extractor</span> <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;extractor&#39;</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;Anonymous function used to extract a single primitive type from an object instance&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ordered_sets</span> <span class="o">=</span> <span class="kc">None</span>
<span class="sd">&quot;&quot;&quot;A ordered list of the fuzzy sets names, sorted by their middle point&quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;preprocess&#39;</span><span class="p">,</span><span class="kc">True</span><span class="p">):</span>
@ -188,7 +189,7 @@
<span class="sd"> :param ax: Matplotlib axis</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_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="mf">1.1</span><span class="p">])</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">min</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">max</span><span class="p">])</span>
<span class="n">ticks</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">x</span> <span class="o">=</span> <span class="p">[]</span>
@ -213,12 +214,14 @@
<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="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="n">tmpx</span> <span class="o">=</span> <span class="p">[</span><span class="n">kk</span> <span class="k">for</span> <span class="n">kk</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">lower</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">upper</span><span class="p">)]</span>
<span class="n">tmpy</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">kk</span><span class="p">)</span> <span class="k">for</span> <span class="n">kk</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">lower</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">upper</span><span class="p">)]</span>
<span class="k">elif</span> <span class="n">s</span><span class="o">.</span><span class="n">mf</span> <span class="ow">in</span> <span class="p">(</span><span class="n">Membership</span><span class="o">.</span><span class="n">gaussmf</span><span class="p">,</span> <span class="n">Membership</span><span class="o">.</span><span class="n">bellmf</span><span class="p">,</span> <span class="n">Membership</span><span class="o">.</span><span class="n">sigmf</span><span class="p">):</span>
<span class="n">tmpx</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">lower</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">upper</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
<span class="n">tmpy</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">membership</span><span class="p">(</span><span class="n">kk</span><span class="p">)</span> <span class="k">for</span> <span class="n">kk</span> <span class="ow">in</span> <span class="n">tmpx</span><span class="p">]</span>
<span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">tmpx</span><span class="p">,</span> <span class="n">tmpy</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">s</span><span class="o">.</span><span class="n">mf</span> <span class="o">==</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trapmf</span><span class="p">:</span>
<span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">parameters</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="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>
<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">singleton</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">0</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></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="sd">&quot;&quot;&quot;</span>

View File

@ -67,6 +67,14 @@ pyFTS.partitioners.Singleton module
:members:
:undoc-members:
:show-inheritance:
pyFTS.partitioners.Simple module
--------------------------------
.. automodule:: pyFTS.partitioners.Sinple
:members:
:undoc-members:
:show-inheritance:
pyFTS.partitioners.Util module

View File

@ -1320,14 +1320,16 @@
</li>
<li><a href="pyFTS.models.html#pyFTS.models.song.ConventionalFTS.operation_matrix">operation_matrix() (pyFTS.models.song.ConventionalFTS method)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="pyFTS.common.html#pyFTS.common.flrg.FLRG.order">order (pyFTS.common.flrg.FLRG attribute)</a>
<ul>
<li><a href="pyFTS.common.html#pyFTS.common.fts.FTS.order">(pyFTS.common.fts.FTS attribute)</a>
</li>
</ul></li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="pyFTS.partitioners.html#pyFTS.partitioners.partitioner.Partitioner.ordered_sets">ordered_sets (pyFTS.partitioners.partitioner.Partitioner attribute)</a>
</li>
<li><a href="pyFTS.common.html#pyFTS.common.fts.FTS.original_max">original_max (pyFTS.common.fts.FTS attribute)</a>
</li>
<li><a href="pyFTS.common.html#pyFTS.common.fts.FTS.original_min">original_min (pyFTS.common.fts.FTS attribute)</a>
@ -1728,6 +1730,12 @@
</li>
<li><a href="pyFTS.common.html#pyFTS.common.SortedCollection.SortedCollection.remove">remove() (pyFTS.common.SortedCollection.SortedCollection method)</a>
</li>
<li><a href="pyFTS.common.html#pyFTS.common.flrg.FLRG.reset_calculated_values">reset_calculated_values() (pyFTS.common.flrg.FLRG method)</a>
<ul>
<li><a href="pyFTS.common.html#pyFTS.common.fts.FTS.reset_calculated_values">(pyFTS.common.fts.FTS method)</a>
</li>
</ul></li>
<li><a href="pyFTS.benchmarks.html#pyFTS.benchmarks.ResidualAnalysis.residuals">residuals() (in module pyFTS.benchmarks.ResidualAnalysis)</a>
</li>
<li><a href="pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.resolution">resolution() (in module pyFTS.benchmarks.Measures)</a>
@ -1817,6 +1825,8 @@
<li><a href="pyFTS.common.html#pyFTS.common.FuzzySet.set_ordered">set_ordered() (in module pyFTS.common.FuzzySet)</a>
</li>
<li><a href="pyFTS.models.multivariate.html#pyFTS.models.multivariate.FLR.FLR.set_rhs">set_rhs() (pyFTS.models.multivariate.FLR.FLR method)</a>
</li>
<li><a href="pyFTS.models.multivariate.html#pyFTS.models.multivariate.common.MultivariateFuzzySet.set_target_variable">set_target_variable() (pyFTS.models.multivariate.common.MultivariateFuzzySet method)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>

Binary file not shown.

View File

@ -1451,6 +1451,11 @@ when the LHS pattern is identified on time t.</p>
<dd><p>Number of lags on LHS</p>
</dd></dl>
<dl class="method">
<dt id="pyFTS.common.flrg.FLRG.reset_calculated_values">
<code class="descname">reset_calculated_values</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/flrg.html#FLRG.reset_calculated_values"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.flrg.FLRG.reset_calculated_values" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
</div>
@ -1818,7 +1823,16 @@ when the LHS pattern is identified on time t.</p>
<dl class="method">
<dt id="pyFTS.common.fts.FTS.len_total">
<code class="descname">len_total</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.len_total"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.len_total" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dd><p>Total length of the model, adding the number of terms in all rules</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"></td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="attribute">
<dt id="pyFTS.common.fts.FTS.max_lag">
@ -1908,6 +1922,20 @@ accept one value (the actual value of the variable) and return the next value.</
</table>
</dd></dl>
<dl class="method">
<dt id="pyFTS.common.fts.FTS.reset_calculated_values">
<code class="descname">reset_calculated_values</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/common/fts.html#FTS.reset_calculated_values"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.common.fts.FTS.reset_calculated_values" title="Permalink to this definition"></a></dt>
<dd><p>Reset all pre-calculated values on the FLRGs</p>
<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"></td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="attribute">
<dt id="pyFTS.common.fts.FTS.sets">
<code class="descname">sets</code><em class="property"> = None</em><a class="headerlink" href="#pyFTS.common.fts.FTS.sets" title="Permalink to this definition"></a></dt>

View File

@ -249,6 +249,7 @@
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.Grid">pyFTS.partitioners.Grid module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.Huarng">pyFTS.partitioners.Huarng module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.Singleton">pyFTS.partitioners.Singleton module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#pyfts-partitioners-simple-module">pyFTS.partitioners.Simple module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.Util">pyFTS.partitioners.Util module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.parallel_util">pyFTS.partitioners.parallel_util module</a></li>
</ul>

View File

@ -180,6 +180,11 @@
</table>
</dd></dl>
<dl class="method">
<dt id="pyFTS.models.multivariate.common.MultivariateFuzzySet.set_target_variable">
<code class="descname">set_target_variable</code><span class="sig-paren">(</span><em>variable</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/models/multivariate/common.html#MultivariateFuzzySet.set_target_variable"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.models.multivariate.common.MultivariateFuzzySet.set_target_variable" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
<dl class="function">

View File

@ -72,6 +72,7 @@
<li><a class="reference internal" href="#module-pyFTS.partitioners.Grid">pyFTS.partitioners.Grid module</a></li>
<li><a class="reference internal" href="#module-pyFTS.partitioners.Huarng">pyFTS.partitioners.Huarng module</a></li>
<li><a class="reference internal" href="#module-pyFTS.partitioners.Singleton">pyFTS.partitioners.Singleton module</a></li>
<li><a class="reference internal" href="#pyfts-partitioners-simple-module">pyFTS.partitioners.Simple module</a></li>
<li><a class="reference internal" href="#module-pyFTS.partitioners.Util">pyFTS.partitioners.Util module</a></li>
<li><a class="reference internal" href="#module-pyFTS.partitioners.parallel_util">pyFTS.partitioners.parallel_util module</a></li>
</ul>
@ -196,6 +197,12 @@
<dd><p>partitioner name</p>
</dd></dl>
<dl class="attribute">
<dt id="pyFTS.partitioners.partitioner.Partitioner.ordered_sets">
<code class="descname">ordered_sets</code><em class="property"> = None</em><a class="headerlink" href="#pyFTS.partitioners.partitioner.Partitioner.ordered_sets" title="Permalink to this definition"></a></dt>
<dd><p>A ordered list of the fuzzy sets names, sorted by their middle point</p>
</dd></dl>
<dl class="attribute">
<dt id="pyFTS.partitioners.partitioner.Partitioner.partitions">
<code class="descname">partitions</code><em class="property"> = None</em><a class="headerlink" href="#pyFTS.partitioners.partitioner.Partitioner.partitions" title="Permalink to this definition"></a></dt>
@ -497,6 +504,9 @@ Fuzzy Sets Syst., vol. 123, no. 3, pp. 387394, Nov. 2001.</p>
</dd></dl>
</div>
<div class="section" id="pyfts-partitioners-simple-module">
<h2>pyFTS.partitioners.Simple module<a class="headerlink" href="#pyfts-partitioners-simple-module" title="Permalink to this headline"></a></h2>
</div>
<div class="section" id="module-pyFTS.partitioners.Util">
<span id="pyfts-partitioners-util-module"></span><h2>pyFTS.partitioners.Util module<a class="headerlink" href="#module-pyFTS.partitioners.Util" title="Permalink to this headline"></a></h2>

File diff suppressed because one or more lines are too long

View File

@ -67,6 +67,14 @@ pyFTS.partitioners.Singleton module
:members:
:undoc-members:
:show-inheritance:
pyFTS.partitioners.Simple module
--------------------------------
.. automodule:: pyFTS.partitioners.Sinple
:members:
:undoc-members:
:show-inheritance:
pyFTS.partitioners.Util module

View File

@ -27,12 +27,18 @@ class FuzzySet(object):
"""In multivariate time series, indicate for which variable this fuzzy set belogs"""
self.Z = None
"""Partition function in respect to the membership function"""
if self.mf == Membership.trimf:
self.lower = min(parameters)
self.upper = max(parameters)
elif self.mf == Membership.gaussmf:
if self.mf == Membership.gaussmf:
self.lower = parameters[0] - parameters[1]*3
self.upper = parameters[0] + parameters[1]*3
elif self.mf == Membership.sigmf:
k = (parameters[1] / (2 * parameters[0]))
self.lower = parameters[1] - k
self.upper = parameters[1] + k
else:
self.lower = min(parameters)
self.upper = max(parameters)
self.metadata = {}
def transform(self, x):

View File

@ -87,4 +87,4 @@ def singleton(x, parameters):
:param parameters: a list with one real value
:returns
"""
return x == parameters[0]
return 1 if x == parameters[0] else 0

View File

@ -0,0 +1,78 @@
"""Simple Partitioner for manually informed fuzzy sets"""
import numpy as np
import math
import random as rnd
import functools, operator
from pyFTS.common import FuzzySet, Membership
from pyFTS.partitioners import partitioner
class SimplePartitioner(partitioner.Partitioner):
"""Simple Partitioner for manually informed fuzzy sets"""
def __init__(self, **kwargs):
"""
Simple Partitioner - the fuzzy sets are informed manually
"""
kwargs['preprocess'] = False
super(SimplePartitioner, self).__init__(name="Simple", **kwargs)
self.partitions = 0
def append(self, name, mf, parameters, **kwargs):
"""
Append a new partition (fuzzy set) to the partitioner
:param name: Fuzzy set name
:param mf: One of the pyFTS.common.Membership functions
:param parameters: A list with the parameters for the membership function
:param kwargs: Optional arguments for the fuzzy set
"""
if name is None or len(name) == 0:
raise ValueError("The name of the fuzzy set cannot be empty")
if name in self.sets:
raise ValueError("This name has already been used")
if mf is None or mf not in (Membership.trimf, Membership.gaussmf,
Membership.trapmf, Membership.singleton,
Membership.sigmf):
raise ValueError("The mf parameter should be one of pyFTS.common.Membership functions")
if mf == Membership.trimf:
if len(parameters) != 3:
raise ValueError("Incorrect number of parameters for the Membership.trimf")
centroid = parameters[1]
elif mf == Membership.gaussmf:
if len(parameters) != 2:
raise ValueError("Incorrect number of parameters for the Membership.gaussmf")
centroid = parameters[0]
elif mf == Membership.trapmf:
if len(parameters) != 4:
raise ValueError("Incorrect number of parameters for the Membership.trapmf")
centroid = (parameters[1]+parameters[2])/2
elif mf == Membership.singleton:
if len(parameters) != 1:
raise ValueError("Incorrect number of parameters for the Membership.singleton")
centroid = parameters[0]
elif mf == Membership.sigmf:
if len(parameters) != 2:
raise ValueError("Incorrect number of parameters for the Membership.sigmf")
centroid = parameters[1] + (parameters[1] / (2 * parameters[0]))
self.sets[name] = FuzzySet.FuzzySet(name, mf, parameters, centroid, **kwargs)
self.partitions += 1
self.ordered_sets = [key for key in sorted(self.sets.keys(), key=lambda k: self.sets[k].centroid)]
self.min = self.sets[self.ordered_sets[0]].lower
self.max = self.sets[self.ordered_sets[-1]].upper

View File

@ -33,6 +33,7 @@ class Partitioner(object):
self.extractor = kwargs.get('extractor', lambda x: x)
"""Anonymous function used to extract a single primitive type from an object instance"""
self.ordered_sets = None
"""A ordered list of the fuzzy sets names, sorted by their middle point"""
if kwargs.get('preprocess',True):
@ -114,7 +115,7 @@ class Partitioner(object):
:param ax: Matplotlib axis
"""
ax.set_title(self.name)
ax.set_ylim([0, 1])
ax.set_ylim([0, 1.1])
ax.set_xlim([self.min, self.max])
ticks = []
x = []
@ -139,12 +140,14 @@ class Partitioner(object):
"""
if s.mf == Membership.trimf:
ax.plot([s.parameters[0], s.parameters[1], s.parameters[2]], [0, s.alpha, 0])
elif s.mf == Membership.gaussmf:
tmpx = [kk for kk in np.arange(s.lower, s.upper)]
tmpy = [s.membership(kk) for kk in np.arange(s.lower, s.upper)]
elif s.mf in (Membership.gaussmf, Membership.bellmf, Membership.sigmf):
tmpx = np.linspace(s.lower, s.upper, 100)
tmpy = [s.membership(kk) for kk in tmpx]
ax.plot(tmpx, tmpy)
elif s.mf == Membership.trapmf:
ax.plot(s.parameters, [0, s.alpha, s.alpha, 0])
elif s.mf == Membership.singleton:
ax.plot([s.parameters[0],s.parameters[0]], [0, s.alpha])
def __str__(self):
"""

View File

@ -9,32 +9,31 @@ import matplotlib.pylab as plt
import pandas as pd
from pyFTS.common import Util as cUtil, FuzzySet
from pyFTS.partitioners import Grid, Entropy, Util as pUtil
from pyFTS.partitioners import Grid, Entropy, Util as pUtil, Simple
from pyFTS.benchmarks import benchmarks as bchmk, Measures
from pyFTS.models import chen, yu, cheng, ismailefendi, hofts, pwfts
from pyFTS.common import Transformations
from pyFTS.common import Transformations, Membership
tdiff = Transformations.Differential(1)
from pyFTS.data import TAIEX, SP500, NASDAQ, Malaysia, Enrollments
train_split = 2000
test_length = 200
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=[15,7])
dataset = TAIEX.get_data()
partitioner = Grid.GridPartitioner(data=dataset[:train_split], npart=35)
partitioner_diff = Grid.GridPartitioner(data=dataset[:train_split], npart=5, transformation=tdiff)
fs = Simple.SimplePartitioner()
pfts1_taiex = pwfts.ProbabilisticWeightedFTS(partitioner=partitioner)
pfts1_taiex.fit(dataset[:train_split], save_model=True, file_path='pwfts', order=1)
pfts1_taiex.shortname = "1st Order"
#print(pfts1_taiex)
fs.append("A", Membership.trimf, [0,1,2])
fs.append("B", Membership.trapmf, [1,2,3,4])
fs.append("C", Membership.gaussmf, [5,1])
fs.append("D", Membership.singleton, [8])
fs.append("E", Membership.sigmf, [2, 10])
#tmp = pfts1_taiex.predict(dataset[train_split:train_split+200], type='distribution')
fs.plot(ax)
print(fs)
tmp = pfts1_taiex.predict(dataset[train_split:train_split+200], type='distribution', steps_ahead=20)
'''
#dataset = SP500.get_data()[11500:16000]