Compare commits

..

20 Commits

Author SHA1 Message Date
sam
4b348ad818 replacing the deprecated append method with the concat method in pandas 2024-08-14 12:08:26 +04:00
sam
eac7a83265 replacing the deprecated append method with the concat method in pandas 2024-08-14 11:57:24 +04:00
sam
ccc0196f56 adding a check for the ndarray data type 2024-08-14 11:55:54 +04:00
sam
3ec1b4c5ce #3 rename variable 2024-08-08 12:53:02 +04:00
sam
a8fb849bc8 #2 Index order is mixed up (transposed array) 2024-08-08 12:00:51 +04:00
sam
8be936e383 return work code 2024-08-08 11:59:33 +04:00
sam
e1f72797ea Warning: An ndarray of dimension greater than 1 is used 2024-08-08 11:59:14 +04:00
sam
e55ef29351 Repair: Use of a single partitioned 2024-08-08 11:58:38 +04:00
sam
619c6ecd15 rename KMeans 2024-08-07 11:19:01 +04:00
sam
fac2aa5ca8 add python 3.11 support 2024-08-07 11:18:21 +04:00
sam
0329e7b83f copy .gitignore to root 2024-08-07 10:30:46 +04:00
sam
e9d5f7629f Delete an unnecessary variable "data" 2024-08-07 10:26:48 +04:00
sam
78e63aaa63 Update portugalian on russian 2024-08-07 10:26:07 +04:00
sam
c24ebe6b81 remove np.array in cMeans 2024-08-06 15:18:31 +04:00
47e78bc066 remove "from pandas import datetime" 2024-08-06 13:19:08 +04:00
Petrônio Cândido de Lima e Silva
4e0ee7cdd9
Update wmvfts.py 2023-05-26 14:44:46 -03:00
Petrônio Cândido de Lima e Silva
afc9b219ce
Update wmvfts.py - class_weights 2023-05-26 14:24:41 -03:00
Petrônio Cândido de Lima e Silva
560dcfacf6
Update Activations.py - weights 2023-05-26 14:21:12 -03:00
Petrônio Cândido de Lima e Silva
b8cfea5278
Update wmvfts.py - class_weights 2023-05-26 14:13:41 -03:00
Petrônio Cândido
02f6022a53 Refactoring and documentation updates 2023-05-24 20:18:52 -03:00
28 changed files with 258 additions and 64 deletions

57
.gitignore vendored Normal file
View File

