pyFTS/docs/build/html/_modules/pyFTS/hyperparam/Util.html

157 lines
9.2 KiB
HTML

<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>pyFTS.hyperparam.Util &#8212; pyFTS 1.7 documentation</title>
<link rel="stylesheet" type="text/css" href="../../../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../../../_static/bizstyle.css" />
<script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/bizstyle.js"></script>
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<!--[if lt IE 9]>
<script src="_static/css3-mediaqueries.js"></script>
<![endif]-->
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">pyFTS 1.7 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.hyperparam.Util</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyFTS.hyperparam.Util</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Common facilities for hyperparameter optimization</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">sqlite3</span>
<div class="viewcode-block" id="open_hyperparam_db"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Util.open_hyperparam_db">[docs]</a><span class="k">def</span> <span class="nf">open_hyperparam_db</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Open a connection with a Sqlite database designed to store benchmark results.</span>
<span class="sd"> :param name: database filenem</span>
<span class="sd"> :return: a sqlite3 database connection</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">conn</span> <span class="o">=</span> <span class="n">sqlite3</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<span class="c1">#performance optimizations</span>
<span class="n">conn</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s2">&quot;PRAGMA journal_mode = WAL&quot;</span><span class="p">)</span>
<span class="n">conn</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s2">&quot;PRAGMA synchronous = NORMAL&quot;</span><span class="p">)</span>
<span class="n">create_hyperparam_tables</span><span class="p">(</span><span class="n">conn</span><span class="p">)</span>
<span class="k">return</span> <span class="n">conn</span></div>
<div class="viewcode-block" id="create_hyperparam_tables"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Util.create_hyperparam_tables">[docs]</a><span class="k">def</span> <span class="nf">create_hyperparam_tables</span><span class="p">(</span><span class="n">conn</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Create a sqlite3 table designed to store benchmark results.</span>
<span class="sd"> :param conn: a sqlite3 database connection</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">c</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">cursor</span><span class="p">()</span>
<span class="n">c</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">&#39;&#39;&#39;CREATE TABLE if not exists hyperparam(</span>
<span class="s1"> ID integer primary key, Date int, Dataset text, Tag text, </span>
<span class="s1"> Model text, Transformation text, mf text, &#39;Order&#39; int, </span>
<span class="s1"> Partitioner text, Partitions int, alpha real, lags text, </span>
<span class="s1"> Measure text, Value real)&#39;&#39;&#39;</span><span class="p">)</span>
<span class="n">conn</span><span class="o">.</span><span class="n">commit</span><span class="p">()</span></div>
<div class="viewcode-block" id="insert_hyperparam"><a class="viewcode-back" href="../../../pyFTS.hyperparam.html#pyFTS.hyperparam.Util.insert_hyperparam">[docs]</a><span class="k">def</span> <span class="nf">insert_hyperparam</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">conn</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Insert benchmark data on database</span>
<span class="sd"> :param data: a tuple with the benchmark data with format:</span>
<span class="sd"> Dataset: Identify on which dataset the dataset was performed</span>
<span class="sd"> Tag: a user defined word that indentify a benchmark set</span>
<span class="sd"> Model: FTS model</span>
<span class="sd"> Transformation: The name of data transformation, if one was used</span>
<span class="sd"> mf: membership function</span>
<span class="sd"> Order: the order of the FTS method</span>
<span class="sd"> Partitioner: UoD partitioning scheme</span>
<span class="sd"> Partitions: Number of partitions</span>
<span class="sd"> alpha: alpha cut</span>
<span class="sd"> lags: lags</span>
<span class="sd"> Measure: accuracy measure</span>
<span class="sd"> Value: the measure value</span>
<span class="sd"> :param conn: a sqlite3 database connection</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">c</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">cursor</span><span class="p">()</span>
<span class="n">c</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s2">&quot;INSERT INTO hyperparam(Date, Dataset, Tag, Model, &quot;</span>
<span class="o">+</span> <span class="s2">&quot;Transformation, mf, &#39;Order&#39;, Partitioner, Partitions, &quot;</span>
<span class="o">+</span> <span class="s2">&quot;alpha, lags, Measure, Value) &quot;</span>
<span class="o">+</span> <span class="s2">&quot;VALUES(datetime(&#39;now&#39;),?,?,?,?,?,?,?,?,?,?,?,?)&quot;</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
<span class="n">conn</span><span class="o">.</span><span class="n">commit</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> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">pyFTS.hyperparam.Util</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2022, Machine Intelligence and Data Science Laboratory - UFMG - Brazil.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.3.2.
</div>
</body>
</html>