Old engine for Continuous Time Bayesian Networks. Superseded by reCTBN. 🐍
https://github.com/madlabunimib/PyCTBN
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
743 lines
61 KiB
743 lines
61 KiB
|
|
|
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
|
<html xml:lang="" lang="" version="-//W3C//DTD XHTML 1.1//EN" xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
|
|
<title>PyCTBN.PyCTBN.utility package — PyCTBN 2.0 documentation</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<link href='https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'/>
|
|
<link rel="stylesheet" href="_static/css/pdj.css" type="text/css" />
|
|
|
|
|
|
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
|
|
|
<link rel="stylesheet" href="_static/css/pdj.css" type="text/css" />
|
|
|
|
|
|
|
|
|
|
|
|
<link rel="index" title="Index"
|
|
href="genindex.html"/>
|
|
<link rel="search" title="Search" href="search.html"/>
|
|
<link rel="top" title="PyCTBN 2.0 documentation" href="index.html"/>
|
|
<link rel="up" title="PyCTBN.PyCTBN package" href="PyCTBN.PyCTBN.html"/>
|
|
<link rel="next" title="Examples" href="examples.html"/>
|
|
<link rel="prev" title="PyCTBN.PyCTBN.structure_graph package" href="PyCTBN.PyCTBN.structure_graph.html"/>
|
|
|
|
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
|
<meta http-equiv="cache-control" content="public" />
|
|
<meta name="robots" content="follow, all" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<!-- Add jQuery library -->
|
|
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
|
|
|
|
</head>
|
|
|
|
<body class="wy-body-for-nav" role="document">
|
|
|
|
<div class="wy-grid-for-nav">
|
|
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
|
|
<div class="wy-side-nav-search">
|
|
<a href="index.html" class="fa fa-home"> PyCTBN </a>
|
|
<div role="search">
|
|
<form id ="rtd-search-form" class="wy-form"
|
|
action="search.html" method="get">
|
|
<input type="text" name="q" placeholder="Search docs" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
|
|
|
|
|
|
|
|
<p class="caption"><span class="caption-text">Contents:</span></p>
|
|
<ul class="current">
|
|
<li class="toctree-l1 current"><a class="reference internal" href="PyCTBN.PyCTBN.html">PyCTBN.PyCTBN package</a><ul class="current">
|
|
<li class="toctree-l2 current"><a class="reference internal" href="PyCTBN.PyCTBN.html#subpackages">Subpackages</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="PyCTBN.PyCTBN.html#module-PyCTBN.PyCTBN">Module contents</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l1"><a class="reference internal" href="examples.html">Examples</a><ul>
|
|
<li class="toctree-l2"><a class="reference internal" href="examples.html#installation-usage">Installation/Usage</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="examples.html#implementing-your-own-data-importer">Implementing your own data importer</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="examples.html#parameters-estimation-example">Parameters Estimation Example</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="examples.html#structure-estimation-example">Structure Estimation Example</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</nav>
|
|
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
|
|
|
|
<nav class="wy-nav-top" id="barra-mobile" role="navigation" aria-label="top navigation">
|
|
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
|
<a href="#">Porão do Juca</a>
|
|
</nav>
|
|
|
|
<div class="wy-nav-content">
|
|
<div class="fundo-claro">
|
|
</div>
|
|
<div class="fundo-escuro">
|
|
</div>
|
|
|
|
<div class="rst-content">
|
|
<div role="navigation" aria-label="breadcrumbs navigation">
|
|
|
|
<!-- <ul class="wy-breadcrumbs"> -->
|
|
<!-- <li><a href="#">Docs</a> »</li> -->
|
|
|
|
<!-- <li>Features</li> -->
|
|
<!-- <li class="wy-breadcrumbs-aside"> -->
|
|
|
|
<!-- <a href="_sources/index.txt" rel="nofollow"> View page source</a> -->
|
|
|
|
<!-- </li> -->
|
|
<!-- </ul> -->
|
|
<!-- <hr/> -->
|
|
</div>
|
|
|
|
<div role="main" class="">
|
|
|
|
<div id="content" class="hfeed entry-container hentry">
|
|
<div class="section" id="pyctbn-pyctbn-utility-package">
|
|
<h1>PyCTBN.PyCTBN.utility package<a class="headerlink" href="#pyctbn-pyctbn-utility-package" title="Permalink to this headline">¶</a></h1>
|
|
<div class="section" id="submodules">
|
|
<h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this headline">¶</a></h2>
|
|
</div>
|
|
<div class="section" id="module-PyCTBN.PyCTBN.utility.abstract_exporter">
|
|
<span id="pyctbn-pyctbn-utility-abstract-exporter-module"></span><h2>PyCTBN.PyCTBN.utility.abstract_exporter module<a class="headerlink" href="#module-PyCTBN.PyCTBN.utility.abstract_exporter" title="Permalink to this headline">¶</a></h2>
|
|
<dl class="py class">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.abstract_exporter.AbstractExporter">
|
|
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">PyCTBN.PyCTBN.utility.abstract_exporter.</span></span><span class="sig-name descname"><span class="pre">AbstractExporter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">variables</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">pandas.core.frame.DataFrame</span><span class="p"><span class="pre">]</span></span></span> <span class="o"><span class="pre">=</span></span> <span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dyn_str</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">pandas.core.frame.DataFrame</span><span class="p"><span class="pre">]</span></span></span> <span class="o"><span class="pre">=</span></span> <span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dyn_cims</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">dict</span><span class="p"><span class="pre">]</span></span></span> <span class="o"><span class="pre">=</span></span> <span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.abstract_exporter.AbstractExporter" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">abc.ABC</span></code></p>
|
|
<p>Abstract class that exposes the methods to save in json format a network information
|
|
along with one or more trajectories generated basing on it</p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><ul class="simple">
|
|
<li><p><strong>_variables</strong> (<em>pandas.DataFrame</em>) – Dataframe containing the nodes labels and cardinalities</p></li>
|
|
<li><p><strong>_dyn_str</strong> (<em>pandas.DataFrame</em>) – Dataframe containing the structure of the network (edges)</p></li>
|
|
<li><p><strong>_dyn_cims</strong> (<em>dict</em>) – It contains, for every variable (label is the key), the SetOfCims object related to it</p></li>
|
|
<li><p><strong>_trajectories</strong> (<em>List</em>) – List of trajectories, that can be added subsequently</p></li>
|
|
</ul>
|
|
</dd>
|
|
</dl>
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.abstract_exporter.AbstractExporter.add_trajectory">
|
|
<span class="sig-name descname"><span class="pre">add_trajectory</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">trajectory</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">list</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.abstract_exporter.AbstractExporter.add_trajectory" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Add a new trajectory to the current list</p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><p><strong>trajectory</strong> (<em>pandas.DataFrame</em>) – The trajectory to add</p>
|
|
</dd>
|
|
</dl>
|
|
</dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.abstract_exporter.AbstractExporter.out_file">
|
|
<em class="property"><span class="pre">abstract</span> </em><span class="sig-name descname"><span class="pre">out_file</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.abstract_exporter.AbstractExporter.out_file" title="Permalink to this definition">¶</a></dt>
|
|
<dd><dl class="simple">
|
|
<dt>Create a file in current directory and write on it the previously added data </dt><dd><p>(variables, dyn_str, dyn_cims and trajectories)</p>
|
|
</dd>
|
|
</dl>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><p><strong>filename</strong> (<em>string</em>) – Name of the output file (it must include json extension)</p>
|
|
</dd>
|
|
</dl>
|
|
</dd></dl>
|
|
|
|
</dd></dl>
|
|
|
|
</div>
|
|
<div class="section" id="module-PyCTBN.PyCTBN.utility.abstract_importer">
|
|
<span id="pyctbn-pyctbn-utility-abstract-importer-module"></span><h2>PyCTBN.PyCTBN.utility.abstract_importer module<a class="headerlink" href="#module-PyCTBN.PyCTBN.utility.abstract_importer" title="Permalink to this headline">¶</a></h2>
|
|
<dl class="py class">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter">
|
|
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">PyCTBN.PyCTBN.utility.abstract_importer.</span></span><span class="sig-name descname"><span class="pre">AbstractImporter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">file_path</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></span> <span class="o"><span class="pre">=</span></span> <span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">trajectory_list</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">Union</span><span class="p"><span class="pre">[</span></span><span class="pre">pandas.core.frame.DataFrame</span><span class="p"><span class="pre">,</span> </span><span class="pre">numpy.ndarray</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></span> <span class="o"><span class="pre">=</span></span> <span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">variables</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">pandas.core.frame.DataFrame</span><span class="p"><span class="pre">]</span></span></span> <span class="o"><span class="pre">=</span></span> <span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">prior_net_structure</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">pandas.core.frame.DataFrame</span><span class="p"><span class="pre">]</span></span></span> <span class="o"><span class="pre">=</span></span> <span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">abc.ABC</span></code></p>
|
|
<p>Abstract class that exposes all the necessary methods to process the trajectories and the net structure.</p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><ul class="simple">
|
|
<li><p><strong>file_path</strong> (<em>str</em>) – the file path, or dataset name if you import already processed data</p></li>
|
|
<li><p><strong>trajectory_list</strong> (<em>typing.Union</em><em>[</em><em>pandas.DataFrame</em><em>, </em><em>numpy.ndarray</em><em>]</em>) – Dataframe or numpy array containing the concatenation of all the processed trajectories</p></li>
|
|
<li><p><strong>variables</strong> (<em>pandas.DataFrame</em>) – Dataframe containing the nodes labels and cardinalities</p></li>
|
|
</ul>
|
|
</dd>
|
|
<dt class="field-even">Prior_net_structure</dt>
|
|
<dd class="field-even"><p>Dataframe containing the structure of the network (edges)</p>
|
|
</dd>
|
|
<dt class="field-odd">_sorter</dt>
|
|
<dd class="field-odd"><p>A list containing the variables labels in the SAME order as the columns in <code class="docutils literal notranslate"><span class="pre">concatenated_samples</span></code></p>
|
|
</dd>
|
|
</dl>
|
|
<div class="admonition warning">
|
|
<p class="admonition-title">Warning</p>
|
|
<p>The parameters <code class="docutils literal notranslate"><span class="pre">variables</span></code> and <code class="docutils literal notranslate"><span class="pre">prior_net_structure</span></code> HAVE to be properly constructed
|
|
as Pandas Dataframes with the following structure:
|
|
Header of _df_structure = [From_Node | To_Node]
|
|
Header of _df_variables = [Variable_Label | Variable_Cardinality]
|
|
See the tutorial on how to construct a correct <code class="docutils literal notranslate"><span class="pre">concatenated_samples</span></code> Dataframe/ndarray.</p>
|
|
</div>
|
|
<div class="admonition note">
|
|
<p class="admonition-title">Note</p>
|
|
<p>See :class:<code class="docutils literal notranslate"><span class="pre">JsonImporter</span></code> for an example implementation</p>
|
|
</div>
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.build_list_of_samples_array">
|
|
<span class="sig-name descname"><span class="pre">build_list_of_samples_array</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">concatenated_sample</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">pandas.core.frame.DataFrame</span></span></em><span class="sig-paren">)</span> → <span class="pre">List</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.build_list_of_samples_array" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Builds a List containing the the delta times numpy array, and the complete transitions matrix</p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><p><strong>concatenated_sample</strong> (<em>pandas.Dataframe</em>) – the dataframe/array from which the time, and transitions matrix have to be extracted
|
|
and converted</p>
|
|
</dd>
|
|
<dt class="field-even">Returns</dt>
|
|
<dd class="field-even"><p>the resulting list of numpy arrays</p>
|
|
</dd>
|
|
<dt class="field-odd">Return type</dt>
|
|
<dd class="field-odd"><p>List</p>
|
|
</dd>
|
|
</dl>
|
|
</dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.build_sorter">
|
|
<em class="property"><span class="pre">abstract</span> </em><span class="sig-name descname"><span class="pre">build_sorter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">trajecory_header</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">object</span></span></em><span class="sig-paren">)</span> → <span class="pre">List</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.build_sorter" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Initializes the <code class="docutils literal notranslate"><span class="pre">_sorter</span></code> class member from a trajectory dataframe, exctracting the header of the frame
|
|
and keeping ONLY the variables symbolic labels, cutting out the time label in the header.</p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><p><strong>trajecory_header</strong> (<em>object</em>) – an object that will be used to define the header</p>
|
|
</dd>
|
|
<dt class="field-even">Returns</dt>
|
|
<dd class="field-even"><p>A list containing the processed header.</p>
|
|
</dd>
|
|
<dt class="field-odd">Return type</dt>
|
|
<dd class="field-odd"><p>List</p>
|
|
</dd>
|
|
</dl>
|
|
</dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.clear_concatenated_frame">
|
|
<span class="sig-name descname"><span class="pre">clear_concatenated_frame</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> → <span class="pre">None</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.clear_concatenated_frame" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Removes all values in the dataframe concatenated_samples.</p>
|
|
</dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.compute_row_delta_in_all_samples_frames">
|
|
<span class="sig-name descname"><span class="pre">compute_row_delta_in_all_samples_frames</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">df_samples_list</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">List</span></span></em><span class="sig-paren">)</span> → <span class="pre">None</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.compute_row_delta_in_all_samples_frames" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Calls the method <code class="docutils literal notranslate"><span class="pre">compute_row_delta_sigle_samples_frame</span></code> on every dataframe present in the list
|
|
<code class="docutils literal notranslate"><span class="pre">df_samples_list</span></code>.
|
|
Concatenates the result in the dataframe <code class="docutils literal notranslate"><span class="pre">concatanated_samples</span></code></p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><p><strong>df_samples_list</strong> (<em>List</em>) – the datframe’s list to be processed and concatenated</p>
|
|
</dd>
|
|
</dl>
|
|
<div class="admonition warning">
|
|
<p class="admonition-title">Warning</p>
|
|
<p>The Dataframe sample_frame has to follow the column structure of this header:
|
|
Header of sample_frame = [Time | Variable values]
|
|
The class member self._sorter HAS to be properly INITIALIZED (See class members definition doc)</p>
|
|
</div>
|
|
<div class="admonition note">
|
|
<p class="admonition-title">Note</p>
|
|
<p>After the call of this method the class member <code class="docutils literal notranslate"><span class="pre">concatanated_samples</span></code> will contain all processed
|
|
and merged trajectories</p>
|
|
</div>
|
|
</dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.compute_row_delta_sigle_samples_frame">
|
|
<span class="sig-name descname"><span class="pre">compute_row_delta_sigle_samples_frame</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sample_frame</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">pandas.core.frame.DataFrame</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">columns_header</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">List</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">shifted_cols_header</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">List</span></span></em><span class="sig-paren">)</span> → <span class="pre">pandas.core.frame.DataFrame</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.compute_row_delta_sigle_samples_frame" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Computes the difference between each value present in th time column.
|
|
Copies and shift by one position up all the values present in the remaining columns.</p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><ul class="simple">
|
|
<li><p><strong>sample_frame</strong> (<em>pandas.Dataframe</em>) – the traj to be processed</p></li>
|
|
<li><p><strong>columns_header</strong> (<em>List</em>) – the original header of sample_frame</p></li>
|
|
<li><p><strong>shifted_cols_header</strong> (<em>List</em>) – a copy of columns_header with changed names of the contents</p></li>
|
|
</ul>
|
|
</dd>
|
|
<dt class="field-even">Returns</dt>
|
|
<dd class="field-even"><p>The processed dataframe</p>
|
|
</dd>
|
|
<dt class="field-odd">Return type</dt>
|
|
<dd class="field-odd"><p>pandas.Dataframe</p>
|
|
</dd>
|
|
</dl>
|
|
<div class="admonition warning">
|
|
<p class="admonition-title">Warning</p>
|
|
<p>the Dataframe <code class="docutils literal notranslate"><span class="pre">sample_frame</span></code> has to follow the column structure of this header:
|
|
Header of sample_frame = [Time | Variable values]</p>
|
|
</div>
|
|
</dd></dl>
|
|
|
|
<dl class="py property">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.concatenated_samples">
|
|
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">concatenated_samples</span></span><em class="property"><span class="pre">:</span> <span class="pre">pandas.core.frame.DataFrame</span></em><a class="headerlink" href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.concatenated_samples" title="Permalink to this definition">¶</a></dt>
|
|
<dd></dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.dataset_id">
|
|
<em class="property"><span class="pre">abstract</span> </em><span class="sig-name descname"><span class="pre">dataset_id</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> → <span class="pre">object</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.dataset_id" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>If the original dataset contains multiple dataset, this method returns a unique id to identify the current
|
|
dataset</p>
|
|
</dd></dl>
|
|
|
|
<dl class="py property">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.file_path">
|
|
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">file_path</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><a class="headerlink" href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.file_path" title="Permalink to this definition">¶</a></dt>
|
|
<dd></dd></dl>
|
|
|
|
<dl class="py property">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.sorter">
|
|
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">sorter</span></span><em class="property"><span class="pre">:</span> <span class="pre">List</span></em><a class="headerlink" href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.sorter" title="Permalink to this definition">¶</a></dt>
|
|
<dd></dd></dl>
|
|
|
|
<dl class="py property">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.structure">
|
|
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">structure</span></span><em class="property"><span class="pre">:</span> <span class="pre">pandas.core.frame.DataFrame</span></em><a class="headerlink" href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.structure" title="Permalink to this definition">¶</a></dt>
|
|
<dd></dd></dl>
|
|
|
|
<dl class="py property">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.variables">
|
|
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">variables</span></span><em class="property"><span class="pre">:</span> <span class="pre">pandas.core.frame.DataFrame</span></em><a class="headerlink" href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.variables" title="Permalink to this definition">¶</a></dt>
|
|
<dd></dd></dl>
|
|
|
|
</dd></dl>
|
|
|
|
</div>
|
|
<div class="section" id="module-PyCTBN.PyCTBN.utility.cache">
|
|
<span id="pyctbn-pyctbn-utility-cache-module"></span><h2>PyCTBN.PyCTBN.utility.cache module<a class="headerlink" href="#module-PyCTBN.PyCTBN.utility.cache" title="Permalink to this headline">¶</a></h2>
|
|
<dl class="py class">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.cache.Cache">
|
|
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">PyCTBN.PyCTBN.utility.cache.</span></span><span class="sig-name descname"><span class="pre">Cache</span></span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.cache.Cache" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
|
|
<p>This class acts as a cache of <code class="docutils literal notranslate"><span class="pre">SetOfCims</span></code> objects for a node.</p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">__list_of_sets_of_parents</dt>
|
|
<dd class="field-odd"><p>a list of <code class="docutils literal notranslate"><span class="pre">Sets</span></code> objects of the parents to which the cim in cache at SAME
|
|
index is related</p>
|
|
</dd>
|
|
<dt class="field-even">__actual_cache</dt>
|
|
<dd class="field-even"><p>a list of setOfCims objects</p>
|
|
</dd>
|
|
</dl>
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.cache.Cache.clear">
|
|
<span class="sig-name descname"><span class="pre">clear</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.cache.Cache.clear" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Clear the contents both of <code class="docutils literal notranslate"><span class="pre">__actual_cache</span></code> and <code class="docutils literal notranslate"><span class="pre">__list_of_sets_of_parents</span></code>.</p>
|
|
</dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.cache.Cache.find">
|
|
<span class="sig-name descname"><span class="pre">find</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">parents_comb</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Set</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.cache.Cache.find" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Tries to find in cache given the symbolic parents combination <code class="docutils literal notranslate"><span class="pre">parents_comb</span></code> the <code class="docutils literal notranslate"><span class="pre">SetOfCims</span></code>
|
|
related to that <code class="docutils literal notranslate"><span class="pre">parents_comb</span></code>.</p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><p><strong>parents_comb</strong> (<em>Set</em>) – the parents related to that <code class="docutils literal notranslate"><span class="pre">SetOfCims</span></code></p>
|
|
</dd>
|
|
<dt class="field-even">Returns</dt>
|
|
<dd class="field-even"><p>A <code class="docutils literal notranslate"><span class="pre">SetOfCims</span></code> object if the <code class="docutils literal notranslate"><span class="pre">parents_comb</span></code> index is found in <code class="docutils literal notranslate"><span class="pre">__list_of_sets_of_parents</span></code>.
|
|
None otherwise.</p>
|
|
</dd>
|
|
<dt class="field-odd">Return type</dt>
|
|
<dd class="field-odd"><p><a class="reference internal" href="PyCTBN.PyCTBN.structure_graph.html#PyCTBN.PyCTBN.structure_graph.set_of_cims.SetOfCims" title="PyCTBN.PyCTBN.structure_graph.set_of_cims.SetOfCims">SetOfCims</a></p>
|
|
</dd>
|
|
</dl>
|
|
</dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.cache.Cache.put">
|
|
<span class="sig-name descname"><span class="pre">put</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">parents_comb</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Set</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">socim</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><a class="reference internal" href="PyCTBN.PyCTBN.structure_graph.html#PyCTBN.PyCTBN.structure_graph.set_of_cims.SetOfCims" title="PyCTBN.PyCTBN.structure_graph.set_of_cims.SetOfCims"><span class="pre">PyCTBN.PyCTBN.structure_graph.set_of_cims.SetOfCims</span></a></span></em><span class="sig-paren">)</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.cache.Cache.put" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Place in cache the <code class="docutils literal notranslate"><span class="pre">SetOfCims</span></code> object, and the related symbolic index <code class="docutils literal notranslate"><span class="pre">parents_comb</span></code> in
|
|
<code class="docutils literal notranslate"><span class="pre">__list_of_sets_of_parents</span></code>.</p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><ul class="simple">
|
|
<li><p><strong>parents_comb</strong> (<em>Set</em>) – the symbolic set index</p></li>
|
|
<li><p><strong>socim</strong> (<a class="reference internal" href="PyCTBN.PyCTBN.structure_graph.html#PyCTBN.PyCTBN.structure_graph.set_of_cims.SetOfCims" title="PyCTBN.PyCTBN.structure_graph.set_of_cims.SetOfCims"><em>SetOfCims</em></a>) – the related SetOfCims object</p></li>
|
|
</ul>
|
|
</dd>
|
|
</dl>
|
|
</dd></dl>
|
|
|
|
</dd></dl>
|
|
|
|
</div>
|
|
<div class="section" id="module-PyCTBN.PyCTBN.utility.json_exporter">
|
|
<span id="pyctbn-pyctbn-utility-json-exporter-module"></span><h2>PyCTBN.PyCTBN.utility.json_exporter module<a class="headerlink" href="#module-PyCTBN.PyCTBN.utility.json_exporter" title="Permalink to this headline">¶</a></h2>
|
|
<dl class="py class">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.json_exporter.JsonExporter">
|
|
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">PyCTBN.PyCTBN.utility.json_exporter.</span></span><span class="sig-name descname"><span class="pre">JsonExporter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">variables</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">pandas.core.frame.DataFrame</span><span class="p"><span class="pre">]</span></span></span> <span class="o"><span class="pre">=</span></span> <span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dyn_str</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">pandas.core.frame.DataFrame</span><span class="p"><span class="pre">]</span></span></span> <span class="o"><span class="pre">=</span></span> <span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dyn_cims</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">dict</span><span class="p"><span class="pre">]</span></span></span> <span class="o"><span class="pre">=</span></span> <span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.json_exporter.JsonExporter" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Bases: <a class="reference internal" href="#PyCTBN.PyCTBN.utility.abstract_exporter.AbstractExporter" title="PyCTBN.PyCTBN.utility.abstract_exporter.AbstractExporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">PyCTBN.PyCTBN.utility.abstract_exporter.AbstractExporter</span></code></a></p>
|
|
<p>Provides the methods to save in json format a network information
|
|
along with one or more trajectories generated basing on it</p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><ul class="simple">
|
|
<li><p><strong>_variables</strong> (<em>pandas.DataFrame</em>) – Dataframe containing the nodes labels and cardinalities</p></li>
|
|
<li><p><strong>_dyn_str</strong> (<em>pandas.DataFrame</em>) – Dataframe containing the structure of the network (edges)</p></li>
|
|
<li><p><strong>_dyn_cims</strong> (<em>dict</em>) – It contains, for every variable (label is the key), the SetOfCims object related to it</p></li>
|
|
<li><p><strong>_trajectories</strong> (<em>List</em>) – List of trajectories, that can be added subsequently</p></li>
|
|
</ul>
|
|
</dd>
|
|
</dl>
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.json_exporter.JsonExporter.cims_to_json">
|
|
<span class="sig-name descname"><span class="pre">cims_to_json</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> → <span class="pre">dict</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.json_exporter.JsonExporter.cims_to_json" title="Permalink to this definition">¶</a></dt>
|
|
<dd></dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.json_exporter.JsonExporter.out_file">
|
|
<span class="sig-name descname"><span class="pre">out_file</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.json_exporter.JsonExporter.out_file" title="Permalink to this definition">¶</a></dt>
|
|
<dd><dl class="simple">
|
|
<dt>Create a file in current directory and write on it the previously added data </dt><dd><p>(variables, dyn_str, dyn_cims and trajectories)</p>
|
|
</dd>
|
|
</dl>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><p><strong>filename</strong> (<em>string</em>) – Name of the output file (it must include json extension)</p>
|
|
</dd>
|
|
</dl>
|
|
</dd></dl>
|
|
|
|
</dd></dl>
|
|
|
|
</div>
|
|
<div class="section" id="module-PyCTBN.PyCTBN.utility.json_importer">
|
|
<span id="pyctbn-pyctbn-utility-json-importer-module"></span><h2>PyCTBN.PyCTBN.utility.json_importer module<a class="headerlink" href="#module-PyCTBN.PyCTBN.utility.json_importer" title="Permalink to this headline">¶</a></h2>
|
|
<dl class="py class">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.json_importer.JsonImporter">
|
|
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">PyCTBN.PyCTBN.utility.json_importer.</span></span><span class="sig-name descname"><span class="pre">JsonImporter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">file_path</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">samples_label</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">structure_label</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">variables_label</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">time_key</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">variables_key</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cims_label</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></span> <span class="o"><span class="pre">=</span></span> <span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.json_importer.JsonImporter" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Bases: <a class="reference internal" href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter" title="PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter</span></code></a></p>
|
|
<p>Implements the abstracts methods of AbstractImporter and adds all the necessary methods to process and prepare
|
|
the data in json extension.</p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><ul class="simple">
|
|
<li><p><strong>file_path</strong> (<em>string</em>) – the path of the file that contains tha data to be imported</p></li>
|
|
<li><p><strong>samples_label</strong> (<em>string</em>) – the reference key for the samples in the trajectories</p></li>
|
|
<li><p><strong>structure_label</strong> (<em>string</em>) – the reference key for the structure of the network data</p></li>
|
|
<li><p><strong>variables_label</strong> (<em>string</em>) – the reference key for the cardinalites of the nodes data</p></li>
|
|
<li><p><strong>time_key</strong> (<em>string</em>) – the key used to identify the timestamps in each trajectory</p></li>
|
|
<li><p><strong>variables_key</strong> (<em>string</em>) – the key used to identify the names of the variables in the net</p></li>
|
|
</ul>
|
|
</dd>
|
|
<dt class="field-even">_array_indx</dt>
|
|
<dd class="field-even"><p>the index of the outer JsonArray to extract the data from</p>
|
|
</dd>
|
|
<dt class="field-odd">_df_samples_list</dt>
|
|
<dd class="field-odd"><p>a Dataframe list in which every dataframe contains a trajectory</p>
|
|
</dd>
|
|
<dt class="field-even">_raw_data</dt>
|
|
<dd class="field-even"><p>The raw contents of the json file to import</p>
|
|
</dd>
|
|
</dl>
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.json_importer.JsonImporter.build_sorter">
|
|
<span class="sig-name descname"><span class="pre">build_sorter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sample_frame</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">pandas.core.frame.DataFrame</span></span></em><span class="sig-paren">)</span> → <span class="pre">List</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.json_importer.JsonImporter.build_sorter" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Implements the abstract method build_sorter of the <code class="xref py py-class docutils literal notranslate"><span class="pre">AbstractImporter</span></code> for this dataset.</p>
|
|
</dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.json_importer.JsonImporter.clear_data_frame_list">
|
|
<span class="sig-name descname"><span class="pre">clear_data_frame_list</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> → <span class="pre">None</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.json_importer.JsonImporter.clear_data_frame_list" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Removes all values present in the dataframes in the list <code class="docutils literal notranslate"><span class="pre">_df_samples_list</span></code>.</p>
|
|
</dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.json_importer.JsonImporter.dataset_id">
|
|
<span class="sig-name descname"><span class="pre">dataset_id</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> → <span class="pre">object</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.json_importer.JsonImporter.dataset_id" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>If the original dataset contains multiple dataset, this method returns a unique id to identify the current
|
|
dataset</p>
|
|
</dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.json_importer.JsonImporter.import_data">
|
|
<span class="sig-name descname"><span class="pre">import_data</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">indx</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">int</span></span></em><span class="sig-paren">)</span> → <span class="pre">None</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.json_importer.JsonImporter.import_data" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Implements the abstract method of <code class="xref py py-class docutils literal notranslate"><span class="pre">AbstractImporter</span></code>.</p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><p><strong>indx</strong> (<em>int</em>) – the index of the outer JsonArray to extract the data from</p>
|
|
</dd>
|
|
</dl>
|
|
</dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.json_importer.JsonImporter.import_sampled_cims">
|
|
<span class="sig-name descname"><span class="pre">import_sampled_cims</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">raw_data</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">List</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">indx</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">int</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cims_key</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span> → <span class="pre">Dict</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.json_importer.JsonImporter.import_sampled_cims" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Imports the synthetic CIMS in the dataset in a dictionary, using variables labels
|
|
as keys for the set of CIMS of a particular node.</p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><ul class="simple">
|
|
<li><p><strong>raw_data</strong> (<em>List</em>) – List of Dicts</p></li>
|
|
<li><p><strong>indx</strong> (<em>int</em>) – The index of the array from which the data have to be extracted</p></li>
|
|
<li><p><strong>cims_key</strong> (<em>string</em>) – the key where the json object cims are placed</p></li>
|
|
</ul>
|
|
</dd>
|
|
<dt class="field-even">Returns</dt>
|
|
<dd class="field-even"><p>a dictionary containing the sampled CIMS for all the variables in the net</p>
|
|
</dd>
|
|
<dt class="field-odd">Return type</dt>
|
|
<dd class="field-odd"><p>Dictionary</p>
|
|
</dd>
|
|
</dl>
|
|
</dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.json_importer.JsonImporter.import_structure">
|
|
<span class="sig-name descname"><span class="pre">import_structure</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">raw_data</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">List</span></span></em><span class="sig-paren">)</span> → <span class="pre">pandas.core.frame.DataFrame</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.json_importer.JsonImporter.import_structure" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Imports in a dataframe the data in the list raw_data at the key <code class="docutils literal notranslate"><span class="pre">_structure_label</span></code></p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><p><strong>raw_data</strong> (<em>List</em>) – List of Dicts</p>
|
|
</dd>
|
|
<dt class="field-even">Returns</dt>
|
|
<dd class="field-even"><p>Dataframe containg the starting node a ending node of every arc of the network</p>
|
|
</dd>
|
|
<dt class="field-odd">Return type</dt>
|
|
<dd class="field-odd"><p>pandas.Dataframe</p>
|
|
</dd>
|
|
</dl>
|
|
</dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.json_importer.JsonImporter.import_trajectories">
|
|
<span class="sig-name descname"><span class="pre">import_trajectories</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">raw_data</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">List</span></span></em><span class="sig-paren">)</span> → <span class="pre">List</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.json_importer.JsonImporter.import_trajectories" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Imports the trajectories from the list of dicts <code class="docutils literal notranslate"><span class="pre">raw_data</span></code>.</p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><p><strong>raw_data</strong> (<em>List</em>) – List of Dicts</p>
|
|
</dd>
|
|
<dt class="field-even">Returns</dt>
|
|
<dd class="field-even"><p>List of dataframes containing all the trajectories</p>
|
|
</dd>
|
|
<dt class="field-odd">Return type</dt>
|
|
<dd class="field-odd"><p>List</p>
|
|
</dd>
|
|
</dl>
|
|
</dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.json_importer.JsonImporter.import_variables">
|
|
<span class="sig-name descname"><span class="pre">import_variables</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">raw_data</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">List</span></span></em><span class="sig-paren">)</span> → <span class="pre">pandas.core.frame.DataFrame</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.json_importer.JsonImporter.import_variables" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Imports the data in <code class="docutils literal notranslate"><span class="pre">raw_data</span></code> at the key <code class="docutils literal notranslate"><span class="pre">_variables_label</span></code>.</p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><p><strong>raw_data</strong> (<em>List</em>) – List of Dicts</p>
|
|
</dd>
|
|
<dt class="field-even">Returns</dt>
|
|
<dd class="field-even"><p>Datframe containg the variables simbolic labels and their cardinalities</p>
|
|
</dd>
|
|
<dt class="field-odd">Return type</dt>
|
|
<dd class="field-odd"><p>pandas.Dataframe</p>
|
|
</dd>
|
|
</dl>
|
|
</dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.json_importer.JsonImporter.normalize_trajectories">
|
|
<span class="sig-name descname"><span class="pre">normalize_trajectories</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">raw_data</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">List</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">indx</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">int</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">trajectories_key</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span> → <span class="pre">List</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.json_importer.JsonImporter.normalize_trajectories" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Extracts the trajectories in <code class="docutils literal notranslate"><span class="pre">raw_data</span></code> at the index <code class="docutils literal notranslate"><span class="pre">index</span></code> at the key <code class="docutils literal notranslate"><span class="pre">trajectories</span> <span class="pre">key</span></code>.</p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><ul class="simple">
|
|
<li><p><strong>raw_data</strong> (<em>List</em>) – List of Dicts</p></li>
|
|
<li><p><strong>indx</strong> (<em>int</em>) – The index of the array from which the data have to be extracted</p></li>
|
|
<li><p><strong>trajectories_key</strong> (<em>string</em>) – the key of the trajectories objects</p></li>
|
|
</ul>
|
|
</dd>
|
|
<dt class="field-even">Returns</dt>
|
|
<dd class="field-even"><p>A list of daframes containg the trajectories</p>
|
|
</dd>
|
|
<dt class="field-odd">Return type</dt>
|
|
<dd class="field-odd"><p>List</p>
|
|
</dd>
|
|
</dl>
|
|
</dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.json_importer.JsonImporter.one_level_normalizing">
|
|
<span class="sig-name descname"><span class="pre">one_level_normalizing</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">raw_data</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">List</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">indx</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">int</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">key</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span> → <span class="pre">pandas.core.frame.DataFrame</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.json_importer.JsonImporter.one_level_normalizing" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Extracts the one-level nested data in the list <code class="docutils literal notranslate"><span class="pre">raw_data</span></code> at the index <code class="docutils literal notranslate"><span class="pre">indx</span></code> at the key <code class="docutils literal notranslate"><span class="pre">key</span></code>.</p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><ul class="simple">
|
|
<li><p><strong>raw_data</strong> (<em>List</em>) – List of Dicts</p></li>
|
|
<li><p><strong>indx</strong> (<em>int</em>) – The index of the array from which the data have to be extracted</p></li>
|
|
<li><p><strong>key</strong> (<em>string</em>) – the key for the Dicts from which exctract data</p></li>
|
|
</ul>
|
|
</dd>
|
|
<dt class="field-even">Returns</dt>
|
|
<dd class="field-even"><p>A normalized dataframe</p>
|
|
</dd>
|
|
<dt class="field-odd">Return type</dt>
|
|
<dd class="field-odd"><p>pandas.Datframe</p>
|
|
</dd>
|
|
</dl>
|
|
</dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.json_importer.JsonImporter.read_json_file">
|
|
<span class="sig-name descname"><span class="pre">read_json_file</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> → <span class="pre">List</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.json_importer.JsonImporter.read_json_file" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Reads the JSON file in the path self.filePath.</p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Returns</dt>
|
|
<dd class="field-odd"><p>The contents of the json file</p>
|
|
</dd>
|
|
<dt class="field-even">Return type</dt>
|
|
<dd class="field-even"><p>List</p>
|
|
</dd>
|
|
</dl>
|
|
</dd></dl>
|
|
|
|
</dd></dl>
|
|
|
|
</div>
|
|
<div class="section" id="module-PyCTBN.PyCTBN.utility.sample_importer">
|
|
<span id="pyctbn-pyctbn-utility-sample-importer-module"></span><h2>PyCTBN.PyCTBN.utility.sample_importer module<a class="headerlink" href="#module-PyCTBN.PyCTBN.utility.sample_importer" title="Permalink to this headline">¶</a></h2>
|
|
<dl class="py class">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.sample_importer.SampleImporter">
|
|
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">PyCTBN.PyCTBN.utility.sample_importer.</span></span><span class="sig-name descname"><span class="pre">SampleImporter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">trajectory_list</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">Union</span><span class="p"><span class="pre">[</span></span><span class="pre">pandas.core.frame.DataFrame</span><span class="p"><span class="pre">,</span> </span><span class="pre">numpy.ndarray</span><span class="p"><span class="pre">,</span> </span><span class="pre">List</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></span> <span class="o"><span class="pre">=</span></span> <span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">variables</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">Union</span><span class="p"><span class="pre">[</span></span><span class="pre">pandas.core.frame.DataFrame</span><span class="p"><span class="pre">,</span> </span><span class="pre">numpy.ndarray</span><span class="p"><span class="pre">,</span> </span><span class="pre">List</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></span> <span class="o"><span class="pre">=</span></span> <span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">prior_net_structure</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">Union</span><span class="p"><span class="pre">[</span></span><span class="pre">pandas.core.frame.DataFrame</span><span class="p"><span class="pre">,</span> </span><span class="pre">numpy.ndarray</span><span class="p"><span class="pre">,</span> </span><span class="pre">List</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></span> <span class="o"><span class="pre">=</span></span> <span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.sample_importer.SampleImporter" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Bases: <a class="reference internal" href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter" title="PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter</span></code></a></p>
|
|
<p>Implements the abstracts methods of AbstractImporter and adds all the necessary methods to process and prepare
|
|
the data loaded directly by using DataFrame</p>
|
|
<dl class="field-list simple">
|
|
<dt class="field-odd">Parameters</dt>
|
|
<dd class="field-odd"><ul class="simple">
|
|
<li><p><strong>trajectory_list</strong> (<em>typing.Union</em><em>[</em><em>pd.DataFrame</em><em>, </em><em>np.ndarray</em><em>, </em><em>typing.List</em><em>]</em>) – the data that describes the trajectories</p></li>
|
|
<li><p><strong>variables</strong> (<em>typing.Union</em><em>[</em><em>pd.DataFrame</em><em>, </em><em>np.ndarray</em><em>, </em><em>typing.List</em><em>]</em>) – the data that describes the variables with name and cardinality</p></li>
|
|
<li><p><strong>prior_net_structure</strong> (<em>typing.Union</em><em>[</em><em>pd.DataFrame</em><em>, </em><em>np.ndarray</em><em>, </em><em>typing.List</em><em>]</em>) – the data of the real structure, if it exists</p></li>
|
|
</ul>
|
|
</dd>
|
|
<dt class="field-even">_df_samples_list</dt>
|
|
<dd class="field-even"><p>a Dataframe list in which every dataframe contains a trajectory</p>
|
|
</dd>
|
|
<dt class="field-odd">_raw_data</dt>
|
|
<dd class="field-odd"><p>The raw contents of the json file to import</p>
|
|
</dd>
|
|
</dl>
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.sample_importer.SampleImporter.build_sorter">
|
|
<span class="sig-name descname"><span class="pre">build_sorter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sample_frame</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">pandas.core.frame.DataFrame</span></span></em><span class="sig-paren">)</span> → <span class="pre">List</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.sample_importer.SampleImporter.build_sorter" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Implements the abstract method build_sorter of the <code class="xref py py-class docutils literal notranslate"><span class="pre">AbstractImporter</span></code> in order to get the ordered variables list.</p>
|
|
</dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.sample_importer.SampleImporter.dataset_id">
|
|
<span class="sig-name descname"><span class="pre">dataset_id</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> → <span class="pre">str</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.sample_importer.SampleImporter.dataset_id" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>If the original dataset contains multiple dataset, this method returns a unique id to identify the current
|
|
dataset</p>
|
|
</dd></dl>
|
|
|
|
<dl class="py method">
|
|
<dt class="sig sig-object py" id="PyCTBN.PyCTBN.utility.sample_importer.SampleImporter.import_data">
|
|
<span class="sig-name descname"><span class="pre">import_data</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">header_column</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#PyCTBN.PyCTBN.utility.sample_importer.SampleImporter.import_data" title="Permalink to this definition">¶</a></dt>
|
|
<dd></dd></dl>
|
|
|
|
</dd></dl>
|
|
|
|
</div>
|
|
<div class="section" id="module-PyCTBN.PyCTBN.utility">
|
|
<span id="module-contents"></span><h2>Module contents<a class="headerlink" href="#module-PyCTBN.PyCTBN.utility" title="Permalink to this headline">¶</a></h2>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
<footer>
|
|
|
|
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
|
|
|
|
<a href="examples.html" class="btn btn-neutral float-right" title="Examples">Next <span class="fa fa-arrow-circle-right"></span></a>
|
|
|
|
|
|
<a href="PyCTBN.PyCTBN.structure_graph.html" class="btn btn-neutral" title="PyCTBN.PyCTBN.structure_graph package"><span class="fa fa-arrow-circle-left"></span> Previous</a>
|
|
|
|
</div>
|
|
|
|
|
|
<hr/>
|
|
|
|
<div role="contentinfo">
|
|
<p>
|
|
© Copyright 2021, Bregoli Alessandro, Martini Filippo, Moretti Luca.
|
|
</p>
|
|
</div>
|
|
|
|
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/jucacrispim/sphinx_pdj_theme">theme</a> provided by <a href="http://poraodojuca.net">Porão do Juca</a>.
|
|
|
|
</footer>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT:'./',
|
|
VERSION:'2.0',
|
|
COLLAPSE_INDEX:false,
|
|
FILE_SUFFIX:'.html',
|
|
HAS_SOURCE: true
|
|
};
|
|
</script>
|
|
<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="_static/js/theme.js"></script>
|
|
|
|
<script type="text/javascript"
|
|
src="_static/js/pdj.js"></script>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
jQuery(function () {
|
|
SphinxRtdTheme.StickyNav.enable();
|
|
});
|
|
</script>
|
|
|
|
|
|
</body>
|
|
</html> |