@ -0,0 +1,57 @@
# 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/msfts.py
pyFTS/models/seasonal/partitioner.py pyFTS/models/seasonal/partitioner.py
pyFTS/models/seasonal/sfts.py pyFTS/models/seasonal/sfts.py
pyFTS/partitioners/CMeans.py pyFTS/partitioners/KMeans.py
pyFTS/partitioners/Entropy.py pyFTS/partitioners/Entropy.py
pyFTS/partitioners/FCM.py pyFTS/partitioners/FCM.py
pyFTS/partitioners/Grid.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: 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 - the number of intervals
- which fuzzy membership function (on [pyFTS.common.Membership](https://github.com/PYFTS/pyFTS/blob/master/pyFTS/common/Membership.py)) - 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), [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]) - 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])
Check out the jupyter notebook on [notebooks/Partitioners.ipynb](https://github.com/PYFTS/notebooks/blob/master/Partitioners.ipynb) for sample codes. 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/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/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/CMeans.html">pyFTS.partitioners.CMeans</a></li>
<li><a href="pyFTS/partitioners/ClassPartitioner.html">pyFTS.partitioners.ClassPartitioner</a></li> <li><a href="pyFTS/partitioners/Class.html">pyFTS.partitioners.Class</a></li>
<li><a href="pyFTS/partitioners/Entropy.html">pyFTS.partitioners.Entropy</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/FCM.html">pyFTS.partitioners.FCM</a></li>
<li><a href="pyFTS/partitioners/Grid.html">pyFTS.partitioners.Grid</a></li> <li><a href="pyFTS/partitioners/Grid.html">pyFTS.partitioners.Grid</a></li>

View File

@ -0,0 +1,126 @@
<!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: :undoc-members:
:show-inheritance: :show-inheritance:
pyFTS.partitioners.ClassPartitioner module pyFTS.partitioners.Class module
----------------------------------- -------------------------------
.. automodule:: pyFTS.partitioners.ClassPartitioner .. automodule:: pyFTS.partitioners.Class
:members: :members:
:undoc-members: :undoc-members:
:show-inheritance: :show-inheritance:

View File

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

Binary file not shown.

View File

@ -389,7 +389,7 @@
<tr class="cg-1"> <tr class="cg-1">
<td></td> <td></td>
<td>&#160;&#160;&#160; <td>&#160;&#160;&#160;
<a href="pyFTS.partitioners.html#module-pyFTS.partitioners.ClassPartitioner"><code class="xref">pyFTS.partitioners.ClassPartitioner</code></a></td><td> <a href="pyFTS.partitioners.html#module-pyFTS.partitioners.Class"><code class="xref">pyFTS.partitioners.Class</code></a></td><td>
<em></em></td></tr> <em></em></td></tr>
<tr class="cg-1"> <tr class="cg-1">
<td></td> <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#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#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.partitioner">pyFTS.partitioners.partitioner 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.Class">pyFTS.partitioners.Class 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.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.Entropy">pyFTS.partitioners.Entropy module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.FCM">pyFTS.partitioners.FCM module</a></li> <li class="toctree-l2"><a class="reference internal" href="pyFTS.partitioners.html#module-pyFTS.partitioners.FCM">pyFTS.partitioners.FCM module</a></li>

View File

@ -299,17 +299,17 @@ overlapped fuzzy sets.</p>
</dd></dl> </dd></dl>
</section> </section>
<section id="pyfts-partitioners-classpartitioner-module"> <section id="module-pyFTS.partitioners.Class">
<h2>pyFTS.partitioners.ClassPartitioner module<a class="headerlink" href="#pyfts-partitioners-classpartitioner-module" title="Permalink to this headline"></a></h2> <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>
<span class="target" id="module-pyFTS.partitioners.ClassPartitioner"></span><p>Class Partitioner with Singleton Fuzzy Sets</p> <p>Class Partitioner with Singleton Fuzzy Sets</p>
<dl class="py class"> <dl class="py class">
<dt class="sig sig-object py" id="pyFTS.partitioners.ClassPartitioner.ClassPartitioner"> <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.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> <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>
<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> <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> <p>Class Partitioner: Given a dictionary with class/values pairs, create singleton fuzzy sets for each class</p>
<dl class="py method"> <dl class="py method">
<dt class="sig sig-object py" id="pyFTS.partitioners.ClassPartitioner.ClassPartitioner.build"> <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/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> <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>
<dd><p>Perform the partitioning of the Universe of Discourse</p> <dd><p>Perform the partitioning of the Universe of Discourse</p>
<dl class="field-list simple"> <dl class="field-list simple">
<dt class="field-odd">Parameters</dt> <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="#module-pyFTS.partitioners">Module contents</a></li>
<li><a class="reference internal" href="#submodules">Submodules</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.partitioner">pyFTS.partitioners.partitioner 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.Class">pyFTS.partitioners.Class 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.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.Entropy">pyFTS.partitioners.Entropy module</a></li>
<li><a class="reference internal" href="#module-pyFTS.partitioners.FCM">pyFTS.partitioners.FCM module</a></li> <li><a class="reference internal" href="#module-pyFTS.partitioners.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: :undoc-members:
:show-inheritance: :show-inheritance:
pyFTS.partitioners.ClassPartitioner module pyFTS.partitioners.Class module
----------------------------------- -------------------------------
.. automodule:: pyFTS.partitioners.ClassPartitioner .. automodule:: pyFTS.partitioners.Class
:members: :members:
:undoc-members: :undoc-members:
:show-inheritance: :show-inheritance:
pyFTS.partitioners.CMeans module pyFTS.partitioners.KMeans module
-------------------------------- --------------------------------
.. automodule:: pyFTS.partitioners.CMeans .. automodule:: pyFTS.partitioners.KMeans
:members: :members:
:undoc-members: :undoc-members:
:show-inheritance: :show-inheritance:

View File

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

View File

@ -1,5 +1,5 @@
from pyFTS.common.transformations.transformation import Transformation from pyFTS.common.transformations.transformation import Transformation
from pandas import datetime # from pandas import datetime
from sklearn.linear_model import LinearRegression from sklearn.linear_model import LinearRegression
import numpy as np import numpy as np
import pandas as pd 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() new_data_point[self.target_variable.data_label] = tmp.expected_value()
sample = sample.append(new_data_point, ignore_index=True) sample = pd.concat([sample, pd.DataFrame([new_data_point])], ignore_index=True)
return ret[-steps:] return ret[-steps:]
@ -199,7 +199,7 @@ class ClusteredMVFTS(mvfts.MVFTS):
for k in np.arange(0, steps): for k in np.arange(0, steps):
sample = ret.iloc[k:self.order+k] sample = ret.iloc[k:self.order+k]
tmp = self.forecast_multivariate(sample, **kwargs) tmp = self.forecast_multivariate(sample, **kwargs)
ret = ret.append(tmp, ignore_index=True) ret = pd.concat([ret, pd.DataFrame([tmp])], ignore_index=True)
return ret return ret

View File

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

View File

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

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)] centroids = [data[rnd.randint(0, data_length - 1)] for kk in range(0, k)]
# Membership table # Membership table
membership_table = np.zeros((k, data_length)) #[[0 for kk in range(0, k)] for xx in range(0, data_length)] membership_table = np.zeros((data_length, k))
mean_change = 1000 mean_change = 1000
@ -50,12 +50,12 @@ def fuzzy_cmeans(k, data, size, m, deltadist=0.001):
inst_count = 0 inst_count = 0
for instance in data: for instance in data:
dist_groups = np.zeros(k) #[0 for xx in range(0, k)] dist_groups = np.zeros(k)
for group_count, group in enumerate(centroids): for group_count, group in enumerate(centroids):
dist_groups[group_count] = fuzzy_distance(group, instance) 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): for grp in range(0, k):
if dist_groups[grp] == 0: if dist_groups[grp] == 0:

View File

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

View File

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

View File

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

View File

@ -1,6 +1,7 @@
from pyFTS.common import FuzzySet, Membership from pyFTS.common import FuzzySet, Membership
import numpy as np import numpy as np
from scipy.spatial import KDTree from scipy.spatial import KDTree
import warnings
class Partitioner(object): class Partitioner(object):
@ -45,6 +46,9 @@ class Partitioner(object):
if kwargs.get('preprocess',True): if kwargs.get('preprocess',True):
data = kwargs.get('data',[None]) 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: if self.indexer is not None:
ndata = self.indexer.get_data(data) ndata = self.indexer.get_data(data)

View File

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

View File

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