parent
864ffbd319
commit
b374d60117
@ -1,68 +1,78 @@ |
|||||||
|
import typing as ty |
||||||
import numpy as np |
import numpy as np |
||||||
|
|
||||||
|
|
||||||
class Structure: |
class Structure: |
||||||
""" |
""" |
||||||
Contiene tutte il informazioni sulla struttura della rete (connessione dei nodi, valori assumibili dalle variabili) |
Contains all the infos about the network structure(nodes names, nodes caridinalites, edges...) |
||||||
|
|
||||||
:structure_frame: il dataframe contenente le connessioni dei nodi della rete |
:nodes_labels_list: the symbolic names of the variables |
||||||
:variables_frame: il data_frame contenente i valori assumibili dalle variabili e si suppone il corretto ordinamento |
:nodes_indexes_arr: the indexes of the nodes |
||||||
rispetto alle colonne del dataset |
:nodes_vals_arr: the cardinalites of the nodes |
||||||
|
:edges_list: the edges of the network |
||||||
|
:total_variables_number: the total number of variables in the net |
||||||
""" |
""" |
||||||
|
|
||||||
def __init__(self, nodes_label_list, node_indexes_arr, nodes_vals_arr, edges_list, total_variables_number): |
def __init__(self, nodes_label_list: ty.List, node_indexes_arr: np.array, nodes_vals_arr: np.array, |
||||||
#self.structure_frame = structure |
edges_list: ty.List, total_variables_number: int): |
||||||
#self.variables_frame = variables |
self._nodes_labels_list = nodes_label_list |
||||||
self.nodes_labels_list = nodes_label_list |
self._nodes_indexes_arr = node_indexes_arr |
||||||
self.nodes_indexes_arr = node_indexes_arr |
self._nodes_vals_arr = nodes_vals_arr |
||||||
self.nodes_vals_arr = nodes_vals_arr |
self._edges_list = edges_list |
||||||
self.edges_list = edges_list |
self._total_variables_number = total_variables_number |
||||||
self.total_variables_number = total_variables_number |
|
||||||
#self.name_label = variables.columns.values[0] |
@property |
||||||
#self.value_label = variables.columns.values[1] |
def edges(self): |
||||||
|
|
||||||
def list_of_edges(self): |
|
||||||
#records = self.structure_frame.to_records(index=False) |
#records = self.structure_frame.to_records(index=False) |
||||||
#edges_list = list(records) |
#edges_list = list(records) |
||||||
return self.edges_list |
return self._edges_list |
||||||
|
|
||||||
def list_of_nodes_labels(self): |
@property |
||||||
return self.nodes_labels_list |
def nodes_labels(self): |
||||||
|
return self._nodes_labels_list |
||||||
|
|
||||||
def list_of_nodes_indexes(self): |
@property |
||||||
return self.nodes_indexes_arr |
def nodes_indexes(self): |
||||||
|
return self._nodes_indexes_arr |
||||||
|
|
||||||
def get_node_id(self, node_indx): |
@property |
||||||
return self.nodes_labels_list[node_indx] |
def nodes_values(self): |
||||||
|
return self._nodes_vals_arr |
||||||
|
|
||||||
def get_node_indx(self, node_id): |
@property |
||||||
return self.nodes_indexes_arr[self.nodes_labels_list.index(node_id)] |
def total_variables_number(self): |
||||||
|
return self._total_variables_number |
||||||
|
|
||||||
def get_positional_node_indx(self, node_id): |
def get_node_id(self, node_indx: int): |
||||||
return self.nodes_labels_list.index(node_id) |
return self._nodes_labels_list[node_indx] |
||||||
|
|
||||||
def get_states_number(self, node): |
def get_node_indx(self, node_id: str): |
||||||
#print("node", node) |
pos_indx = self._nodes_labels_list.index(node_id) |
||||||
return self.nodes_vals_arr[self.get_positional_node_indx(node)] |
return self._nodes_indexes_arr[pos_indx] |
||||||
|
|
||||||
def get_states_number_by_indx(self, node_indx): |
def get_positional_node_indx(self, node_id: str): |
||||||
#print(self.value_label) |
return self._nodes_labels_list.index(node_id) |
||||||
#print("Node indx", node_indx) |
|
||||||
return self.nodes_vals_arr[node_indx] |
|
||||||
|
|
||||||
def nodes_values(self): |
def get_states_number(self, node: str): |
||||||
return self.nodes_vals_arr |
pos_indx = self._nodes_labels_list.index(node) |
||||||
|
return self._nodes_vals_arr[pos_indx] |
||||||
|
|
||||||
def total_variables_number(self): |
def get_states_number_by_indx(self, node_indx: int): |
||||||
return self.total_variables_number |
#print(self.value_label) |
||||||
|
#print("Node indx", node_indx) |
||||||
|
return self._nodes_vals_arr[node_indx] |
||||||
|
|
||||||
def __repr__(self): |
def __repr__(self): |
||||||
return "Variables:\n" + str(self.variables_frame) + "\nEdges: \n" + str(self.structure_frame) |
return "Variables:\n" + str(self._nodes_labels_list) +"\nValues:\n"+ str(self._nodes_vals_arr) +\ |
||||||
|
"\nEdges: \n" + str(self._edges_list) |
||||||
|
|
||||||
def __eq__(self, other): |
def __eq__(self, other): |
||||||
"""Overrides the default implementation""" |
"""Overrides the default implementation""" |
||||||
if isinstance(other, Structure): |
if isinstance(other, Structure): |
||||||
return self.structure_frame.equals(other.structure_frame) and \ |
return set(self._nodes_labels_list) == set(other._nodes_labels_list) and \ |
||||||
self.variables_frame.equals(other.variables_frame) |
np.array_equal(self._nodes_vals_arr, other._nodes_vals_arr) and \ |
||||||
|
np.array_equal(self._nodes_indexes_arr, other._nodes_indexes_arr) and \ |
||||||
|
set(self._edges_list) == set(other._edges_list) |
||||||
|
|
||||||
return NotImplemented |
return NotImplemented |
||||||
|
|
||||||
|
Reference in new issue