diff --git a/main_package/classes/json_importer.py b/main_package/classes/json_importer.py index 1b291a2..bde6212 100644 --- a/main_package/classes/json_importer.py +++ b/main_package/classes/json_importer.py @@ -94,7 +94,7 @@ class JsonImporter(AbstractImporter): #self.sorter.sort() #print("Sorter:", self.sorter) self._df_variables[self.variables_key] = self._df_variables[self.variables_key].astype("category") - self._df_variables[self.variables_key] = self._df_variables[self.variables_key].cat.set_categories(self.sorter) + self._df_variables[self.variables_key] = self._df_variables[self.variables_key].cat.set_categories(sorter) self._df_variables = self._df_variables.sort_values([self.variables_key]) self._df_variables.reset_index(inplace=True) print("Var Frame", self._df_variables) @@ -186,14 +186,8 @@ class JsonImporter(AbstractImporter): Returns: void """ - """columns_header = list(self.df_samples_list[0].columns.values) - columns_header.remove('Time') - self.sorter = columns_header""" shifted_cols_header = [s + "S" for s in self.sorter] compute_row_delta = self.compute_row_delta_sigle_samples_frame - """for indx, sample in enumerate(self.df_samples_list): - self.df_samples_list[indx] = self.compute_row_delta_sigle_samples_frame(sample, - time_header_label, self.sorter, shifted_cols_header)""" self.df_samples_list = [compute_row_delta(sample, time_header_label, self.sorter, shifted_cols_header) for sample in self.df_samples_list] self._concatenated_samples = pd.concat(self.df_samples_list) diff --git a/main_package/classes/parameters_estimator.py b/main_package/classes/parameters_estimator.py index 18b60b0..566e37c 100644 --- a/main_package/classes/parameters_estimator.py +++ b/main_package/classes/parameters_estimator.py @@ -22,12 +22,6 @@ class ParametersEstimator: self.sets_of_cims_struct = None self.single_set_of_cims = None - def init_sets_cims_container(self): - self.sets_of_cims_struct = acims.SetsOfCimsContainer(self.net_graph.nodes, - self.net_graph.nodes_values, - self.net_graph.get_ordered_by_indx_parents_values_for_all_nodes(), - self.net_graph.p_combs) - def fast_init(self, node_id: str): """ Initializes all the necessary structures for the parameters estimation. @@ -41,28 +35,6 @@ class ParametersEstimator: node_states_number = self.net_graph.get_states_number(node_id) self.single_set_of_cims = sofc.SetOfCims(node_id, p_vals, node_states_number, self.net_graph.p_combs) - - def compute_parameters(self): - #print(self.net_graph.get_nodes()) - #print(self.amalgamated_cims_struct.sets_of_cims) - #enumerate(zip(self.net_graph.get_nodes(), self.amalgamated_cims_struct.sets_of_cims)) - for indx, aggr in enumerate(zip(self.net_graph.nodes, self.sets_of_cims_struct.sets_of_cims)): - #print(self.net_graph.time_filtering[indx]) - #print(self.net_graph.time_scalar_indexing_strucure[indx]) - self.compute_state_res_time_for_node(self.net_graph.get_node_indx(aggr[0]), self.sample_path.trajectories.times, - self.sample_path.trajectories.trajectory, - self.net_graph.time_filtering[indx], - self.net_graph.time_scalar_indexing_strucure[indx], - aggr[1].state_residence_times) - #print(self.net_graph.transition_filtering[indx]) - #print(self.net_graph.transition_scalar_indexing_structure[indx]) - self.compute_state_transitions_for_a_node(self.net_graph.get_node_indx(aggr[0]), - self.sample_path.trajectories.complete_trajectory, - self.net_graph.transition_filtering[indx], - self.net_graph.transition_scalar_indexing_structure[indx], - aggr[1].transition_matrices) - aggr[1].build_cims(aggr[1].state_residence_times, aggr[1].transition_matrices) - def compute_parameters_for_node(self, node_id: str) -> sofc.SetOfCims: """ Compute the CIMS of the node identified by the label node_id @@ -132,6 +104,33 @@ class ParametersEstimator: M_raveled[diag_indices] = 0 M_raveled[diag_indices] = np.sum(M, axis=2).ravel() + def init_sets_cims_container(self): + self.sets_of_cims_struct = acims.SetsOfCimsContainer(self.net_graph.nodes, + self.net_graph.nodes_values, + self.net_graph.get_ordered_by_indx_parents_values_for_all_nodes(), + self.net_graph.p_combs) + + def compute_parameters(self): + #print(self.net_graph.get_nodes()) + #print(self.amalgamated_cims_struct.sets_of_cims) + #enumerate(zip(self.net_graph.get_nodes(), self.amalgamated_cims_struct.sets_of_cims)) + for indx, aggr in enumerate(zip(self.net_graph.nodes, self.sets_of_cims_struct.sets_of_cims)): + #print(self.net_graph.time_filtering[indx]) + #print(self.net_graph.time_scalar_indexing_strucure[indx]) + self.compute_state_res_time_for_node(self.net_graph.get_node_indx(aggr[0]), self.sample_path.trajectories.times, + self.sample_path.trajectories.trajectory, + self.net_graph.time_filtering[indx], + self.net_graph.time_scalar_indexing_strucure[indx], + aggr[1].state_residence_times) + #print(self.net_graph.transition_filtering[indx]) + #print(self.net_graph.transition_scalar_indexing_structure[indx]) + self.compute_state_transitions_for_a_node(self.net_graph.get_node_indx(aggr[0]), + self.sample_path.trajectories.complete_trajectory, + self.net_graph.transition_filtering[indx], + self.net_graph.transition_scalar_indexing_structure[indx], + aggr[1].transition_matrices) + aggr[1].build_cims(aggr[1].state_residence_times, aggr[1].transition_matrices) + diff --git a/main_package/setup.py b/main_package/setup.py new file mode 100644 index 0000000..5f4b403 --- /dev/null +++ b/main_package/setup.py @@ -0,0 +1,12 @@ +from setuptools import setup, find_packages + +setup(name='ctbn', + version='1.0', + url='https://github.com/philipMartini/CTBN_Project', + #license='MIT', + author='Filippo Martini', + author_email='f.martini@campus.unimib.it', + description='A Continuous Time Bayesian Network Library', + packages=find_packages(exclude=['tests', 'data']), + long_description=open('README.md').read(), + zip_safe=False) \ No newline at end of file