Documentation update

This commit is contained in:
Petrônio Cândido 2019-04-09 17:14:51 -03:00
parent 59f68801a3
commit df047661b9
8 changed files with 15 additions and 259 deletions

Binary file not shown.

View File

@ -112,7 +112,6 @@
<li><a href="pyFTS/data/rossler.html">pyFTS.data.rossler</a></li>
<li><a href="pyFTS/data/sunspots.html">pyFTS.data.sunspots</a></li>
<li><a href="pyFTS/distributed/spark.html">pyFTS.distributed.spark</a></li>
<li><a href="pyFTS/hyperparam/GridSearch.html">pyFTS.hyperparam.GridSearch</a></li>
<li><a href="pyFTS/hyperparam/Util.html">pyFTS.hyperparam.Util</a></li>
<li><a href="pyFTS/models/chen.html">pyFTS.models.chen</a></li>
<li><a href="pyFTS/models/cheng.html">pyFTS.models.cheng</a></li>

View File

@ -1,250 +0,0 @@
<!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.hyperparam.GridSearch &#8212; 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> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</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.hyperparam.GridSearch</h1><div class="highlight"><pre>
<span></span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="k">import</span> <span class="n">Util</span><span class="p">,</span> <span class="n">Membership</span>
<span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="k">import</span> <span class="n">hofts</span>
<span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="k">import</span> <span class="n">Grid</span><span class="p">,</span> <span class="n">Entropy</span>
<span class="kn">from</span> <span class="nn">pyFTS.benchmarks</span> <span class="k">import</span> <span class="n">Measures</span>
<span class="kn">from</span> <span class="nn">pyFTS.hyperparam</span> <span class="k">import</span> <span class="n">Util</span> <span class="k">as</span> <span class="n">hUtil</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">dispy</span>
<span class="kn">from</span> <span class="nn">itertools</span> <span class="k">import</span> <span class="n">product</span>
<div class="viewcode-block" id="dict_individual"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.GridSearch.dict_individual">[docs]</a><span class="k">def</span> <span class="nf">dict_individual</span><span class="p">(</span><span class="n">mf</span><span class="p">,</span> <span class="n">partitioner</span><span class="p">,</span> <span class="n">partitions</span><span class="p">,</span> <span class="n">order</span><span class="p">,</span> <span class="n">lags</span><span class="p">,</span> <span class="n">alpha_cut</span><span class="p">):</span>
<span class="k">return</span> <span class="p">{</span>
<span class="s1">&#39;mf&#39;</span><span class="p">:</span> <span class="n">mf</span><span class="p">,</span>
<span class="s1">&#39;partitioner&#39;</span><span class="p">:</span> <span class="n">partitioner</span><span class="p">,</span>
<span class="s1">&#39;npart&#39;</span><span class="p">:</span> <span class="n">partitions</span><span class="p">,</span>
<span class="s1">&#39;alpha&#39;</span><span class="p">:</span> <span class="n">alpha_cut</span><span class="p">,</span>
<span class="s1">&#39;order&#39;</span><span class="p">:</span> <span class="n">order</span><span class="p">,</span>
<span class="s1">&#39;lags&#39;</span><span class="p">:</span> <span class="n">lags</span>
<span class="p">}</span></div>
<div class="viewcode-block" id="cluster_method"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.GridSearch.cluster_method">[docs]</a><span class="k">def</span> <span class="nf">cluster_method</span><span class="p">(</span><span class="n">individual</span><span class="p">,</span> <span class="n">train</span><span class="p">,</span> <span class="n">test</span><span class="p">):</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="k">import</span> <span class="n">Util</span><span class="p">,</span> <span class="n">Membership</span>
<span class="kn">from</span> <span class="nn">pyFTS.models</span> <span class="k">import</span> <span class="n">hofts</span>
<span class="kn">from</span> <span class="nn">pyFTS.partitioners</span> <span class="k">import</span> <span class="n">Grid</span><span class="p">,</span> <span class="n">Entropy</span>
<span class="kn">from</span> <span class="nn">pyFTS.benchmarks</span> <span class="k">import</span> <span class="n">Measures</span>
<span class="k">if</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;mf&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">mf</span> <span class="o">=</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trimf</span>
<span class="k">elif</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;mf&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
<span class="n">mf</span> <span class="o">=</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trapmf</span>
<span class="k">elif</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;mf&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">3</span> <span class="ow">and</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;partitioner&#39;</span><span class="p">]</span> <span class="o">!=</span> <span class="mi">2</span><span class="p">:</span>
<span class="n">mf</span> <span class="o">=</span> <span class="n">Membership</span><span class="o">.</span><span class="n">gaussmf</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">mf</span> <span class="o">=</span> <span class="n">Membership</span><span class="o">.</span><span class="n">trimf</span>
<span class="k">if</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;partitioner&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">partitioner</span> <span class="o">=</span> <span class="n">Grid</span><span class="o">.</span><span class="n">GridPartitioner</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">train</span><span class="p">,</span> <span class="n">npart</span><span class="o">=</span><span class="n">individual</span><span class="p">[</span><span class="s1">&#39;npart&#39;</span><span class="p">],</span> <span class="n">func</span><span class="o">=</span><span class="n">mf</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;partitioner&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
<span class="n">npart</span> <span class="o">=</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;npart&#39;</span><span class="p">]</span> <span class="k">if</span> <span class="n">individual</span><span class="p">[</span><span class="s1">&#39;npart&#39;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">10</span> <span class="k">else</span> <span class="mi">10</span>
<span class="n">partitioner</span> <span class="o">=</span> <span class="n">Entropy</span><span class="o">.</span><span class="n">EntropyPartitioner</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">train</span><span class="p">,</span> <span class="n">npart</span><span class="o">=</span><span class="n">npart</span><span class="p">,</span> <span class="n">func</span><span class="o">=</span><span class="n">mf</span><span class="p">)</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">hofts</span><span class="o">.</span><span class="n">WeightedHighOrderFTS</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="n">lags</span><span class="o">=</span><span class="n">individual</span><span class="p">[</span><span class="s1">&#39;lags&#39;</span><span class="p">],</span>
<span class="n">alpha_cut</span><span class="o">=</span><span class="n">individual</span><span class="p">[</span><span class="s1">&#39;alpha&#39;</span><span class="p">],</span>
<span class="n">order</span><span class="o">=</span><span class="n">individual</span><span class="p">[</span><span class="s1">&#39;order&#39;</span><span class="p">])</span>
<span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">train</span><span class="p">)</span>
<span class="n">rmse</span><span class="p">,</span> <span class="n">mape</span><span class="p">,</span> <span class="n">u</span> <span class="o">=</span> <span class="n">Measures</span><span class="o">.</span><span class="n">get_point_statistics</span><span class="p">(</span><span class="n">test</span><span class="p">,</span> <span class="n">model</span><span class="p">)</span>
<span class="n">size</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">model</span><span class="p">)</span>
<span class="k">return</span> <span class="n">individual</span><span class="p">,</span> <span class="n">rmse</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">mape</span><span class="p">,</span> <span class="n">u</span></div>
<div class="viewcode-block" id="process_jobs"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.GridSearch.process_jobs">[docs]</a><span class="k">def</span> <span class="nf">process_jobs</span><span class="p">(</span><span class="n">jobs</span><span class="p">,</span> <span class="n">datasetname</span><span class="p">,</span> <span class="n">conn</span><span class="p">):</span>
<span class="k">for</span> <span class="n">job</span> <span class="ow">in</span> <span class="n">jobs</span><span class="p">:</span>
<span class="n">result</span><span class="p">,</span> <span class="n">rmse</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">mape</span><span class="p">,</span> <span class="n">u</span> <span class="o">=</span> <span class="n">job</span><span class="p">()</span>
<span class="k">if</span> <span class="n">job</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="n">dispy</span><span class="o">.</span><span class="n">DispyJob</span><span class="o">.</span><span class="n">Finished</span> <span class="ow">and</span> <span class="n">result</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Processing result of </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">result</span><span class="p">))</span>
<span class="n">metrics</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;rmse&#39;</span><span class="p">:</span> <span class="n">rmse</span><span class="p">,</span> <span class="s1">&#39;size&#39;</span><span class="p">:</span> <span class="n">size</span><span class="p">,</span> <span class="s1">&#39;mape&#39;</span><span class="p">:</span> <span class="n">mape</span><span class="p">,</span> <span class="s1">&#39;u&#39;</span><span class="p">:</span> <span class="n">u</span> <span class="p">}</span>
<span class="k">for</span> <span class="n">metric</span> <span class="ow">in</span> <span class="n">metrics</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="n">record</span> <span class="o">=</span> <span class="p">(</span><span class="n">datasetname</span><span class="p">,</span> <span class="s1">&#39;GridSearch&#39;</span><span class="p">,</span> <span class="s1">&#39;WHOFTS&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">result</span><span class="p">[</span><span class="s1">&#39;mf&#39;</span><span class="p">],</span>
<span class="n">result</span><span class="p">[</span><span class="s1">&#39;order&#39;</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="s1">&#39;partitioner&#39;</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="s1">&#39;npart&#39;</span><span class="p">],</span>
<span class="n">result</span><span class="p">[</span><span class="s1">&#39;alpha&#39;</span><span class="p">],</span> <span class="nb">str</span><span class="p">(</span><span class="n">result</span><span class="p">[</span><span class="s1">&#39;lags&#39;</span><span class="p">]),</span> <span class="n">metric</span><span class="p">,</span> <span class="n">metrics</span><span class="p">[</span><span class="n">metric</span><span class="p">])</span>
<span class="nb">print</span><span class="p">(</span><span class="n">record</span><span class="p">)</span>
<span class="n">hUtil</span><span class="o">.</span><span class="n">insert_hyperparam</span><span class="p">(</span><span class="n">record</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">job</span><span class="o">.</span><span class="n">exception</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">job</span><span class="o">.</span><span class="n">stdout</span><span class="p">)</span></div>
<div class="viewcode-block" id="execute"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.GridSearch.execute">[docs]</a><span class="k">def</span> <span class="nf">execute</span><span class="p">(</span><span class="n">hyperparams</span><span class="p">,</span> <span class="n">datasetname</span><span class="p">,</span> <span class="n">train</span><span class="p">,</span> <span class="n">test</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">nodes</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="s1">&#39;nodes&#39;</span><span class="p">,[</span><span class="s1">&#39;127.0.0.1&#39;</span><span class="p">])</span>
<span class="n">individuals</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="s1">&#39;lags&#39;</span> <span class="ow">in</span> <span class="n">hyperparams</span><span class="p">:</span>
<span class="n">lags</span> <span class="o">=</span> <span class="n">hyperparams</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;lags&#39;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">lags</span> <span class="o">=</span> <span class="p">[</span><span class="n">k</span> <span class="k">for</span> <span class="n">k</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">50</span><span class="p">)]</span>
<span class="n">keys_sorted</span> <span class="o">=</span> <span class="p">[</span><span class="n">k</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">hyperparams</span><span class="o">.</span><span class="n">keys</span><span class="p">())]</span>
<span class="n">index</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">k</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="nb">len</span><span class="p">(</span><span class="n">keys_sorted</span><span class="p">)):</span>
<span class="n">index</span><span class="p">[</span><span class="n">keys_sorted</span><span class="p">[</span><span class="n">k</span><span class="p">]]</span> <span class="o">=</span> <span class="n">k</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Evaluation order: </span><span class="se">\n</span><span class="s2"> </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">index</span><span class="p">))</span>
<span class="n">hp_values</span> <span class="o">=</span> <span class="p">[</span>
<span class="p">[</span><span class="n">v</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">hyperparams</span><span class="p">[</span><span class="n">hp</span><span class="p">]]</span>
<span class="k">for</span> <span class="n">hp</span> <span class="ow">in</span> <span class="n">keys_sorted</span>
<span class="p">]</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Evaluation values: </span><span class="se">\n</span><span class="s2"> </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">hp_values</span><span class="p">))</span>
<span class="n">cluster</span><span class="p">,</span> <span class="n">http_server</span> <span class="o">=</span> <span class="n">Util</span><span class="o">.</span><span class="n">start_dispy_cluster</span><span class="p">(</span><span class="n">cluster_method</span><span class="p">,</span> <span class="n">nodes</span><span class="o">=</span><span class="n">nodes</span><span class="p">)</span>
<span class="n">conn</span> <span class="o">=</span> <span class="n">hUtil</span><span class="o">.</span><span class="n">open_hyperparam_db</span><span class="p">(</span><span class="s1">&#39;hyperparam.db&#39;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">instance</span> <span class="ow">in</span> <span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">hp_values</span><span class="p">):</span>
<span class="n">partitions</span> <span class="o">=</span> <span class="n">instance</span><span class="p">[</span><span class="n">index</span><span class="p">[</span><span class="s1">&#39;partitions&#39;</span><span class="p">]]</span>
<span class="n">partitioner</span> <span class="o">=</span> <span class="n">instance</span><span class="p">[</span><span class="n">index</span><span class="p">[</span><span class="s1">&#39;partitioner&#39;</span><span class="p">]]</span>
<span class="n">mf</span> <span class="o">=</span> <span class="n">instance</span><span class="p">[</span><span class="n">index</span><span class="p">[</span><span class="s1">&#39;mf&#39;</span><span class="p">]]</span>
<span class="n">alpha_cut</span> <span class="o">=</span> <span class="n">instance</span><span class="p">[</span><span class="n">index</span><span class="p">[</span><span class="s1">&#39;alpha&#39;</span><span class="p">]]</span>
<span class="n">order</span> <span class="o">=</span> <span class="n">instance</span><span class="p">[</span><span class="n">index</span><span class="p">[</span><span class="s1">&#39;order&#39;</span><span class="p">]]</span>
<span class="n">count</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">lag1</span> <span class="ow">in</span> <span class="n">lags</span><span class="p">:</span> <span class="c1"># o é o lag1</span>
<span class="n">_lags</span> <span class="o">=</span> <span class="p">[</span><span class="n">lag1</span><span class="p">]</span>
<span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="k">if</span> <span class="n">order</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
<span class="k">for</span> <span class="n">lag2</span> <span class="ow">in</span> <span class="n">lags</span><span class="p">:</span> <span class="c1"># o é o lag1</span>
<span class="n">_lags2</span> <span class="o">=</span> <span class="p">[</span><span class="n">lag1</span><span class="p">,</span> <span class="n">lag1</span><span class="o">+</span><span class="n">lag2</span><span class="p">]</span>
<span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="k">if</span> <span class="n">order</span> <span class="o">&gt;</span> <span class="mi">2</span><span class="p">:</span>
<span class="k">for</span> <span class="n">lag3</span> <span class="ow">in</span> <span class="n">lags</span><span class="p">:</span> <span class="c1"># o é o lag1</span>
<span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="n">_lags3</span> <span class="o">=</span> <span class="p">[</span><span class="n">lag1</span><span class="p">,</span> <span class="n">lag1</span> <span class="o">+</span> <span class="n">lag2</span><span class="p">,</span> <span class="n">lag1</span> <span class="o">+</span> <span class="n">lag2</span><span class="o">+</span><span class="n">lag3</span> <span class="p">]</span>
<span class="n">individuals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dict_individual</span><span class="p">(</span><span class="n">mf</span><span class="p">,</span> <span class="n">partitioner</span><span class="p">,</span> <span class="n">partitions</span><span class="p">,</span> <span class="n">order</span><span class="p">,</span> <span class="n">_lags3</span><span class="p">,</span> <span class="n">alpha_cut</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">individuals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
<span class="n">dict_individual</span><span class="p">(</span><span class="n">mf</span><span class="p">,</span> <span class="n">partitioner</span><span class="p">,</span> <span class="n">partitions</span><span class="p">,</span> <span class="n">order</span><span class="p">,</span> <span class="n">_lags2</span><span class="p">,</span> <span class="n">alpha_cut</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">individuals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dict_individual</span><span class="p">(</span><span class="n">mf</span><span class="p">,</span> <span class="n">partitioner</span><span class="p">,</span> <span class="n">partitions</span><span class="p">,</span> <span class="n">order</span><span class="p">,</span> <span class="n">_lags</span><span class="p">,</span> <span class="n">alpha_cut</span><span class="p">))</span>
<span class="k">if</span> <span class="n">count</span> <span class="o">&gt;</span> <span class="mi">50</span><span class="p">:</span>
<span class="n">jobs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">ind</span> <span class="ow">in</span> <span class="n">individuals</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Testing individual </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ind</span><span class="p">))</span>
<span class="n">job</span> <span class="o">=</span> <span class="n">cluster</span><span class="o">.</span><span class="n">submit</span><span class="p">(</span><span class="n">ind</span><span class="p">,</span> <span class="n">train</span><span class="p">,</span> <span class="n">test</span><span class="p">)</span>
<span class="n">jobs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">job</span><span class="p">)</span>
<span class="n">process_jobs</span><span class="p">(</span><span class="n">jobs</span><span class="p">,</span> <span class="n">datasetname</span><span class="p">,</span> <span class="n">conn</span><span class="p">)</span>
<span class="n">count</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">individuals</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">Util</span><span class="o">.</span><span class="n">stop_dispy_cluster</span><span class="p">(</span><span class="n">cluster</span><span class="p">,</span> <span class="n">http_server</span><span class="p">)</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> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; 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>

View File

@ -164,7 +164,7 @@
<li class="toctree-l4"><a class="reference internal" href="pyFTS.hyperparam.html#module-pyFTS.hyperparam">Module contents</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.hyperparam.html#submodules">Submodules</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.hyperparam.html#module-pyFTS.hyperparam.Util">pyFTS.hyperparam.Util module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.hyperparam.html#module-pyFTS.hyperparam.GridSearch">pyFTS.hyperparam.GridSearch module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.hyperparam.html#pyfts-hyperparam-gridsearch-module">pyFTS.hyperparam.GridSearch module</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyFTS.hyperparam.html#pyfts-hyperparam-evolutionary-module">pyFTS.hyperparam.Evolutionary module</a></li>
</ul>
</li>

File diff suppressed because one or more lines are too long

View File

@ -121,13 +121,12 @@ def fuzzyfy(data, partitioner, **kwargs):
:param data: input value to be fuzzyfied
:param partitioner: a trained pyFTS.partitioners.Partitioner object
:param kwargs: dict, optional arguments
:keyword alpha_cut: the minimal membership value to be considered on fuzzyfication (only for mode='sets')
:keyword method: the fuzzyfication method (fuzzy: all fuzzy memberships, maximum: only the maximum membership)
:keyword mode: the fuzzyfication mode (sets: return the fuzzy sets names, vector: return a vector with the membership
values for all fuzzy sets, both: return a list with tuples (fuzzy set, membership value) )
:returns a list with the fuzzyfied values, depending on the mode
"""
alpha_cut = kwargs.get('alpha_cut', 0.)
mode = kwargs.get('mode', 'sets')

View File

@ -127,7 +127,7 @@ class Partitioner(object):
def fuzzyfy(self, data, **kwargs):
"""
A general method for fuzzyfication.
Fuzzyfy the input data according to this partitioner fuzzy sets.
:param data: input value to be fuzzyfied
:keyword alpha_cut: the minimal membership value to be considered on fuzzyfication (only for mode='sets')
@ -178,6 +178,14 @@ class Partitioner(object):
return sets
def check_bounds(self, data):
'''
Check if the input data is outside the known Universe of Discourse and, if it is, round it to the closest
fuzzy set.
:param data: input data to be verified
:return: the index of the closest fuzzy set when data is outside de universe of discourse or None if
the data is inside the UoD.
'''
if data < self.min:
return 0
elif data > self.max:

View File

@ -7,7 +7,7 @@ from pyFTS.probabilistic import ProbabilityDistribution
class Mixture(ProbabilityDistribution.ProbabilityDistribution):
"""
Mix two or more Probability Distributions smoothing them with weights.
"""
def __init__(self, type="mixture", **kwargs):
self.models = []
@ -21,7 +21,7 @@ class Mixture(ProbabilityDistribution.ProbabilityDistribution):
if not isinstance(values, list):
values = [values]
for ct, m in enumerate(self.models):
#for ct, m in enumerate(self.models):
probs = [m.density(values) ]
#probs = [m.density(values) ]