<!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" /><script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-55120145-3']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> <title>pyFTS.common.Transformations — pyFTS 1.4 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.4 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.common.Transformations</h1><div class="highlight"><pre> <span></span><span class="sd">"""</span> <span class="sd">Common data transformation used on pre and post processing of the FTS</span> <span class="sd">"""</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">from</span> <span class="nn">pyFTS</span> <span class="k">import</span> <span class="o">*</span> <div class="viewcode-block" id="Transformation"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Transformations.Transformation">[docs]</a><span class="k">class</span> <span class="nc">Transformation</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> <span class="sd">"""</span> <span class="sd"> Data transformation used on pre and post processing of the FTS</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="o">**</span><span class="n">kwargs</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_invertible</span> <span class="o">=</span> <span class="kc">True</span> <span class="bp">self</span><span class="o">.</span><span class="n">minimal_length</span> <span class="o">=</span> <span class="mi">1</span> <div class="viewcode-block" id="Transformation.apply"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Transformations.Transformation.apply">[docs]</a> <span class="k">def</span> <span class="nf">apply</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="n">param</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <span class="sd">"""</span> <span class="sd"> Apply the transformation on input data</span> <span class="sd"> :param data: input data</span> <span class="sd"> :param param:</span> <span class="sd"> :param kwargs:</span> <span class="sd"> :return: numpy array with transformed data</span> <span class="sd"> """</span> <span class="k">pass</span></div> <div class="viewcode-block" id="Transformation.inverse"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Transformations.Transformation.inverse">[docs]</a> <span class="k">def</span> <span class="nf">inverse</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="n">param</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <span class="sd">"""</span> <span class="sd"> :param data: transformed data</span> <span class="sd"> :param param:</span> <span class="sd"> :param kwargs:</span> <span class="sd"> :return: numpy array with inverse transformed data</span> <span class="sd"> """</span> <span class="k">pass</span></div> <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">+</span> <span class="s1">'('</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="p">)</span> <span class="o">+</span> <span class="s1">')'</span></div> <div class="viewcode-block" id="Differential"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Transformations.Differential">[docs]</a><span class="k">class</span> <span class="nc">Differential</span><span class="p">(</span><span class="n">Transformation</span><span class="p">):</span> <span class="sd">"""</span> <span class="sd"> Differentiation data transform</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">lag</span><span class="p">):</span> <span class="nb">super</span><span class="p">(</span><span class="n">Differential</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="bp">self</span><span class="o">.</span><span class="n">lag</span> <span class="o">=</span> <span class="n">lag</span> <span class="bp">self</span><span class="o">.</span><span class="n">minimal_length</span> <span class="o">=</span> <span class="mi">2</span> <span class="nd">@property</span> <span class="k">def</span> <span class="nf">parameters</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">lag</span> <div class="viewcode-block" id="Differential.apply"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Transformations.Differential.apply">[docs]</a> <span class="k">def</span> <span class="nf">apply</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="n">param</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <span class="k">if</span> <span class="n">param</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">lag</span> <span class="o">=</span> <span class="n">param</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">generic</span><span class="p">)):</span> <span class="n">data</span> <span class="o">=</span> <span class="p">[</span><span class="n">data</span><span class="p">]</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">generic</span><span class="p">)):</span> <span class="n">data</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span> <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="n">diff</span> <span class="o">=</span> <span class="p">[</span><span class="n">data</span><span class="p">[</span><span class="n">t</span><span class="p">]</span> <span class="o">-</span> <span class="n">data</span><span class="p">[</span><span class="n">t</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">lag</span><span class="p">]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lag</span><span class="p">,</span> <span class="n">n</span><span class="p">)]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">lag</span><span class="p">):</span> <span class="n">diff</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="k">return</span> <span class="n">diff</span></div> <div class="viewcode-block" id="Differential.inverse"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Transformations.Differential.inverse">[docs]</a> <span class="k">def</span> <span class="nf">inverse</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="n">param</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <span class="nb">type</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">"type"</span><span class="p">,</span><span class="s2">"point"</span><span class="p">)</span> <span class="n">steps_ahead</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">"steps_ahead"</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">generic</span><span class="p">)):</span> <span class="n">data</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</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="n">data</span> <span class="o">=</span> <span class="p">[</span><span class="n">data</span><span class="p">]</span> <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="c1"># print(n)</span> <span class="c1"># print(len(param))</span> <span class="k">if</span> <span class="n">steps_ahead</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span> <span class="k">if</span> <span class="nb">type</span> <span class="o">==</span> <span class="s2">"point"</span><span class="p">:</span> <span class="n">inc</span> <span class="o">=</span> <span class="p">[</span><span class="n">data</span><span class="p">[</span><span class="n">t</span><span class="p">]</span> <span class="o">+</span> <span class="n">param</span><span class="p">[</span><span class="n">t</span><span class="p">]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">n</span><span class="p">)]</span> <span class="k">elif</span> <span class="nb">type</span> <span class="o">==</span> <span class="s2">"interval"</span><span class="p">:</span> <span class="n">inc</span> <span class="o">=</span> <span class="p">[[</span><span class="n">data</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">param</span><span class="p">[</span><span class="n">t</span><span class="p">],</span> <span class="n">data</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">param</span><span class="p">[</span><span class="n">t</span><span class="p">]]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">n</span><span class="p">)]</span> <span class="k">elif</span> <span class="nb">type</span> <span class="o">==</span> <span class="s2">"distribution"</span><span class="p">:</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">n</span><span class="p">):</span> <span class="n">data</span><span class="p">[</span><span class="n">t</span><span class="p">]</span><span class="o">.</span><span class="n">differential_offset</span><span class="p">(</span><span class="n">param</span><span class="p">[</span><span class="n">t</span><span class="p">])</span> <span class="n">inc</span> <span class="o">=</span> <span class="n">data</span> <span class="k">else</span><span class="p">:</span> <span class="k">if</span> <span class="nb">type</span> <span class="o">==</span> <span class="s2">"point"</span><span class="p">:</span> <span class="n">inc</span> <span class="o">=</span> <span class="p">[</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">param</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">steps_ahead</span><span class="p">):</span> <span class="n">inc</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">t</span><span class="p">]</span> <span class="o">+</span> <span class="n">inc</span><span class="p">[</span><span class="n">t</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span> <span class="k">elif</span> <span class="nb">type</span> <span class="o">==</span> <span class="s2">"interval"</span><span class="p">:</span> <span class="n">inc</span> <span class="o">=</span> <span class="p">[[</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">param</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">param</span><span class="p">[</span><span class="mi">0</span><span class="p">]]]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">steps_ahead</span><span class="p">):</span> <span class="n">inc</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">data</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmean</span><span class="p">(</span><span class="n">inc</span><span class="p">[</span><span class="n">t</span><span class="o">-</span><span class="mi">1</span><span class="p">]),</span> <span class="n">data</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmean</span><span class="p">(</span><span class="n">inc</span><span class="p">[</span><span class="n">t</span><span class="o">-</span><span class="mi">1</span><span class="p">])])</span> <span class="k">elif</span> <span class="nb">type</span> <span class="o">==</span> <span class="s2">"distribution"</span><span class="p">:</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">differential_offset</span><span class="p">(</span><span class="n">param</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">steps_ahead</span><span class="p">):</span> <span class="n">ex</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">t</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">expected_value</span><span class="p">()</span> <span class="n">data</span><span class="p">[</span><span class="n">t</span><span class="p">]</span><span class="o">.</span><span class="n">differential_offset</span><span class="p">(</span><span class="n">ex</span><span class="p">)</span> <span class="n">inc</span> <span class="o">=</span> <span class="n">data</span> <span class="k">if</span> <span class="n">n</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span> <span class="k">return</span> <span class="n">inc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">else</span><span class="p">:</span> <span class="k">return</span> <span class="n">inc</span></div></div> <div class="viewcode-block" id="Scale"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Transformations.Scale">[docs]</a><span class="k">class</span> <span class="nc">Scale</span><span class="p">(</span><span class="n">Transformation</span><span class="p">):</span> <span class="sd">"""</span> <span class="sd"> Scale data inside a interval [min, max]</span> <span class="sd"> </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="nb">min</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="nb">max</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span> <span class="nb">super</span><span class="p">(</span><span class="n">Scale</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="bp">self</span><span class="o">.</span><span class="n">data_max</span> <span class="o">=</span> <span class="kc">None</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_min</span> <span class="o">=</span> <span class="kc">None</span> <span class="bp">self</span><span class="o">.</span><span class="n">transf_max</span> <span class="o">=</span> <span class="nb">max</span> <span class="bp">self</span><span class="o">.</span><span class="n">transf_min</span> <span class="o">=</span> <span class="nb">min</span> <span class="nd">@property</span> <span class="k">def</span> <span class="nf">parameters</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">transf_max</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">transf_min</span><span class="p">]</span> <div class="viewcode-block" id="Scale.apply"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Transformations.Scale.apply">[docs]</a> <span class="k">def</span> <span class="nf">apply</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="n">param</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_max</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_max</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmax</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_min</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nanmin</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="n">data_range</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_max</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_min</span> <span class="n">transf_range</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">transf_max</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">transf_min</span> <span class="k">if</span> <span class="nb">isinstance</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="n">tmp</span> <span class="o">=</span> <span class="p">[(</span><span class="n">k</span> <span class="o">+</span> <span class="p">(</span><span class="o">-</span><span class="mi">1</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_min</span><span class="p">))</span> <span class="o">/</span> <span class="n">data_range</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">data</span><span class="p">]</span> <span class="n">tmp2</span> <span class="o">=</span> <span class="p">[</span> <span class="p">(</span><span class="n">k</span> <span class="o">*</span> <span class="n">transf_range</span><span class="p">)</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">transf_min</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">tmp</span><span class="p">]</span> <span class="k">else</span><span class="p">:</span> <span class="n">tmp</span> <span class="o">=</span> <span class="p">(</span><span class="n">data</span> <span class="o">+</span> <span class="p">(</span><span class="o">-</span><span class="mi">1</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_min</span><span class="p">))</span> <span class="o">/</span> <span class="n">data_range</span> <span class="n">tmp2</span> <span class="o">=</span> <span class="p">(</span><span class="n">tmp</span> <span class="o">*</span> <span class="n">transf_range</span><span class="p">)</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">transf_min</span> <span class="k">return</span> <span class="n">tmp2</span></div> <div class="viewcode-block" id="Scale.inverse"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Transformations.Scale.inverse">[docs]</a> <span class="k">def</span> <span class="nf">inverse</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="n">param</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <span class="n">data_range</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_max</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_min</span> <span class="n">transf_range</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">transf_max</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">transf_min</span> <span class="k">if</span> <span class="nb">isinstance</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="n">tmp2</span> <span class="o">=</span> <span class="p">[(</span><span class="n">k</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">transf_min</span><span class="p">)</span> <span class="o">/</span> <span class="n">transf_range</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">data</span><span class="p">]</span> <span class="n">tmp</span> <span class="o">=</span> <span class="p">[(</span><span class="n">k</span> <span class="o">*</span> <span class="n">data_range</span><span class="p">)</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_min</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">tmp2</span><span class="p">]</span> <span class="k">else</span><span class="p">:</span> <span class="n">tmp2</span> <span class="o">=</span> <span class="p">(</span><span class="n">data</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">transf_min</span><span class="p">)</span> <span class="o">/</span> <span class="n">transf_range</span> <span class="n">tmp</span> <span class="o">=</span> <span class="p">(</span><span class="n">tmp2</span> <span class="o">*</span> <span class="n">data_range</span><span class="p">)</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_min</span> <span class="k">return</span> <span class="n">tmp</span></div></div> <div class="viewcode-block" id="AdaptiveExpectation"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Transformations.AdaptiveExpectation">[docs]</a><span class="k">class</span> <span class="nc">AdaptiveExpectation</span><span class="p">(</span><span class="n">Transformation</span><span class="p">):</span> <span class="sd">"""</span> <span class="sd"> Adaptive Expectation post processing</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">parameters</span><span class="p">):</span> <span class="nb">super</span><span class="p">(</span><span class="n">AdaptiveExpectation</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">parameters</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">h</span> <span class="o">=</span> <span class="n">parameters</span> <span class="nd">@property</span> <span class="k">def</span> <span class="nf">parameters</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span> <div class="viewcode-block" id="AdaptiveExpectation.apply"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Transformations.AdaptiveExpectation.apply">[docs]</a> <span class="k">def</span> <span class="nf">apply</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="n">param</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <span class="k">return</span> <span class="n">data</span></div> <div class="viewcode-block" id="AdaptiveExpectation.inverse"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Transformations.AdaptiveExpectation.inverse">[docs]</a> <span class="k">def</span> <span class="nf">inverse</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="n">param</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="n">inc</span> <span class="o">=</span> <span class="p">[</span><span class="n">param</span><span class="p">[</span><span class="n">t</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">h</span><span class="o">*</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">t</span><span class="p">]</span> <span class="o">-</span> <span class="n">param</span><span class="p">[</span><span class="n">t</span><span class="p">])</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">n</span><span class="p">)]</span> <span class="k">if</span> <span class="n">n</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span> <span class="k">return</span> <span class="n">inc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">else</span><span class="p">:</span> <span class="k">return</span> <span class="n">inc</span></div></div> <div class="viewcode-block" id="BoxCox"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Transformations.BoxCox">[docs]</a><span class="k">class</span> <span class="nc">BoxCox</span><span class="p">(</span><span class="n">Transformation</span><span class="p">):</span> <span class="sd">"""</span> <span class="sd"> Box-Cox power transformation</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">plambda</span><span class="p">):</span> <span class="nb">super</span><span class="p">(</span><span class="n">BoxCox</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="bp">self</span><span class="o">.</span><span class="n">plambda</span> <span class="o">=</span> <span class="n">plambda</span> <span class="nd">@property</span> <span class="k">def</span> <span class="nf">parameters</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">plambda</span> <div class="viewcode-block" id="BoxCox.apply"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Transformations.BoxCox.apply">[docs]</a> <span class="k">def</span> <span class="nf">apply</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="n">param</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">plambda</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span> <span class="n">modified</span> <span class="o">=</span> <span class="p">[(</span><span class="n">dat</span> <span class="o">**</span> <span class="bp">self</span><span class="o">.</span><span class="n">plambda</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">plambda</span> <span class="k">for</span> <span class="n">dat</span> <span class="ow">in</span> <span class="n">data</span><span class="p">]</span> <span class="k">else</span><span class="p">:</span> <span class="n">modified</span> <span class="o">=</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">dat</span><span class="p">)</span> <span class="k">for</span> <span class="n">dat</span> <span class="ow">in</span> <span class="n">data</span><span class="p">]</span> <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">modified</span><span class="p">)</span></div> <div class="viewcode-block" id="BoxCox.inverse"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Transformations.BoxCox.inverse">[docs]</a> <span class="k">def</span> <span class="nf">inverse</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="n">param</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">plambda</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span> <span class="n">modified</span> <span class="o">=</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">dat</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">plambda</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="p">)</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">plambda</span> <span class="k">for</span> <span class="n">dat</span> <span class="ow">in</span> <span class="n">data</span><span class="p">]</span> <span class="k">else</span><span class="p">:</span> <span class="n">modified</span> <span class="o">=</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">dat</span><span class="p">)</span> <span class="k">for</span> <span class="n">dat</span> <span class="ow">in</span> <span class="n">data</span><span class="p">]</span> <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">modified</span><span class="p">)</span></div></div> <div class="viewcode-block" id="Z"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Transformations.Z">[docs]</a><span class="k">def</span> <span class="nf">Z</span><span class="p">(</span><span class="n">original</span><span class="p">):</span> <span class="n">mu</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">original</span><span class="p">)</span> <span class="n">sigma</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">std</span><span class="p">(</span><span class="n">original</span><span class="p">)</span> <span class="n">z</span> <span class="o">=</span> <span class="p">[(</span><span class="n">k</span> <span class="o">-</span> <span class="n">mu</span><span class="p">)</span><span class="o">/</span><span class="n">sigma</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">original</span><span class="p">]</span> <span class="k">return</span> <span class="n">z</span></div> <span class="c1"># retrieved from Sadaei and Lee (2014) - Multilayer Stock ForecastingModel Using Fuzzy Time Series</span> <div class="viewcode-block" id="roi"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Transformations.roi">[docs]</a><span class="k">def</span> <span class="nf">roi</span><span class="p">(</span><span class="n">original</span><span class="p">):</span> <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">original</span><span class="p">)</span> <span class="n">roi</span> <span class="o">=</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">):</span> <span class="n">roi</span><span class="o">.</span><span class="n">append</span><span class="p">(</span> <span class="p">(</span><span class="n">original</span><span class="p">[</span><span class="n">t</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">original</span><span class="p">[</span><span class="n">t</span><span class="p">])</span><span class="o">/</span><span class="n">original</span><span class="p">[</span><span class="n">t</span><span class="p">]</span> <span class="p">)</span> <span class="k">return</span> <span class="n">roi</span></div> <div class="viewcode-block" id="smoothing"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Transformations.smoothing">[docs]</a><span class="k">def</span> <span class="nf">smoothing</span><span class="p">(</span><span class="n">original</span><span class="p">,</span> <span class="n">lags</span><span class="p">):</span> <span class="k">pass</span></div> <div class="viewcode-block" id="aggregate"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.Transformations.aggregate">[docs]</a><span class="k">def</span> <span class="nf">aggregate</span><span class="p">(</span><span class="n">original</span><span class="p">,</span> <span class="n">operation</span><span class="p">):</span> <span class="k">pass</span></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.4 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>