diff --git a/main_package/classes/amalgamated_cims.py b/main_package/classes/amalgamated_cims.py index 52f4f69..dfd154a 100644 --- a/main_package/classes/amalgamated_cims.py +++ b/main_package/classes/amalgamated_cims.py @@ -20,8 +20,9 @@ class AmalgamatedCims: 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] + + def get_set_of_cims(self, node_indx): + return self.sets_of_cims[node_indx] def get_cims_of_node(self, node_indx, cim_indx): return self.sets_of_cims[node_indx].get_cim(cim_indx) diff --git a/main_package/classes/conditional_intensity_matrix.py b/main_package/classes/conditional_intensity_matrix.py index a29db61..bffd040 100644 --- a/main_package/classes/conditional_intensity_matrix.py +++ b/main_package/classes/conditional_intensity_matrix.py @@ -18,6 +18,7 @@ class ConditionalIntensityMatrix: #print("Time updating In state", state, time) self.state_residence_times[state] += time + def compute_cim_coefficients(self): np.fill_diagonal(self.cim, self.cim.diagonal() * -1) self.cim = ((self.cim.T + 1) / (self.state_residence_times + 1)).T diff --git a/main_package/classes/json_importer.py b/main_package/classes/json_importer.py index 3ea4c33..45ecd6a 100644 --- a/main_package/classes/json_importer.py +++ b/main_package/classes/json_importer.py @@ -27,6 +27,7 @@ class JsonImporter(AbstractImporter): self._df_structure = pd.DataFrame() self._df_variables = pd.DataFrame() self._concatenated_samples = None + super(JsonImporter, self).__init__(files_path) def import_data(self): @@ -115,6 +116,26 @@ class JsonImporter(AbstractImporter): for indx in range(len(self.df_samples_list)): # Le singole traj non servono piĆ¹ self.df_samples_list[indx] = self.df_samples_list[indx].iloc[0:0] + def compute_row_delta_sigle_samples_frame(self, sample_frame): + columns_header = list(sample_frame.columns.values) + #print(columns_header) + for col_name in columns_header: + if col_name == 'Time': + sample_frame[col_name + 'Delta'] = sample_frame[col_name].diff() + #else: + #sample_frame[col_name + 'Delta'] = (sample_frame[col_name].diff().bfill() != 0).astype(int) + #sample_frame['Delta'] = sample_frame['Time'].diff() + #print(sample_frame) + + def compute_row_delta_in_all_samples_frames(self): + for sample in self.df_samples_list: + self.compute_row_delta_sigle_samples_frame(sample) + self.concatenated_samples = pd.concat(self.df_samples_list) + self.concatenated_samples['Time'] = self.concatenated_samples['TimeDelta'] + del self.concatenated_samples['TimeDelta'] + self.concatenated_samples['Time'] = self.concatenated_samples['Time'].fillna(0) + + def build_list_of_samples_array(self, data_frame): """ Costruisce una lista contenente le colonne presenti nel dataframe data_frame convertendole in numpy_array @@ -147,6 +168,7 @@ class JsonImporter(AbstractImporter): def variables(self): return self._df_variables + @property def structure(self): return self._df_structure @@ -165,3 +187,5 @@ print(ij.df_structure) print(ij.df_variables) print(ij.concatenated_samples)""" + + diff --git a/main_package/classes/parameters_estimator.py b/main_package/classes/parameters_estimator.py index e035540..6073484 100644 --- a/main_package/classes/parameters_estimator.py +++ b/main_package/classes/parameters_estimator.py @@ -1,4 +1,5 @@ import os + from line_profiler import LineProfiler import numba as nb @@ -20,6 +21,7 @@ class ParametersEstimator: self.net_graph.get_nodes(), self.net_graph.get_ordered_by_indx_parents_values_for_all_nodes()) + def compute_parameters(self): for node_indx, set_of_cims in enumerate(self.amalgamated_cims_struct.sets_of_cims): self.compute_state_res_time_for_node(node_indx, self.sample_path.trajectories.times, @@ -86,6 +88,7 @@ class ParametersEstimator: self.transition_scalar_index_converter[node_indx], set_of_cims.transition_matrices) + # Simple Test # os.getcwd() os.chdir('..') @@ -145,4 +148,5 @@ lp_wrapper() #for cond in variable.get_cims(): #print(cond.cim) print(pe.amalgamated_cims_struct.get_cims_of_node(1,[2])) -lp.print_stats() \ No newline at end of file +lp.print_stats() + diff --git a/main_package/classes/sample_path.py b/main_package/classes/sample_path.py index 407f53e..acee6c1 100644 --- a/main_package/classes/sample_path.py +++ b/main_package/classes/sample_path.py @@ -40,6 +40,9 @@ class SamplePath: def structure(self): return self._structure +"""os.getcwd() +os.chdir('..') +path = os.getcwd() + '/data' """os.getcwd() @@ -50,3 +53,4 @@ s1 = SamplePath(path) s1.build_trajectories() s1.build_structure() print(s1.trajectories[0].get_complete_trajectory())""" +