<!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.Util — 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.hyperparam.Util</h1><div class="highlight"><pre> <span></span><span class="sd">"""</span> <span class="sd">Common facilities for hyperparameter tunning</span> <span class="sd">"""</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="sd">"""</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"> """</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">"PRAGMA journal_mode = WAL"</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">"PRAGMA synchronous = NORMAL"</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="sd">"""</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"> """</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">'''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, 'Order' int, </span> <span class="s1"> Partitioner text, Partitions int, alpha real, lags text, </span> <span class="s1"> Measure text, Value real)'''</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="sd">"""</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"> """</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">"INSERT INTO hyperparam(Date, Dataset, Tag, Model, "</span> <span class="o">+</span> <span class="s2">"Transformation, mf, 'Order', Partitioner, Partitions, "</span> <span class="o">+</span> <span class="s2">"alpha, lags, Measure, Value) "</span> <span class="o">+</span> <span class="s2">"VALUES(datetime('now'),?,?,?,?,?,?,?,?,?,?,?,?)"</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> </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>