160 lines
13 KiB
HTML
160 lines
13 KiB
HTML
|
|
|
|
<!doctype html>
|
|
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>pyFTS.common.tree — 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> »</li>
|
|
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> »</li>
|
|
<li class="nav-item nav-item-this"><a href="">pyFTS.common.tree</a></li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="document">
|
|
<div class="documentwrapper">
|
|
<div class="bodywrapper">
|
|
<div class="body" role="main">
|
|
|
|
<h1>Source code for pyFTS.common.tree</h1><div class="highlight"><pre>
|
|
<span></span><span class="sd">"""</span>
|
|
<span class="sd">Tree data structure</span>
|
|
<span class="sd">"""</span>
|
|
|
|
<span class="kn">from</span> <span class="nn">pyFTS</span> <span class="k">import</span> <span class="o">*</span>
|
|
<span class="kn">from</span> <span class="nn">functools</span> <span class="k">import</span> <span class="n">reduce</span>
|
|
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
|
|
|
|
|
|
<div class="viewcode-block" id="FLRGTreeNode"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.tree.FLRGTreeNode">[docs]</a><span class="k">class</span> <span class="nc">FLRGTreeNode</span><span class="p">:</span>
|
|
<span class="sd">"""</span>
|
|
<span class="sd"> Tree node for</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">value</span><span class="p">):</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">isRoot</span> <span class="o">=</span> <span class="kc">False</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">children</span> <span class="o">=</span> <span class="p">[]</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">value</span>
|
|
|
|
<div class="viewcode-block" id="FLRGTreeNode.appendChild"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.tree.FLRGTreeNode.appendChild">[docs]</a> <span class="k">def</span> <span class="nf">appendChild</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">child</span><span class="p">):</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">children</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">child</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="FLRGTreeNode.getChildren"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.tree.FLRGTreeNode.getChildren">[docs]</a> <span class="k">def</span> <span class="nf">getChildren</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
|
<span class="k">for</span> <span class="n">child</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">children</span><span class="p">:</span>
|
|
<span class="k">yield</span> <span class="n">child</span></div>
|
|
|
|
<div class="viewcode-block" id="FLRGTreeNode.paths"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.tree.FLRGTreeNode.paths">[docs]</a> <span class="k">def</span> <span class="nf">paths</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">acc</span><span class="o">=</span><span class="p">[]):</span>
|
|
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">children</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
|
|
<span class="k">yield</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">]</span> <span class="o">+</span> <span class="n">acc</span>
|
|
|
|
<span class="k">for</span> <span class="n">child</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">children</span><span class="p">:</span>
|
|
<span class="k">for</span> <span class="n">leaf_path</span> <span class="ow">in</span> <span class="n">child</span><span class="o">.</span><span class="n">paths</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">]</span> <span class="o">+</span> <span class="n">acc</span><span class="p">):</span> <span class="c1"># these two</span>
|
|
<span class="k">yield</span> <span class="n">leaf_path</span></div>
|
|
|
|
<div class="viewcode-block" id="FLRGTreeNode.getStr"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.tree.FLRGTreeNode.getStr">[docs]</a> <span class="k">def</span> <span class="nf">getStr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">k</span><span class="p">):</span>
|
|
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">isRoot</span><span class="p">:</span>
|
|
<span class="n">tmp</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">value</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="s2">"</span><span class="se">\\</span><span class="s2">"</span> <span class="o">+</span> <span class="p">(</span><span class="s2">"-"</span> <span class="o">*</span> <span class="n">k</span><span class="p">)</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">value</span><span class="p">)</span>
|
|
<span class="k">for</span> <span class="n">child</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">getChildren</span><span class="p">():</span>
|
|
<span class="n">tmp</span> <span class="o">=</span> <span class="n">tmp</span> <span class="o">+</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">"</span> <span class="o">+</span> <span class="n">child</span><span class="o">.</span><span class="n">getStr</span><span class="p">(</span><span class="n">k</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
|
|
<span class="k">return</span> <span class="n">tmp</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="n">getStr</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span></div>
|
|
|
|
|
|
<div class="viewcode-block" id="FLRGTree"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.tree.FLRGTree">[docs]</a><span class="k">class</span> <span class="nc">FLRGTree</span><span class="p">:</span>
|
|
<span class="sd">"""Represents a FLRG set with a tree structure"""</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="bp">self</span><span class="o">.</span><span class="n">root</span> <span class="o">=</span> <span class="n">FLRGTreeNode</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span></div>
|
|
|
|
|
|
<div class="viewcode-block" id="flat"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.tree.flat">[docs]</a><span class="k">def</span> <span class="nf">flat</span><span class="p">(</span><span class="n">dados</span><span class="p">):</span>
|
|
<span class="k">for</span> <span class="n">inst</span> <span class="ow">in</span> <span class="n">dados</span><span class="p">:</span>
|
|
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">inst</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)):</span>
|
|
<span class="n">x</span> <span class="o">=</span> <span class="n">flat</span><span class="p">(</span><span class="n">inst</span><span class="p">)</span>
|
|
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">x</span><span class="p">:</span>
|
|
<span class="k">yield</span> <span class="n">k</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">yield</span> <span class="n">inst</span></div>
|
|
|
|
|
|
<div class="viewcode-block" id="build_tree_without_order"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.tree.build_tree_without_order">[docs]</a><span class="k">def</span> <span class="nf">build_tree_without_order</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">lags</span><span class="p">,</span> <span class="n">level</span><span class="p">):</span>
|
|
|
|
<span class="k">if</span> <span class="n">level</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">lags</span><span class="p">:</span>
|
|
<span class="k">return</span>
|
|
|
|
<span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">lags</span><span class="p">[</span><span class="n">level</span><span class="p">]:</span>
|
|
<span class="n">node</span><span class="o">.</span><span class="n">appendChild</span><span class="p">(</span><span class="n">FLRGTreeNode</span><span class="p">(</span><span class="n">s</span><span class="p">))</span>
|
|
|
|
<span class="k">for</span> <span class="n">child</span> <span class="ow">in</span> <span class="n">node</span><span class="o">.</span><span class="n">getChildren</span><span class="p">():</span>
|
|
<span class="n">build_tree_without_order</span><span class="p">(</span><span class="n">child</span><span class="p">,</span> <span class="n">lags</span><span class="p">,</span> <span class="n">level</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span></div>
|
|
</pre></div>
|
|
|
|
<div class="clearer"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
|
<div class="sphinxsidebarwrapper">
|
|
<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> »</li>
|
|
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> »</li>
|
|
<li class="nav-item nav-item-this"><a href="">pyFTS.common.tree</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="footer" role="contentinfo">
|
|
© Copyright 2022, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
|
|
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.5.0.
|
|
</div>
|
|
</body>
|
|
</html> |