Compare commits

..

No commits in common. "master" and "classification" have entirely different histories.

28 changed files with 64 additions and 258 deletions

57
.gitignore vendored
View File

@ -1,57 +0,0 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/

View File

@ -104,7 +104,7 @@ pyFTS/models/seasonal/common.py
pyFTS/models/seasonal/msfts.py
pyFTS/models/seasonal/partitioner.py
pyFTS/models/seasonal/sfts.py
pyFTS/partitioners/KMeans.py
pyFTS/partitioners/CMeans.py
pyFTS/partitioners/Entropy.py
pyFTS/partitioners/FCM.py
pyFTS/partitioners/Grid.py

View File

@ -38,7 +38,7 @@ Fuzzy Time Series (FTS) are non parametric methods for time series forecasting b
2. **Universe of Discourse Partitioning**: This is the most important step. Here, the range of values of the numerical time series *Y(t)* will be splited in overlapped intervals and for each interval will be created a Fuzzy Set. This step is performed by pyFTS.partition module and its classes (for instance GridPartitioner, EntropyPartitioner, etc). The main parameters are:
- the number of intervals
- which fuzzy membership function (on [pyFTS.common.Membership](https://github.com/PYFTS/pyFTS/blob/master/pyFTS/common/Membership.py))
- partition scheme ([GridPartitioner](https://github.com/PYFTS/pyFTS/blob/master/pyFTS/partitioners/Grid.py), [EntropyPartitioner](https://github.com/PYFTS/pyFTS/blob/master/pyFTS/partitioners/Entropy.py)[3], [FCMPartitioner](https://github.com/PYFTS/pyFTS/blob/master/pyFTS/partitioners/FCM.py), [KMeansPartitioner](https://github.com/PYFTS/pyFTS/blob/master/pyFTS/partitioners/KMeans.py), [HuarngPartitioner](https://github.com/PYFTS/pyFTS/blob/master/pyFTS/partitioners/Huarng.py)[4])
- partition scheme ([GridPartitioner](https://github.com/PYFTS/pyFTS/blob/master/pyFTS/partitioners/Grid.py), [EntropyPartitioner](https://github.com/PYFTS/pyFTS/blob/master/pyFTS/partitioners/Entropy.py)[3], [FCMPartitioner](https://github.com/PYFTS/pyFTS/blob/master/pyFTS/partitioners/FCM.py), [CMeansPartitioner](https://github.com/PYFTS/pyFTS/blob/master/pyFTS/partitioners/CMeans.py), [HuarngPartitioner](https://github.com/PYFTS/pyFTS/blob/master/pyFTS/partitioners/Huarng.py)[4])
Check out the jupyter notebook on [notebooks/Partitioners.ipynb](https://github.com/PYFTS/notebooks/blob/master/Partitioners.ipynb) for sample codes.

Binary file not shown.

Binary file not shown.

View File

@ -94,7 +94,7 @@
<li><a href="pyFTS/models/seasonal/common.html">pyFTS.models.seasonal.common</a></li>
<li><a href="pyFTS/models/seasonal/partitioner.html">pyFTS.models.seasonal.partitioner</a></li>
<li><a href="pyFTS/partitioners/CMeans.html">pyFTS.partitioners.CMeans</a></li>
<li><a href="pyFTS/partitioners/Class.html">pyFTS.partitioners.Class</a></li>
<li><a href="pyFTS/partitioners/ClassPartitioner.html">pyFTS.partitioners.ClassPartitioner</a></li>
<li><a href="pyFTS/partitioners/Entropy.html">pyFTS.partitioners.Entropy</a></li>
<li><a href="pyFTS/partitioners/FCM.html">pyFTS.partitioners.FCM</a></li>
<li><a href="pyFTS/partitioners/Grid.html">pyFTS.partitioners.Grid</a></li>

View File

@ -1,126 +0,0 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>pyFTS.partitioners.Class &#8212; pyFTS 1.7 documentation</title>
<link rel="stylesheet" type="text/css" href="../../../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../../../_static/bizstyle.css" />
<script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/bizstyle.js"></script>
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<!--[if lt IE 9]>
<script src="_static/css3-mediaqueries.js"></script>
<![endif]-->
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.7 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.partitioners.Class</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.partitioners.Class</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;Class Partitioner with Singleton Fuzzy Sets&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">math</span>
<span class="kn">import</span> <span class="nn">random</span> <span class="k">as</span> <span class="nn">rnd</span>
<span class="kn">import</span> <span class="nn">functools</span><span class="o">,</span> <span class="nn">operator</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="kn">import</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">Membership</span>
<span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="kn">import</span> <span class="n">partitioner</span>
<div class="viewcode-block" id="ClassPartitioner"><a class="viewcode-back" href="../../../pyFTS.partitioners.html#pyFTS.partitioners.Class.ClassPartitioner">[docs]</a><span class="k">class</span> <span class="nc">ClassPartitioner</span><span class="p">(</span><span class="n">partitioner</span><span class="o">.</span><span class="n">Partitioner</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Class Partitioner: Given a dictionary with class/values pairs, create singleton fuzzy sets for each class&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Class Partitioner</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="nb">super</span><span class="p">(</span><span class="n">ClassPartitioner</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;Class&quot;</span><span class="p">,</span> <span class="n">preprocess</span> <span class="o">=</span> <span class="kc">False</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ordered_sets</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min</span> <span class="o">=</span> <span class="mi">0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max</span> <span class="o">=</span> <span class="mi">0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitions</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">classes</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;classes&quot;</span><span class="p">,</span> <span class="p">{})</span>
<span class="k">for</span> <span class="n">k</span><span class="p">,</span><span class="n">v</span> <span class="ow">in</span> <span class="n">classes</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min</span> <span class="o">=</span> <span class="nb">min</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">min</span><span class="p">,</span> <span class="n">v</span><span class="p">])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">max</span> <span class="o">=</span> <span class="nb">max</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">max</span><span class="p">,</span> <span class="n">v</span><span class="p">])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partitions</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">FuzzySet</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">Membership</span><span class="o">.</span><span class="n">singleton</span><span class="p">,</span> <span class="p">[</span><span class="n">v</span><span class="p">],</span> <span class="n">v</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ordered_sets</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
<div class="viewcode-block" id="ClassPartitioner.build"><a class="viewcode-back" href="../../../pyFTS.partitioners.html#pyFTS.partitioners.Class.ClassPartitioner.build">[docs]</a> <span class="k">def</span> <span class="nf">build</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span> <span class="p">:</span> <span class="nb">list</span><span class="p">):</span>
<span class="k">pass</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../../../index.html">
<img class="logo" src="../../../_static/logo_heading2.png" alt="Logo"/>
</a></p>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.7 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.partitioners.Class</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2022, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.3.2.
</div>
</body>
</html>

View File

@ -20,10 +20,10 @@ pyFTS.partitioners.partitioner module
:undoc-members:
:show-inheritance:
pyFTS.partitioners.Class module
-------------------------------
pyFTS.partitioners.ClassPartitioner module
-----------------------------------
.. automodule:: pyFTS.partitioners.Class
.. automodule:: pyFTS.partitioners.ClassPartitioner
:members:
:undoc-members:
:show-inheritance:

View File

@ -159,7 +159,7 @@
</li>
<li><a href="pyFTS.models.seasonal.html#pyFTS.models.seasonal.partitioner.TimeGridPartitioner.build">(pyFTS.models.seasonal.partitioner.TimeGridPartitioner method)</a>
</li>
<li><a href="pyFTS.partitioners.html#pyFTS.partitioners.Class.ClassPartitioner.build">(pyFTS.partitioners.Class.ClassPartitioner method)</a>
<li><a href="pyFTS.partitioners.html#pyFTS.partitioners.ClassPartitioner.ClassPartitioner.build">(pyFTS.partitioners.ClassPartitioner.ClassPartitioner method)</a>
</li>
<li><a href="pyFTS.partitioners.html#pyFTS.partitioners.CMeans.CMeansPartitioner.build">(pyFTS.partitioners.CMeans.CMeansPartitioner method)</a>
</li>
@ -216,7 +216,7 @@
</ul></li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="pyFTS.partitioners.html#pyFTS.partitioners.Class.ClassPartitioner">ClassPartitioner (class in pyFTS.partitioners.Class)</a>
<li><a href="pyFTS.partitioners.html#pyFTS.partitioners.ClassPartitioner.ClassPartitioner">ClassPartitioner (class in pyFTS.partitioners.ClassPartitioner)</a>
</li>
<li><a href="pyFTS.common.html#pyFTS.common.SortedCollection.SortedCollection.clear">clear() (pyFTS.common.SortedCollection.SortedCollection method)</a>
</li>
@ -876,7 +876,7 @@
</li>
<li><a href="pyFTS.partitioners.html#module-pyFTS.partitioners">pyFTS.partitioners</a>
</li>
<li><a href="pyFTS.partitioners.html#module-pyFTS.partitioners.Class">pyFTS.partitioners.Class</a>
<li><a href="pyFTS.partitioners.html#module-pyFTS.partitioners.ClassPartitioner">pyFTS.partitioners.ClassPartitioner</a>
</li>
<li><a href="pyFTS.partitioners.html#module-pyFTS.partitioners.CMeans">pyFTS.partitioners.CMeans</a>
</li>
@ -1468,10 +1468,10 @@
</li>
</ul></li>
<li>
pyFTS.partitioners.Class
pyFTS.partitioners.ClassPartitioner
<ul>
<li><a href="pyFTS.partitioners.html#module-pyFTS.partitioners.Class">module</a>
<li><a href="pyFTS.partitioners.html#module-pyFTS.partitioners.ClassPartitioner">module</a>
</li>
</ul></li>
<li>

Binary file not shown.

View File

@ -389,7 +389,7 @@
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="pyFTS.partitioners.html#module-pyFTS.partitioners.Class"><code class="xref">pyFTS.partitioners.Class</code></a></td><td>
<a href="pyFTS.partitioners.html#module-pyFTS.partitioners.ClassPartitioner"><code class="xref">pyFTS.partitioners.ClassPartitioner</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>

View File

@ -221,7 +221,7 @@
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners">Module contents</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#submodules">Submodules</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.partitioner">pyFTS.partitioners.partitioner module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.Class">pyFTS.partitioners.Class module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#pyfts-partitioners-classpartitioner-module">pyFTS.partitioners.ClassPartitioner module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.CMeans">pyFTS.partitioners.CMeans module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.Entropy">pyFTS.partitioners.Entropy module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.FCM">pyFTS.partitioners.FCM module</a></li>

View File

@ -299,17 +299,17 @@ overlapped fuzzy sets.</p>
</dd></dl>
</section>
<section id="module-pyFTS.partitioners.Class">
<span id="pyfts-partitioners-class-module"></span><h2>pyFTS.partitioners.Class module<a class="headerlink" href="#module-pyFTS.partitioners.Class" title="Permalink to this headline"></a></h2>
<p>Class Partitioner with Singleton Fuzzy Sets</p>
<section id="pyfts-partitioners-classpartitioner-module">
<h2>pyFTS.partitioners.ClassPartitioner module<a class="headerlink" href="#pyfts-partitioners-classpartitioner-module" title="Permalink to this headline"></a></h2>
<span class="target" id="module-pyFTS.partitioners.ClassPartitioner"></span><p>Class Partitioner with Singleton Fuzzy Sets</p>
<dl class="py class">
<dt class="sig sig-object py" id="pyFTS.partitioners.Class.ClassPartitioner">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pyFTS.partitioners.Class.</span></span><span class="sig-name descname"><span class="pre">ClassPartitioner</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/Class.html#ClassPartitioner"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pyFTS.partitioners.Class.ClassPartitioner" title="Permalink to this definition"></a></dt>
<dt class="sig sig-object py" id="pyFTS.partitioners.ClassPartitioner.ClassPartitioner">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pyFTS.partitioners.ClassPartitioner.</span></span><span class="sig-name descname"><span class="pre">ClassPartitioner</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/ClassPartitioner.html#ClassPartitioner"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pyFTS.partitioners.ClassPartitioner.ClassPartitioner" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#pyFTS.partitioners.partitioner.Partitioner" title="pyFTS.partitioners.partitioner.Partitioner"><code class="xref py py-class docutils literal notranslate"><span class="pre">pyFTS.partitioners.partitioner.Partitioner</span></code></a></p>
<p>Class Partitioner: Given a dictionary with class/values pairs, create singleton fuzzy sets for each class</p>
<dl class="py method">
<dt class="sig sig-object py" id="pyFTS.partitioners.Class.ClassPartitioner.build">
<span class="sig-name descname"><span class="pre">build</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.11)"><span class="pre">list</span></a></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/Class.html#ClassPartitioner.build"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pyFTS.partitioners.Class.ClassPartitioner.build" title="Permalink to this definition"></a></dt>
<dt class="sig sig-object py" id="pyFTS.partitioners.ClassPartitioner.ClassPartitioner.build">
<span class="sig-name descname"><span class="pre">build</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.11)"><span class="pre">list</span></a></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/partitioners/ClassPartitioner.html#ClassPartitioner.build"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pyFTS.partitioners.ClassPartitioner.ClassPartitioner.build" title="Permalink to this definition"></a></dt>
<dd><p>Perform the partitioning of the Universe of Discourse</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
@ -604,7 +604,7 @@ Comput. Math. Appl., vol. 56, no. 12, pp. 30523063, Dec. 2008. DOI: 10.1016/j
<li><a class="reference internal" href="#module-pyFTS.partitioners">Module contents</a></li>
<li><a class="reference internal" href="#submodules">Submodules</a></li>
<li><a class="reference internal" href="#module-pyFTS.partitioners.partitioner">pyFTS.partitioners.partitioner module</a></li>
<li><a class="reference internal" href="#module-pyFTS.partitioners.Class">pyFTS.partitioners.Class module</a></li>
<li><a class="reference internal" href="#pyfts-partitioners-classpartitioner-module">pyFTS.partitioners.ClassPartitioner module</a></li>
<li><a class="reference internal" href="#module-pyFTS.partitioners.CMeans">pyFTS.partitioners.CMeans module</a></li>
<li><a class="reference internal" href="#module-pyFTS.partitioners.Entropy">pyFTS.partitioners.Entropy module</a></li>
<li><a class="reference internal" href="#module-pyFTS.partitioners.FCM">pyFTS.partitioners.FCM module</a></li>

File diff suppressed because one or more lines are too long

View File

@ -20,18 +20,18 @@ pyFTS.partitioners.partitioner module
:undoc-members:
:show-inheritance:
pyFTS.partitioners.Class module
-------------------------------
pyFTS.partitioners.ClassPartitioner module
-----------------------------------
.. automodule:: pyFTS.partitioners.Class
.. automodule:: pyFTS.partitioners.ClassPartitioner
:members:
:undoc-members:
:show-inheritance:
pyFTS.partitioners.KMeans module
pyFTS.partitioners.CMeans module
--------------------------------
.. automodule:: pyFTS.partitioners.KMeans
.. automodule:: pyFTS.partitioners.CMeans
:members:
:undoc-members:
:show-inheritance:

View File

@ -6,14 +6,14 @@ import numpy as np
import math
from pyFTS import *
def scale(dist : dict, weights : dict) -> dict:
def scale(dist : dict) -> dict:
norm = np.sum([v for v in dist.values()])
return {k : ((v * weights[k]) / norm) for k,v in dist.items() }
return {k : (v / norm) for k,v in dist.items() }
def softmax(dist : dict, weights : dict) -> dict:
def softmax(dist : dict) -> dict:
norm = np.sum([np.exp(v) for v in dist.values()])
return {k : (np.exp(v * weights[k]) / norm) for k,v in dist.items() }
return {k : (np.exp(v) / norm) for k,v in dist.items() }
def argmax(dist : dict, weights : dict) -> str:
mx = np.max([v * weights[k] for k,v in dist.items()])
return [k for k,v in dist.items() if v * weights[k] == mx ][0]
def argmax(dist : dict) -> str:
mx = np.max([v for v in dist.values()])
return [k for k,v in dist.items() if v == mx ][0]

View File

@ -1,5 +1,5 @@
from pyFTS.common.transformations.transformation import Transformation
# from pandas import datetime
from pandas import datetime
from sklearn.linear_model import LinearRegression
import numpy as np
import pandas as pd

View File

@ -146,7 +146,7 @@ class ClusteredMVFTS(mvfts.MVFTS):
new_data_point[self.target_variable.data_label] = tmp.expected_value()
sample = pd.concat([sample, pd.DataFrame([new_data_point])], ignore_index=True)
sample = sample.append(new_data_point, ignore_index=True)
return ret[-steps:]
@ -199,7 +199,7 @@ class ClusteredMVFTS(mvfts.MVFTS):
for k in np.arange(0, steps):
sample = ret.iloc[k:self.order+k]
tmp = self.forecast_multivariate(sample, **kwargs)
ret = pd.concat([ret, pd.DataFrame([tmp])], ignore_index=True)
ret = ret.append(tmp, ignore_index=True)
return ret

View File

@ -211,7 +211,7 @@ class MVFTS(fts.FTS):
new_data_point[self.target_variable.data_label] = tmp
ndata = pd.concat([ndata, pd.DataFrame([new_data_point])], ignore_index=True)
ndata = ndata.append(new_data_point, ignore_index=True)
return ret[-steps:]
@ -307,8 +307,8 @@ class MVFTS(fts.FTS):
new_data_point_lo[self.target_variable.data_label] = min(tmp_lo)
new_data_point_up[self.target_variable.data_label] = max(tmp_up)
lo = pd.concat([lo, pd.DataFrame([new_data_point_lo])], ignore_index=True)
up = pd.concat([up, pd.DataFrame([new_data_point_up])], ignore_index=True)
lo = lo.append(new_data_point_lo, ignore_index=True)
up = up.append(new_data_point_up, ignore_index=True)
return ret[-steps:]

View File

@ -69,8 +69,6 @@ class WeightedMVFTS(mvfts.MVFTS):
self.shortname = "WeightedMVFTS"
self.name = "Weighted Multivariate FTS"
self.has_classification = True
self.class_weights : dict = kwargs.get("class_weights", {})
def generate_flrg(self, flrs):
for flr in flrs:
@ -82,8 +80,6 @@ class WeightedMVFTS(mvfts.MVFTS):
self.flrgs[flrg.get_key()].append_rhs(flr.RHS)
def classify(self, data, **kwargs):
if len(self.class_weights) == 0:
self.class_weights = {k : 1.0 for k in self.target_variable.partitioner.sets.keys()}
ret = []
ndata = self.apply_transformations(data)
activation = kwargs.get('activation', Activations.scale)
@ -102,7 +98,7 @@ class WeightedMVFTS(mvfts.MVFTS):
for k,v in _flrg.RHS.items():
classification[k] += (v / _flrg.count) * mb
classification = activation(classification, self.class_weights)
classification = activation(classification)
ret.append(classification)

View File

@ -14,15 +14,15 @@ def distance(x, y):
return math.sqrt(tmp)
def k_means(k, dados, tam):
# Инициализирует центроиды, выбирая случайные элементы из множества
def c_means(k, dados, tam):
# Inicializa as centróides escolhendo elementos aleatórios dos conjuntos
centroides = [dados[rnd.randint(0, len(dados)-1)] for kk in range(0, k)]
grupos = [-1 for x in range(0, len(dados))]
it_semmodificacao = 0
# для каждого экземпляра
# para cada instância
iteracoes = 0
while iteracoes < 1000 and it_semmodificacao < 10:
inst_count = 0
@ -31,7 +31,7 @@ def k_means(k, dados, tam):
for instancia in dados:
# проверяет расстояние до каждого центроида
# verifica a distância para cada centroide
grupo_count = 0
dist = 10000
@ -41,7 +41,7 @@ def k_means(k, dados, tam):
tmp = distance(instancia, grupo)
if tmp < dist:
dist = tmp
# ассоциирует центроид с наименьшим расстоянием до экземпляра
# associa a a centroide de menor distância à instância
grupos[inst_count] = grupo_count
grupo_count = grupo_count + 1
@ -55,7 +55,7 @@ def k_means(k, dados, tam):
else:
it_semmodificacao = 0
# обновляет каждый центроид на основе средних значений всех связанных с ним экземпляров
# atualiza cada centroide com base nos valores médios de todas as instâncias à ela associadas
grupo_count = 0
for grupo in centroides:
total_inst = functools.reduce(operator.add, [1 for xx in grupos if xx == grupo_count], 0)
@ -77,21 +77,21 @@ def k_means(k, dados, tam):
return centroides
class KMeansPartitioner(partitioner.Partitioner):
class CMeansPartitioner(partitioner.Partitioner):
def __init__(self, **kwargs):
super(KMeansPartitioner, self).__init__(name="KMeans", **kwargs)
super(CMeansPartitioner, self).__init__(name="CMeans", **kwargs)
def build(self, data):
sets = {}
kwargs = {'type': self.type, 'variable': self.variable}
centroides = k_means(self.partitions, data, 1)
centroides = c_means(self.partitions, data, 1)
centroides.append(self.max)
centroides.append(self.min)
centroides = list(set(centroides))
centroides.sort()
for c in range(1, len(centroides) - 1):
for c in np.arange(1, len(centroides) - 1):
_name = self.get_name(c)
sets[_name] = FuzzySet.FuzzySet(_name, Membership.trimf,
[round(centroides[c - 1], 3), round(centroides[c], 3), round(centroides[c + 1], 3)],

View File

@ -36,7 +36,7 @@ def fuzzy_cmeans(k, data, size, m, deltadist=0.001):
centroids = [data[rnd.randint(0, data_length - 1)] for kk in range(0, k)]
# Membership table
membership_table = np.zeros((data_length, k))
membership_table = np.zeros((k, data_length)) #[[0 for kk in range(0, k)] for xx in range(0, data_length)]
mean_change = 1000
@ -50,12 +50,12 @@ def fuzzy_cmeans(k, data, size, m, deltadist=0.001):
inst_count = 0
for instance in data:
dist_groups = np.zeros(k)
dist_groups = np.zeros(k) #[0 for xx in range(0, k)]
for group_count, group in enumerate(centroids):
dist_groups[group_count] = fuzzy_distance(group, instance)
# dist_groups_total = functools.reduce(operator.add, [xk for xk in dist_groups])
dist_groups_total = functools.reduce(operator.add, [xk for xk in dist_groups])
for grp in range(0, k):
if dist_groups[grp] == 0:

View File

@ -19,13 +19,13 @@ class HuarngPartitioner(partitioner.Partitioner):
def build(self, data):
diff = Transformations.Differential(1)
data2 = diff.apply(data)
divs = np.abs( np.mean(data2) / 2 )
davg = np.abs( np.mean(data2) / 2 )
if divs <= 1.0:
if davg <= 1.0:
base = 0.1
elif 1 < divs <= 10:
elif 1 < davg <= 10:
base = 1.0
elif 10 < divs <= 100:
elif 10 < davg <= 100:
base = 10
else:
base = 100

View File

@ -18,20 +18,19 @@ all_methods = [Grid.GridPartitioner, Entropy.EntropyPartitioner, FCM.FCMPartitio
mfs = [Membership.trimf, Membership.gaussmf, Membership.trapmf]
def plot_sets(sets: dict, titles : list, size=[12, 10], save=False, file=None, axis=None):
def plot_sets(data, sets: dict, titles : list, size=[12, 10], save=False, file=None, axis=None):
"""
Plot all fuzzy sets in a Partitioner
"""
num = len(sets)
num_cols_plot = 1
if axis is None:
fig, axes = plt.subplots(nrows=num, ncols=num_cols_plot, figsize=size, squeeze=False)
for k in range(num):
fig, axes = plt.subplots(nrows=num, ncols=1,figsize=size)
for k in np.arange(0,num):
ticks = []
x = []
ax = axes[k, num_cols_plot-1] if axis is None else axis
ax = axes[k] if axis is None else axis
ax.set_title(titles[k])
ax.set_ylim([0, 1.1])
for key in sets[k].keys():
@ -55,7 +54,7 @@ def plot_sets(sets: dict, titles : list, size=[12, 10], save=False, file=None, a
Util.show_and_save_image(fig, file, save)
def plot_partitioners(objs, tam=[12, 10], save=False, file=None, axis=None):
def plot_partitioners(data, objs, tam=[12, 10], save=False, file=None, axis=None):
sets = [k.sets for k in objs]
titles = [k.name for k in objs]
plot_sets(sets, titles, tam, save, file, axis)

View File

@ -1,7 +1,6 @@
from pyFTS.common import FuzzySet, Membership
import numpy as np
from scipy.spatial import KDTree
import warnings
class Partitioner(object):
@ -47,9 +46,6 @@ class Partitioner(object):
data = kwargs.get('data',[None])
if isinstance(data, np.ndarray) and len(data.shape) > 1:
warnings.warn(f"An ndarray of dimension greater than 1 is used. shape.len(): {len(data.shape)}")
if self.indexer is not None:
ndata = self.indexer.get_data(data)
else:

View File

@ -11,7 +11,7 @@ from mpl_toolkits.mplot3d import Axes3D
import datetime
import pandas as pd
from pyFTS.partitioners import Grid, KMeans, FCM, Entropy
from pyFTS.partitioners import Grid, CMeans, FCM, Entropy
from pyFTS.common import FLR, FuzzySet, Membership, Transformations, Util, fts
from pyFTS import sfts
from pyFTS.models import msfts

View File

@ -25,8 +25,6 @@ setuptools.setup(
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Intended Audience :: Science/Research',
'Intended Audience :: Developers',
'Intended Audience :: Education',