From fd43774766f21e6e6e09e476d6f9051aa9d49be1 Mon Sep 17 00:00:00 2001 From: philpMartin Date: Sat, 4 Jul 2020 16:36:57 +0200 Subject: [PATCH] Changed AmalgCim Struct to List --- main_package/classes/amalgamated_cims.py | 5 ++-- main_package/classes/parameters_estimator.py | 27 ++++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/main_package/classes/amalgamated_cims.py b/main_package/classes/amalgamated_cims.py index 65138e5..750e60a 100644 --- a/main_package/classes/amalgamated_cims.py +++ b/main_package/classes/amalgamated_cims.py @@ -9,7 +9,7 @@ class AmalgamatedCims: """ # list_of_vars_orders contiene tutte le liste con i parent ordinati secondo il valore indx def __init__(self, states_number_per_node, list_of_keys, list_of_parents_states_number): - self.sets_of_cims = {} + self.sets_of_cims = [] self.init_cims_structure(list_of_keys, states_number_per_node, list_of_parents_states_number) #self.states_per_variable = states_number @@ -17,7 +17,8 @@ class AmalgamatedCims: print(keys) print(list_of_parents_states_number) for indx, key in enumerate(keys): - self.sets_of_cims[key] = socim.SetOfCims(key, list_of_parents_states_number[indx], states_number_per_node[indx]) + self.sets_of_cims.append( + socim.SetOfCims(key, list_of_parents_states_number[indx], states_number_per_node[indx])) def get_set_of_cims(self, node_id): return self.sets_of_cims[node_id] diff --git a/main_package/classes/parameters_estimator.py b/main_package/classes/parameters_estimator.py index 4ac0563..b54e503 100644 --- a/main_package/classes/parameters_estimator.py +++ b/main_package/classes/parameters_estimator.py @@ -29,13 +29,13 @@ class ParametersEstimator: print("Elapsed Time ", t1) def parameters_estimation_single_trajectory(self, trajectory): - #print(type(trajectory[0][0])) + row_length = trajectory.shape[1] for indx, row in enumerate(trajectory): if trajectory[indx][1] == -1: break if trajectory[indx + 1][1] != -1: - transition = self.find_transition(trajectory[indx], trajectory[indx + 1]) - which_node = self.net_graph.get_node_by_index(transition[0]) + transition = self.find_transition(trajectory[indx], trajectory[indx + 1], row_length) + which_node = transition[0] # print(which_node) which_matrix = self.which_matrix_to_update(row, transition[0]) which_element = transition[1] @@ -44,19 +44,18 @@ class ParametersEstimator: #changed_node = which_node time = self.compute_time_delta(trajectory[indx], trajectory[indx + 1]) - for node_indx, node in enumerate(self.net_graph.get_nodes()): + for node_indx in range(0, 3): #if node != changed_node: # print(node) - which_node = node + which_node = node_indx which_matrix = self.which_matrix_to_update(row, node_indx) which_element = row[node_indx + 1] - # print("State res time element " + str(which_element) + node) - # print("State res time matrix indx" + str(which_matrix)) - self.amalgamated_cims_struct.update_state_residence_time_for_matrix(which_node, which_matrix, which_element, time) + self.amalgamated_cims_struct.update_state_residence_time_for_matrix( + which_node, which_matrix, which_element, time) - def find_transition(self, current_row, next_row): - for indx in range(1, len(current_row)): + def find_transition(self, current_row, next_row, row_length): + for indx in range(1, row_length): if current_row[indx] != next_row[indx]: return [indx - 1, (current_row[indx], next_row[indx])] @@ -85,12 +84,12 @@ g1.init_graph() pe = ParametersEstimator(s1, g1) pe.init_amalgamated_cims_struct() -print(pe.amalgamated_cims_struct.get_set_of_cims('X').get_cims_number()) -print(pe.amalgamated_cims_struct.get_set_of_cims('Y').get_cims_number()) -print(pe.amalgamated_cims_struct.get_set_of_cims('Z').get_cims_number()) +print(pe.amalgamated_cims_struct.get_set_of_cims(0).get_cims_number()) +print(pe.amalgamated_cims_struct.get_set_of_cims(1).get_cims_number()) +print(pe.amalgamated_cims_struct.get_set_of_cims(2).get_cims_number()) #pe.parameters_estimation_single_trajectory(pe.sample_path.trajectories[0].get_trajectory()) pe.parameters_estimation() -for matrix in pe.amalgamated_cims_struct.get_set_of_cims('Y').actual_cims: +for matrix in pe.amalgamated_cims_struct.get_set_of_cims(1).actual_cims: print(matrix.state_residence_times) print(matrix.state_transition_matrix) matrix.compute_cim_coefficients()