<liclass="toctree-l2"><aclass="reference internal"href="examples.html#implementing-your-own-data-importer">Implementing your own data importer</a></li>
<spanid="PyCTBN-utility-abstract-importer-module"></span><h2>PyCTBN.utility.abstract_importer module<aclass="headerlink"href="#module-PyCTBN.utility.abstract_importer"title="Permalink to this headline">¶</a></h2>
<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>
<codeclass="sig-name descname">build_list_of_samples_array</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">concatenated_sample</span><spanclass="p">:</span><spanclass="n">pandas.core.frame.DataFrame</span></em><spanclass="sig-paren">)</span>→ List<aclass="headerlink"href="#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">abstract </em><codeclass="sig-name descname">build_sorter</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">trajecory_header</span><spanclass="p">:</span><spanclass="n">object</span></em><spanclass="sig-paren">)</span>→ List<aclass="headerlink"href="#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>
<codeclass="sig-name descname">clear_concatenated_frame</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span>→ None<aclass="headerlink"href="#PyCTBN.utility.abstract_importer.AbstractImporter.clear_concatenated_frame"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">compute_row_delta_in_all_samples_frames</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">df_samples_list</span><spanclass="p">:</span><spanclass="n">List</span></em><spanclass="sig-paren">)</span>→ None<aclass="headerlink"href="#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
<codeclass="sig-name descname">compute_row_delta_sigle_samples_frame</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">sample_frame</span><spanclass="p">:</span><spanclass="n">pandas.core.frame.DataFrame</span></em>, <emclass="sig-param"><spanclass="n">columns_header</span><spanclass="p">:</span><spanclass="n">List</span></em>, <emclass="sig-param"><spanclass="n">shifted_cols_header</span><spanclass="p">:</span><spanclass="n">List</span></em><spanclass="sig-paren">)</span>→ pandas.core.frame.DataFrame<aclass="headerlink"href="#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">property </em><codeclass="sig-name descname">concatenated_samples</code><aclass="headerlink"href="#PyCTBN.utility.abstract_importer.AbstractImporter.concatenated_samples"title="Permalink to this definition">¶</a></dt>
<emclass="property">abstract </em><codeclass="sig-name descname">dataset_id</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span>→ object<aclass="headerlink"href="#PyCTBN.utility.abstract_importer.AbstractImporter.dataset_id"title="Permalink to this definition">¶</a></dt>
<emclass="property">property </em><codeclass="sig-name descname">file_path</code><aclass="headerlink"href="#PyCTBN.utility.abstract_importer.AbstractImporter.file_path"title="Permalink to this definition">¶</a></dt>
<emclass="property">property </em><codeclass="sig-name descname">sorter</code><aclass="headerlink"href="#PyCTBN.utility.abstract_importer.AbstractImporter.sorter"title="Permalink to this definition">¶</a></dt>
<emclass="property">property </em><codeclass="sig-name descname">structure</code><aclass="headerlink"href="#PyCTBN.utility.abstract_importer.AbstractImporter.structure"title="Permalink to this definition">¶</a></dt>
<emclass="property">property </em><codeclass="sig-name descname">variables</code><aclass="headerlink"href="#PyCTBN.utility.abstract_importer.AbstractImporter.variables"title="Permalink to this definition">¶</a></dt>
<spanid="PyCTBN-utility-cache-module"></span><h2>PyCTBN.utility.cache module<aclass="headerlink"href="#module-PyCTBN.utility.cache"title="Permalink to this headline">¶</a></h2>
<emclass="property">class </em><codeclass="sig-prename descclassname">PyCTBN.utility.cache.</code><codeclass="sig-name descname">Cache</code><aclass="headerlink"href="#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>
<codeclass="sig-name descname">clear</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="headerlink"href="#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>
<codeclass="sig-name descname">find</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">parents_comb</span><spanclass="p">:</span><spanclass="n">Set</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#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>.
<codeclass="sig-name descname">put</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">parents_comb</span><spanclass="p">:</span><spanclass="n">Set</span></em>, <emclass="sig-param"><spanclass="n">socim</span><spanclass="p">:</span><spanclass="n"><aclass="reference internal"href="PyCTBN.structure_graph.html#PyCTBN.structure_graph.set_of_cims.SetOfCims"title="PyCTBN.structure_graph.set_of_cims.SetOfCims">PyCTBN.structure_graph.set_of_cims.SetOfCims</a></span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#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>socim</strong> (<aclass="reference internal"href="PyCTBN.structure_graph.html#PyCTBN.structure_graph.set_of_cims.SetOfCims"title="PyCTBN.structure_graph.set_of_cims.SetOfCims"><em>SetOfCims</em></a>) – the related SetOfCims object</p></li>
<spanid="PyCTBN-utility-decorators-module"></span><h2>PyCTBN.utility.decorators module<aclass="headerlink"href="#module-PyCTBN.utility.decorators"title="Permalink to this headline">¶</a></h2>
<codeclass="sig-prename descclassname">PyCTBN.utility.decorators.</code><codeclass="sig-name descname">timing</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">f</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#PyCTBN.utility.decorators.timing"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-prename descclassname">PyCTBN.utility.decorators.</code><codeclass="sig-name descname">timing_write</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">f</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#PyCTBN.utility.decorators.timing_write"title="Permalink to this definition">¶</a></dt>
<spanid="PyCTBN-utility-json-importer-module"></span><h2>PyCTBN.utility.json_importer module<aclass="headerlink"href="#module-PyCTBN.utility.json_importer"title="Permalink to this headline">¶</a></h2>
<codeclass="sig-name descname">build_sorter</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">sample_frame</span><spanclass="p">:</span><spanclass="n">pandas.core.frame.DataFrame</span></em><spanclass="sig-paren">)</span>→ List<aclass="headerlink"href="#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>
<codeclass="sig-name descname">clear_data_frame_list</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span>→ None<aclass="headerlink"href="#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>
<codeclass="sig-name descname">dataset_id</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span>→ object<aclass="headerlink"href="#PyCTBN.utility.json_importer.JsonImporter.dataset_id"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">import_data</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">indx</span><spanclass="p">:</span><spanclass="n">int</span></em><spanclass="sig-paren">)</span>→ None<aclass="headerlink"href="#PyCTBN.utility.json_importer.JsonImporter.import_data"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">import_sampled_cims</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">raw_data</span><spanclass="p">:</span><spanclass="n">List</span></em>, <emclass="sig-param"><spanclass="n">indx</span><spanclass="p">:</span><spanclass="n">int</span></em>, <emclass="sig-param"><spanclass="n">cims_key</span><spanclass="p">:</span><spanclass="n">str</span></em><spanclass="sig-paren">)</span>→ Dict<aclass="headerlink"href="#PyCTBN.utility.json_importer.JsonImporter.import_sampled_cims"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">import_structure</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">raw_data</span><spanclass="p">:</span><spanclass="n">List</span></em><spanclass="sig-paren">)</span>→ pandas.core.frame.DataFrame<aclass="headerlink"href="#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>
<codeclass="sig-name descname">import_trajectories</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">raw_data</span><spanclass="p">:</span><spanclass="n">List</span></em><spanclass="sig-paren">)</span>→ List<aclass="headerlink"href="#PyCTBN.utility.json_importer.JsonImporter.import_trajectories"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">import_variables</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">raw_data</span><spanclass="p">:</span><spanclass="n">List</span></em><spanclass="sig-paren">)</span>→ pandas.core.frame.DataFrame<aclass="headerlink"href="#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>
<codeclass="sig-name descname">normalize_trajectories</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">raw_data</span><spanclass="p">:</span><spanclass="n">List</span></em>, <emclass="sig-param"><spanclass="n">indx</span><spanclass="p">:</span><spanclass="n">int</span></em>, <emclass="sig-param"><spanclass="n">trajectories_key</span><spanclass="p">:</span><spanclass="n">str</span></em><spanclass="sig-paren">)</span>→ List<aclass="headerlink"href="#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>
<codeclass="sig-name descname">one_level_normalizing</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">raw_data</span><spanclass="p">:</span><spanclass="n">List</span></em>, <emclass="sig-param"><spanclass="n">indx</span><spanclass="p">:</span><spanclass="n">int</span></em>, <emclass="sig-param"><spanclass="n">key</span><spanclass="p">:</span><spanclass="n">str</span></em><spanclass="sig-paren">)</span>→ pandas.core.frame.DataFrame<aclass="headerlink"href="#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>
<codeclass="sig-name descname">read_json_file</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span>→ List<aclass="headerlink"href="#PyCTBN.utility.json_importer.JsonImporter.read_json_file"title="Permalink to this definition">¶</a></dt>
<spanid="PyCTBN-utility-sample-importer-module"></span><h2>PyCTBN.utility.sample_importer module<aclass="headerlink"href="#module-PyCTBN.utility.sample_importer"title="Permalink to this headline">¶</a></h2>
<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>
<codeclass="sig-name descname">build_sorter</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">sample_frame</span><spanclass="p">:</span><spanclass="n">pandas.core.frame.DataFrame</span></em><spanclass="sig-paren">)</span>→ List<aclass="headerlink"href="#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>
<codeclass="sig-name descname">dataset_id</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span>→ object<aclass="headerlink"href="#PyCTBN.utility.sample_importer.SampleImporter.dataset_id"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">import_data</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">header_column</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#PyCTBN.utility.sample_importer.SampleImporter.import_data"title="Permalink to this definition">¶</a></dt>
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>.