structure_estimator module

class structure_estimator.StructureEstimator(sample_path: sample_path.SamplePath, exp_test_alfa: float, chi_test_alfa: float)

Bases: object

Has the task of estimating the network structure given the trajectories in samplepath.

Parameters
  • sample_path (SamplePath) – the _sample_path object containing the trajectories and the real structure

  • exp_test_alfa (float) – the significance level for the exponential Hp test

  • chi_test_alfa (float) – the significance level for the chi Hp test

_nodes

the nodes labels

_nodes_vals

the nodes cardinalities

_nodes_indxs

the nodes indexes

_complete_graph

the complete directed graph built using the nodes labels in _nodes

_cache

the Cache object

build_complete_graph(node_ids: List) → networkx.classes.digraph.DiGraph

Builds a complete directed graph (no self loops) given the nodes labels in the list node_ids:

Parameters

node_ids (List) – the list of nodes labels

Returns

a complete Digraph Object

Return type

networkx.DiGraph

complete_test(test_parent: str, test_child: str, parent_set: List, child_states_numb: int, tot_vars_count: int) → bool

Performs a complete independence test on the directed graphs G1 = {test_child U parent_set} G2 = {G1 U test_parent} (added as an additional parent of the test_child). Generates all the necessary structures and datas to perform the tests.

Parameters
  • test_parent (string) – the node label of the test parent

  • test_child (string) – the node label of the child

  • parent_set (List) – the common parent set

  • child_states_numb (int) – the cardinality of the test_child

  • tot_vars_count (int) – the total number of variables in the net

Returns

True iff test_child and test_parent are independent given the sep_set parent_set. False otherwise

Return type

bool

ctpc_algorithm() → None

Compute the CTPC algorithm over the entire net.

generate_possible_sub_sets_of_size(u: List, size: int, parent_label: str) → Iterator

Creates a list containing all possible subsets of the list u of size size, that do not contains a the node identified by parent_label.

Parameters
  • u (List) – the list of nodes

  • size (int) – the size of the subsets

  • parent_label (string) – the node to exclude in the subsets generation

Returns

an Iterator Object containing a list of lists

Return type

Iterator

independence_test(child_states_numb: int, cim1: conditional_intensity_matrix.ConditionalIntensityMatrix, cim2: conditional_intensity_matrix.ConditionalIntensityMatrix) → bool

Compute the actual independence test using two cims. It is performed first the exponential test and if the null hypothesis is not rejected, it is performed also the chi_test.

Parameters

:return:True iff both tests do NOT reject the null hypothesis of indipendence. False otherwise. :rtype: bool

one_iteration_of_CTPC_algorithm(var_id: str, tot_vars_count: int) → None

Performs an iteration of the CTPC algorithm using the node var_id as test_child.

Parameters
  • var_id (string) – the node label of the test child

  • tot_vars_count (int) – the number of _nodes in the net

save_results() → None

Save the estimated Structure to a .json file in the path where the data are loaded from. The file is named as the input dataset but the results_ word is appendend to the results file.