<liclass="toctree-l2"><aclass="reference internal"href="examples.html#implementing-your-own-data-importer">Implementing your own data importer</a></li>
<spanid="pyctbn-pyctbn-utility-abstract-exporter-module"></span><h2>PyCTBN.PyCTBN.utility.abstract_exporter module<aclass="headerlink"href="#module-PyCTBN.PyCTBN.utility.abstract_exporter"title="Permalink to this headline">¶</a></h2>
<emclass="property"><spanclass="pre">class</span></em><spanclass="sig-prename descclassname"><spanclass="pre">PyCTBN.PyCTBN.utility.abstract_exporter.</span></span><spanclass="sig-name descname"><spanclass="pre">AbstractExporter</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">variables</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">Optional</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">pandas.core.frame.DataFrame</span><spanclass="p"><spanclass="pre">]</span></span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">dyn_str</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">Optional</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">pandas.core.frame.DataFrame</span><spanclass="p"><spanclass="pre">]</span></span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">dyn_cims</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">Optional</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">dict</span><spanclass="p"><spanclass="pre">]</span></span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.abstract_exporter.AbstractExporter"title="Permalink to this definition">¶</a></dt>
<spanclass="sig-name descname"><spanclass="pre">add_trajectory</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">trajectory</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">list</span></span></em><spanclass="sig-paren">)</span><aclass="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>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>trajectory</strong> (<em>pandas.DataFrame</em>) – The trajectory to add</p>
<emclass="property"><spanclass="pre">abstract</span></em><spanclass="sig-name descname"><spanclass="pre">out_file</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">filename</span></span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.abstract_exporter.AbstractExporter.out_file"title="Permalink to this definition">¶</a></dt>
<dd><dlclass="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>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>filename</strong> (<em>string</em>) – Name of the output file (it must include json extension)</p>
<spanid="pyctbn-pyctbn-utility-abstract-importer-module"></span><h2>PyCTBN.PyCTBN.utility.abstract_importer module<aclass="headerlink"href="#module-PyCTBN.PyCTBN.utility.abstract_importer"title="Permalink to this headline">¶</a></h2>
<emclass="property"><spanclass="pre">class</span></em><spanclass="sig-prename descclassname"><spanclass="pre">PyCTBN.PyCTBN.utility.abstract_importer.</span></span><spanclass="sig-name descname"><spanclass="pre">AbstractImporter</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">file_path</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">Optional</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">str</span><spanclass="p"><spanclass="pre">]</span></span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">trajectory_list</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">Optional</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">Union</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">pandas.core.frame.DataFrame</span><spanclass="p"><spanclass="pre">,</span></span><spanclass="pre">numpy.ndarray</span><spanclass="p"><spanclass="pre">]</span></span><spanclass="p"><spanclass="pre">]</span></span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">variables</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">Optional</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">pandas.core.frame.DataFrame</span><spanclass="p"><spanclass="pre">]</span></span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">prior_net_structure</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">Optional</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">pandas.core.frame.DataFrame</span><spanclass="p"><spanclass="pre">]</span></span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter"title="Permalink to this definition">¶</a></dt>
<p>Abstract class that exposes all the necessary methods to process the trajectories and the net structure.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="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>
<dtclass="field-even">Prior_net_structure</dt>
<ddclass="field-even"><p>Dataframe containing the structure of the network (edges)</p>
</dd>
<dtclass="field-odd">_sorter</dt>
<ddclass="field-odd"><p>A list containing the variables labels in the SAME order as the columns in <codeclass="docutils literal notranslate"><spanclass="pre">concatenated_samples</span></code></p>
</dd>
</dl>
<divclass="admonition warning">
<pclass="admonition-title">Warning</p>
<p>The parameters <codeclass="docutils literal notranslate"><spanclass="pre">variables</span></code> and <codeclass="docutils literal notranslate"><spanclass="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 <codeclass="docutils literal notranslate"><spanclass="pre">concatenated_samples</span></code> Dataframe/ndarray.</p>
</div>
<divclass="admonition note">
<pclass="admonition-title">Note</p>
<p>See :class:<codeclass="docutils literal notranslate"><spanclass="pre">JsonImporter</span></code> for an example implementation</p>
<spanclass="sig-name descname"><spanclass="pre">build_list_of_samples_array</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">concatenated_sample</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">pandas.core.frame.DataFrame</span></span></em><spanclass="sig-paren">)</span>→<spanclass="pre">List</span><aclass="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>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="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>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p>the resulting list of numpy arrays</p>
<emclass="property"><spanclass="pre">abstract</span></em><spanclass="sig-name descname"><spanclass="pre">build_sorter</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">trajecory_header</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">object</span></span></em><spanclass="sig-paren">)</span>→<spanclass="pre">List</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.build_sorter"title="Permalink to this definition">¶</a></dt>
<dd><p>Initializes the <codeclass="docutils literal notranslate"><spanclass="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>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>trajecory_header</strong> (<em>object</em>) – an object that will be used to define the header</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p>A list containing the processed header.</p>
<spanclass="sig-name descname"><spanclass="pre">clear_concatenated_frame</span></span><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span>→<spanclass="pre">None</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.clear_concatenated_frame"title="Permalink to this definition">¶</a></dt>
<spanclass="sig-name descname"><spanclass="pre">compute_row_delta_in_all_samples_frames</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">df_samples_list</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">List</span></span></em><spanclass="sig-paren">)</span>→<spanclass="pre">None</span><aclass="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 <codeclass="docutils literal notranslate"><spanclass="pre">compute_row_delta_sigle_samples_frame</span></code> on every dataframe present in the list
Concatenates the result in the dataframe <codeclass="docutils literal notranslate"><spanclass="pre">concatanated_samples</span></code></p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>df_samples_list</strong> (<em>List</em>) – the datframe’s list to be processed and concatenated</p>
</dd>
</dl>
<divclass="admonition warning">
<pclass="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>
<divclass="admonition note">
<pclass="admonition-title">Note</p>
<p>After the call of this method the class member <codeclass="docutils literal notranslate"><spanclass="pre">concatanated_samples</span></code> will contain all processed
<spanclass="sig-name descname"><spanclass="pre">compute_row_delta_sigle_samples_frame</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">sample_frame</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">pandas.core.frame.DataFrame</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">columns_header</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">List</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">shifted_cols_header</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">List</span></span></em><spanclass="sig-paren">)</span>→<spanclass="pre">pandas.core.frame.DataFrame</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.compute_row_delta_sigle_samples_frame"title="Permalink to this definition">¶</a></dt>
<p>the Dataframe <codeclass="docutils literal notranslate"><spanclass="pre">sample_frame</span></code> has to follow the column structure of this header:
Header of sample_frame = [Time | Variable values]</p>
<emclass="property"><spanclass="pre">property</span></em><spanclass="sig-name descname"><spanclass="pre">concatenated_samples</span></span><emclass="property"><spanclass="pre">:</span><spanclass="pre">pandas.core.frame.DataFrame</span></em><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.concatenated_samples"title="Permalink to this definition">¶</a></dt>
<emclass="property"><spanclass="pre">abstract</span></em><spanclass="sig-name descname"><spanclass="pre">dataset_id</span></span><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span>→<spanclass="pre">object</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.dataset_id"title="Permalink to this definition">¶</a></dt>
<emclass="property"><spanclass="pre">property</span></em><spanclass="sig-name descname"><spanclass="pre">file_path</span></span><emclass="property"><spanclass="pre">:</span><spanclass="pre">str</span></em><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.file_path"title="Permalink to this definition">¶</a></dt>
<emclass="property"><spanclass="pre">property</span></em><spanclass="sig-name descname"><spanclass="pre">sorter</span></span><emclass="property"><spanclass="pre">:</span><spanclass="pre">List</span></em><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.sorter"title="Permalink to this definition">¶</a></dt>
<emclass="property"><spanclass="pre">property</span></em><spanclass="sig-name descname"><spanclass="pre">structure</span></span><emclass="property"><spanclass="pre">:</span><spanclass="pre">pandas.core.frame.DataFrame</span></em><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.structure"title="Permalink to this definition">¶</a></dt>
<emclass="property"><spanclass="pre">property</span></em><spanclass="sig-name descname"><spanclass="pre">variables</span></span><emclass="property"><spanclass="pre">:</span><spanclass="pre">pandas.core.frame.DataFrame</span></em><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.abstract_importer.AbstractImporter.variables"title="Permalink to this definition">¶</a></dt>
<spanid="pyctbn-pyctbn-utility-cache-module"></span><h2>PyCTBN.PyCTBN.utility.cache module<aclass="headerlink"href="#module-PyCTBN.PyCTBN.utility.cache"title="Permalink to this headline">¶</a></h2>
<emclass="property"><spanclass="pre">class</span></em><spanclass="sig-prename descclassname"><spanclass="pre">PyCTBN.PyCTBN.utility.cache.</span></span><spanclass="sig-name descname"><spanclass="pre">Cache</span></span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.cache.Cache"title="Permalink to this definition">¶</a></dt>
<ddclass="field-odd"><p>a list of <codeclass="docutils literal notranslate"><spanclass="pre">Sets</span></code> objects of the parents to which the cim in cache at SAME
index is related</p>
</dd>
<dtclass="field-even">__actual_cache</dt>
<ddclass="field-even"><p>a list of setOfCims objects</p>
<spanclass="sig-name descname"><spanclass="pre">clear</span></span><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.cache.Cache.clear"title="Permalink to this definition">¶</a></dt>
<dd><p>Clear the contents both of <codeclass="docutils literal notranslate"><spanclass="pre">__actual_cache</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">__list_of_sets_of_parents</span></code>.</p>
<spanclass="sig-name descname"><spanclass="pre">find</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">parents_comb</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">Set</span></span></em><spanclass="sig-paren">)</span><aclass="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 <codeclass="docutils literal notranslate"><spanclass="pre">parents_comb</span></code> the <codeclass="docutils literal notranslate"><spanclass="pre">SetOfCims</span></code>
related to that <codeclass="docutils literal notranslate"><spanclass="pre">parents_comb</span></code>.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>parents_comb</strong> (<em>Set</em>) – the parents related to that <codeclass="docutils literal notranslate"><spanclass="pre">SetOfCims</span></code></p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p>A <codeclass="docutils literal notranslate"><spanclass="pre">SetOfCims</span></code> object if the <codeclass="docutils literal notranslate"><spanclass="pre">parents_comb</span></code> index is found in <codeclass="docutils literal notranslate"><spanclass="pre">__list_of_sets_of_parents</span></code>.
<spanclass="sig-name descname"><spanclass="pre">put</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">parents_comb</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">Set</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">socim</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><aclass="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"><spanclass="pre">PyCTBN.PyCTBN.structure_graph.set_of_cims.SetOfCims</span></a></span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.cache.Cache.put"title="Permalink to this definition">¶</a></dt>
<dd><p>Place in cache the <codeclass="docutils literal notranslate"><spanclass="pre">SetOfCims</span></code> object, and the related symbolic index <codeclass="docutils literal notranslate"><spanclass="pre">parents_comb</span></code> in
<li><p><strong>parents_comb</strong> (<em>Set</em>) – the symbolic set index</p></li>
<li><p><strong>socim</strong> (<aclass="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>
<spanid="pyctbn-pyctbn-utility-json-exporter-module"></span><h2>PyCTBN.PyCTBN.utility.json_exporter module<aclass="headerlink"href="#module-PyCTBN.PyCTBN.utility.json_exporter"title="Permalink to this headline">¶</a></h2>
<emclass="property"><spanclass="pre">class</span></em><spanclass="sig-prename descclassname"><spanclass="pre">PyCTBN.PyCTBN.utility.json_exporter.</span></span><spanclass="sig-name descname"><spanclass="pre">JsonExporter</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">variables</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">Optional</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">pandas.core.frame.DataFrame</span><spanclass="p"><spanclass="pre">]</span></span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">dyn_str</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">Optional</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">pandas.core.frame.DataFrame</span><spanclass="p"><spanclass="pre">]</span></span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">dyn_cims</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">Optional</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">dict</span><spanclass="p"><spanclass="pre">]</span></span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.json_exporter.JsonExporter"title="Permalink to this definition">¶</a></dt>
<spanclass="sig-name descname"><spanclass="pre">cims_to_json</span></span><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span>→<spanclass="pre">dict</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.json_exporter.JsonExporter.cims_to_json"title="Permalink to this definition">¶</a></dt>
<spanclass="sig-name descname"><spanclass="pre">out_file</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">filename</span></span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.json_exporter.JsonExporter.out_file"title="Permalink to this definition">¶</a></dt>
<dd><dlclass="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>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>filename</strong> (<em>string</em>) – Name of the output file (it must include json extension)</p>
<spanid="pyctbn-pyctbn-utility-json-importer-module"></span><h2>PyCTBN.PyCTBN.utility.json_importer module<aclass="headerlink"href="#module-PyCTBN.PyCTBN.utility.json_importer"title="Permalink to this headline">¶</a></h2>
<spanclass="sig-name descname"><spanclass="pre">build_sorter</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">sample_frame</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">pandas.core.frame.DataFrame</span></span></em><spanclass="sig-paren">)</span>→<spanclass="pre">List</span><aclass="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 <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">AbstractImporter</span></code> for this dataset.</p>
<spanclass="sig-name descname"><spanclass="pre">clear_data_frame_list</span></span><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span>→<spanclass="pre">None</span><aclass="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 <codeclass="docutils literal notranslate"><spanclass="pre">_df_samples_list</span></code>.</p>
<spanclass="sig-name descname"><spanclass="pre">dataset_id</span></span><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span>→<spanclass="pre">object</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.json_importer.JsonImporter.dataset_id"title="Permalink to this definition">¶</a></dt>
<spanclass="sig-name descname"><spanclass="pre">import_data</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">indx</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">int</span></span></em><spanclass="sig-paren">)</span>→<spanclass="pre">None</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.json_importer.JsonImporter.import_data"title="Permalink to this definition">¶</a></dt>
<spanclass="sig-name descname"><spanclass="pre">import_sampled_cims</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">raw_data</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">List</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">indx</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">int</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">cims_key</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">str</span></span></em><spanclass="sig-paren">)</span>→<spanclass="pre">Dict</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.json_importer.JsonImporter.import_sampled_cims"title="Permalink to this definition">¶</a></dt>
<spanclass="sig-name descname"><spanclass="pre">import_structure</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">raw_data</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">List</span></span></em><spanclass="sig-paren">)</span>→<spanclass="pre">pandas.core.frame.DataFrame</span><aclass="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 <codeclass="docutils literal notranslate"><spanclass="pre">_structure_label</span></code></p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>raw_data</strong> (<em>List</em>) – List of Dicts</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p>Dataframe containg the starting node a ending node of every arc of the network</p>
<spanclass="sig-name descname"><spanclass="pre">import_trajectories</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">raw_data</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">List</span></span></em><spanclass="sig-paren">)</span>→<spanclass="pre">List</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.json_importer.JsonImporter.import_trajectories"title="Permalink to this definition">¶</a></dt>
<spanclass="sig-name descname"><spanclass="pre">import_variables</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">raw_data</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">List</span></span></em><spanclass="sig-paren">)</span>→<spanclass="pre">pandas.core.frame.DataFrame</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.json_importer.JsonImporter.import_variables"title="Permalink to this definition">¶</a></dt>
<dd><p>Imports the data in <codeclass="docutils literal notranslate"><spanclass="pre">raw_data</span></code> at the key <codeclass="docutils literal notranslate"><spanclass="pre">_variables_label</span></code>.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>raw_data</strong> (<em>List</em>) – List of Dicts</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p>Datframe containg the variables simbolic labels and their cardinalities</p>
<spanclass="sig-name descname"><spanclass="pre">normalize_trajectories</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">raw_data</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">List</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">indx</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">int</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">trajectories_key</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">str</span></span></em><spanclass="sig-paren">)</span>→<spanclass="pre">List</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.json_importer.JsonImporter.normalize_trajectories"title="Permalink to this definition">¶</a></dt>
<dd><p>Extracts the trajectories in <codeclass="docutils literal notranslate"><spanclass="pre">raw_data</span></code> at the index <codeclass="docutils literal notranslate"><spanclass="pre">index</span></code> at the key <codeclass="docutils literal notranslate"><spanclass="pre">trajectories</span><spanclass="pre">key</span></code>.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="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>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p>A list of daframes containg the trajectories</p>
<spanclass="sig-name descname"><spanclass="pre">one_level_normalizing</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">raw_data</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">List</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">indx</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">int</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">key</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">str</span></span></em><spanclass="sig-paren">)</span>→<spanclass="pre">pandas.core.frame.DataFrame</span><aclass="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 <codeclass="docutils literal notranslate"><spanclass="pre">raw_data</span></code> at the index <codeclass="docutils literal notranslate"><spanclass="pre">indx</span></code> at the key <codeclass="docutils literal notranslate"><spanclass="pre">key</span></code>.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="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>
<spanclass="sig-name descname"><spanclass="pre">read_json_file</span></span><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span>→<spanclass="pre">List</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.json_importer.JsonImporter.read_json_file"title="Permalink to this definition">¶</a></dt>
<spanid="pyctbn-pyctbn-utility-sample-importer-module"></span><h2>PyCTBN.PyCTBN.utility.sample_importer module<aclass="headerlink"href="#module-PyCTBN.PyCTBN.utility.sample_importer"title="Permalink to this headline">¶</a></h2>
<emclass="property"><spanclass="pre">class</span></em><spanclass="sig-prename descclassname"><spanclass="pre">PyCTBN.PyCTBN.utility.sample_importer.</span></span><spanclass="sig-name descname"><spanclass="pre">SampleImporter</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">trajectory_list</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">Optional</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">Union</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">pandas.core.frame.DataFrame</span><spanclass="p"><spanclass="pre">,</span></span><spanclass="pre">numpy.ndarray</span><spanclass="p"><spanclass="pre">,</span></span><spanclass="pre">List</span><spanclass="p"><spanclass="pre">]</span></span><spanclass="p"><spanclass="pre">]</span></span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">variables</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">Optional</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">Union</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">pandas.core.frame.DataFrame</span><spanclass="p"><spanclass="pre">,</span></span><spanclass="pre">numpy.ndarray</span><spanclass="p"><spanclass="pre">,</span></span><spanclass="pre">List</span><spanclass="p"><spanclass="pre">]</span></span><spanclass="p"><spanclass="pre">]</span></span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">prior_net_structure</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">Optional</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">Union</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">pandas.core.frame.DataFrame</span><spanclass="p"><spanclass="pre">,</span></span><spanclass="pre">numpy.ndarray</span><spanclass="p"><spanclass="pre">,</span></span><spanclass="pre">List</span><spanclass="p"><spanclass="pre">]</span></span><spanclass="p"><spanclass="pre">]</span></span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.sample_importer.SampleImporter"title="Permalink to this definition">¶</a></dt>
<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>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="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>
<dtclass="field-even">_df_samples_list</dt>
<ddclass="field-even"><p>a Dataframe list in which every dataframe contains a trajectory</p>
</dd>
<dtclass="field-odd">_raw_data</dt>
<ddclass="field-odd"><p>The raw contents of the json file to import</p>
<spanclass="sig-name descname"><spanclass="pre">build_sorter</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">sample_frame</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="n"><spanclass="pre">pandas.core.frame.DataFrame</span></span></em><spanclass="sig-paren">)</span>→<spanclass="pre">List</span><aclass="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 <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">AbstractImporter</span></code> in order to get the ordered variables list.</p>
<spanclass="sig-name descname"><spanclass="pre">dataset_id</span></span><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span>→<spanclass="pre">str</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.sample_importer.SampleImporter.dataset_id"title="Permalink to this definition">¶</a></dt>
<spanclass="sig-name descname"><spanclass="pre">import_data</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">header_column</span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#PyCTBN.PyCTBN.utility.sample_importer.SampleImporter.import_data"title="Permalink to this definition">¶</a></dt>
<spanid="module-contents"></span><h2>Module contents<aclass="headerlink"href="#module-PyCTBN.PyCTBN.utility"title="Permalink to this headline">¶</a></h2>
Built with <ahref="http://sphinx-doc.org/">Sphinx</a> using a <ahref="https://github.com/jucacrispim/sphinx_pdj_theme">theme</a> provided by <ahref="http://poraodojuca.net">Porão do Juca</a>.