186 lines
21 KiB
HTML
186 lines
21 KiB
HTML
|
|
|
|
<!doctype html>
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<title>pyFTS.models.seasonal.common — pyFTS 1.2.3 documentation</title>
|
|
<link rel="stylesheet" href="../../../../_static/bizstyle.css" type="text/css" />
|
|
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
|
|
<script type="text/javascript" src="../../../../_static/documentation_options.js"></script>
|
|
<script type="text/javascript" src="../../../../_static/jquery.js"></script>
|
|
<script type="text/javascript" src="../../../../_static/underscore.js"></script>
|
|
<script type="text/javascript" src="../../../../_static/doctools.js"></script>
|
|
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
|
|
<script type="text/javascript" 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 type="text/javascript" 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.2.3 documentation</a> »</li>
|
|
<li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> »</li>
|
|
</ul>
|
|
</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>Quick search</h3>
|
|
<div class="searchformwrapper">
|
|
<form class="search" action="../../../../search.html" method="get">
|
|
<input type="text" name="q" />
|
|
<input type="submit" value="Go" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">$('#searchbox').show(0);</script>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="document">
|
|
<div class="documentwrapper">
|
|
<div class="bodywrapper">
|
|
<div class="body" role="main">
|
|
|
|
<h1>Source code for pyFTS.models.seasonal.common</h1><div class="highlight"><pre>
|
|
<span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
|
|
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
|
|
<span class="kn">from</span> <span class="nn">enum</span> <span class="k">import</span> <span class="n">Enum</span>
|
|
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="k">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="k">import</span> <span class="n">partitioner</span><span class="p">,</span> <span class="n">Grid</span>
|
|
|
|
|
|
<div class="viewcode-block" id="DateTime"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.common.DateTime">[docs]</a><span class="k">class</span> <span class="nc">DateTime</span><span class="p">(</span><span class="n">Enum</span><span class="p">):</span>
|
|
<span class="n">year</span> <span class="o">=</span> <span class="mi">1</span>
|
|
<span class="n">month</span> <span class="o">=</span> <span class="mi">12</span>
|
|
<span class="n">day_of_month</span> <span class="o">=</span> <span class="mi">30</span>
|
|
<span class="n">day_of_year</span> <span class="o">=</span> <span class="mi">364</span>
|
|
<span class="n">day_of_week</span> <span class="o">=</span> <span class="mi">7</span>
|
|
<span class="n">hour</span> <span class="o">=</span> <span class="mi">6</span>
|
|
<span class="n">minute</span> <span class="o">=</span> <span class="mi">7</span>
|
|
<span class="n">second</span> <span class="o">=</span> <span class="mi">8</span>
|
|
<span class="n">hour_of_day</span> <span class="o">=</span> <span class="mi">24</span>
|
|
<span class="n">hour_of_week</span> <span class="o">=</span> <span class="mi">168</span>
|
|
<span class="n">hour_of_month</span> <span class="o">=</span> <span class="mi">744</span>
|
|
<span class="n">hour_of_year</span> <span class="o">=</span> <span class="mi">8736</span>
|
|
<span class="n">minute_of_hour</span> <span class="o">=</span> <span class="mi">60</span>
|
|
<span class="n">minute_of_day</span> <span class="o">=</span> <span class="mi">1440</span>
|
|
<span class="n">minute_of_week</span> <span class="o">=</span> <span class="mi">10080</span>
|
|
<span class="n">minute_of_month</span> <span class="o">=</span> <span class="mi">44640</span>
|
|
<span class="n">minute_of_year</span> <span class="o">=</span> <span class="mi">524160</span>
|
|
<span class="n">second_of_minute</span> <span class="o">=</span> <span class="mf">60.00001</span>
|
|
<span class="n">second_of_hour</span> <span class="o">=</span> <span class="mi">3600</span>
|
|
<span class="n">second_of_day</span> <span class="o">=</span> <span class="mi">86400</span></div>
|
|
|
|
|
|
<div class="viewcode-block" id="strip_datepart"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.common.strip_datepart">[docs]</a><span class="k">def</span> <span class="nf">strip_datepart</span><span class="p">(</span><span class="n">date</span><span class="p">,</span> <span class="n">date_part</span><span class="p">):</span>
|
|
<span class="k">if</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">year</span><span class="p">:</span>
|
|
<span class="n">tmp</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">year</span>
|
|
<span class="k">elif</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">month</span><span class="p">:</span>
|
|
<span class="n">tmp</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">month</span>
|
|
<span class="k">elif</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">day_of_year</span><span class="p">:</span>
|
|
<span class="n">tmp</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">timetuple</span><span class="p">()</span><span class="o">.</span><span class="n">tm_yday</span>
|
|
<span class="k">elif</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">day_of_month</span><span class="p">:</span>
|
|
<span class="n">tmp</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">day</span>
|
|
<span class="k">elif</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">day_of_week</span><span class="p">:</span>
|
|
<span class="n">tmp</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">weekday</span><span class="p">()</span>
|
|
<span class="k">elif</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">hour</span> <span class="ow">or</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">hour_of_day</span><span class="p">:</span>
|
|
<span class="n">tmp</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">hour</span>
|
|
<span class="k">elif</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">hour_of_week</span><span class="p">:</span>
|
|
<span class="n">wk</span> <span class="o">=</span> <span class="p">(</span><span class="n">date</span><span class="o">.</span><span class="n">weekday</span><span class="p">()</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="mi">24</span>
|
|
<span class="n">tmp</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">hour</span> <span class="o">+</span> <span class="n">wk</span>
|
|
<span class="k">elif</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">hour_of_month</span><span class="p">:</span>
|
|
<span class="n">wk</span> <span class="o">=</span> <span class="p">(</span><span class="n">date</span><span class="o">.</span><span class="n">day</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="mi">24</span>
|
|
<span class="n">tmp</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">hour</span> <span class="o">+</span> <span class="n">wk</span>
|
|
<span class="k">elif</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">hour_of_year</span><span class="p">:</span>
|
|
<span class="n">wk</span> <span class="o">=</span> <span class="p">(</span><span class="n">date</span><span class="o">.</span><span class="n">timetuple</span><span class="p">()</span><span class="o">.</span><span class="n">tm_yday</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="mi">24</span>
|
|
<span class="n">tmp</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">hour</span> <span class="o">+</span> <span class="n">wk</span>
|
|
<span class="k">elif</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">minute</span> <span class="ow">or</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">minute_of_hour</span><span class="p">:</span>
|
|
<span class="n">tmp</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">minute</span>
|
|
<span class="k">elif</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">minute_of_day</span><span class="p">:</span>
|
|
<span class="n">wk</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">hour</span> <span class="o">*</span> <span class="mi">60</span>
|
|
<span class="n">tmp</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">minute</span> <span class="o">+</span> <span class="n">wk</span>
|
|
<span class="k">elif</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">minute_of_week</span><span class="p">:</span>
|
|
<span class="n">wk1</span> <span class="o">=</span> <span class="p">(</span><span class="n">date</span><span class="o">.</span><span class="n">weekday</span><span class="p">()</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="mi">1440</span> <span class="c1">#24 * 60</span>
|
|
<span class="n">wk2</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">hour</span> <span class="o">*</span> <span class="mi">60</span>
|
|
<span class="n">tmp</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">minute</span> <span class="o">+</span> <span class="n">wk1</span> <span class="o">+</span> <span class="n">wk2</span>
|
|
<span class="k">elif</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">minute_of_month</span><span class="p">:</span>
|
|
<span class="n">wk1</span> <span class="o">=</span> <span class="p">(</span><span class="n">date</span><span class="o">.</span><span class="n">day</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="mi">1440</span> <span class="c1">#24 * 60</span>
|
|
<span class="n">wk2</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">hour</span> <span class="o">*</span> <span class="mi">60</span>
|
|
<span class="n">tmp</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">minute</span> <span class="o">+</span> <span class="n">wk1</span> <span class="o">+</span> <span class="n">wk2</span>
|
|
<span class="k">elif</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">minute_of_year</span><span class="p">:</span>
|
|
<span class="n">wk1</span> <span class="o">=</span> <span class="p">(</span><span class="n">date</span><span class="o">.</span><span class="n">timetuple</span><span class="p">()</span><span class="o">.</span><span class="n">tm_yday</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="mi">1440</span> <span class="c1">#24 * 60</span>
|
|
<span class="n">wk2</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">hour</span> <span class="o">*</span> <span class="mi">60</span>
|
|
<span class="n">tmp</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">minute</span> <span class="o">+</span> <span class="n">wk1</span> <span class="o">+</span> <span class="n">wk2</span>
|
|
<span class="k">elif</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">second</span> <span class="ow">or</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">second_of_minute</span><span class="p">:</span>
|
|
<span class="n">tmp</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">second</span>
|
|
<span class="k">elif</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">second_of_hour</span><span class="p">:</span>
|
|
<span class="n">wk1</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">minute</span> <span class="o">*</span> <span class="mi">60</span>
|
|
<span class="n">tmp</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">second</span> <span class="o">+</span> <span class="n">wk1</span>
|
|
<span class="k">elif</span> <span class="n">date_part</span> <span class="o">==</span> <span class="n">DateTime</span><span class="o">.</span><span class="n">second_of_day</span><span class="p">:</span>
|
|
<span class="n">wk1</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">hour</span> <span class="o">*</span> <span class="mi">3600</span> <span class="c1">#60 * 60</span>
|
|
<span class="n">wk2</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">minute</span> <span class="o">*</span> <span class="mi">60</span>
|
|
<span class="n">tmp</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">second</span> <span class="o">+</span> <span class="n">wk1</span> <span class="o">+</span> <span class="n">wk2</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">"Unknown DateTime value!"</span><span class="p">)</span>
|
|
|
|
<span class="k">return</span> <span class="n">tmp</span></div>
|
|
|
|
|
|
<div class="viewcode-block" id="FuzzySet"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.common.FuzzySet">[docs]</a><span class="k">class</span> <span class="nc">FuzzySet</span><span class="p">(</span><span class="n">FuzzySet</span><span class="o">.</span><span class="n">FuzzySet</span><span class="p">):</span>
|
|
<span class="sd">"""</span>
|
|
<span class="sd"> Temporal/Seasonal Fuzzy Set</span>
|
|
<span class="sd"> """</span>
|
|
|
|
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">datepart</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">mf</span><span class="p">,</span> <span class="n">parameters</span><span class="p">,</span> <span class="n">centroid</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
|
|
<span class="nb">super</span><span class="p">(</span><span class="n">FuzzySet</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="p">,</span> <span class="n">mf</span><span class="p">,</span> <span class="n">parameters</span><span class="p">,</span> <span class="n">centroid</span><span class="p">,</span> <span class="n">alpha</span><span class="p">,</span> <span class="nb">type</span> <span class="o">=</span> <span class="s1">'datetime'</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">datepart</span> <span class="o">=</span> <span class="n">datepart</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="s1">'seasonal'</span>
|
|
|
|
<div class="viewcode-block" id="FuzzySet.membership"><a class="viewcode-back" href="../../../../pyFTS.models.seasonal.html#pyFTS.models.seasonal.common.FuzzySet.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">dp</span> <span class="o">=</span> <span class="n">strip_datepart</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">datepart</span><span class="p">)</span>
|
|
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">mf</span><span class="p">(</span><span class="n">dp</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="p">)</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">alpha</span></div></div>
|
|
</pre></div>
|
|
|
|
</div>
|
|
</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.2.3 documentation</a> »</li>
|
|
<li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> »</li>
|
|
</ul>
|
|
</div>
|
|
<div class="footer" role="contentinfo">
|
|
© Copyright 2018, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
|
|
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.7.2.
|
|
</div>
|
|
</body>
|
|
</html> |