1
0
Fork 0

Some Ref JsonImp

parallel_struct_est
philpMartin 4 years ago
parent cef0280c09
commit 9419134a01
  1. 18
      main_package/classes/json_importer.py
  2. 2
      main_package/classes/structure_estimator.py
  3. 1
      main_package/tests/test_structure_estimator.py

@ -39,11 +39,12 @@ class JsonImporter(AbstractImporter):
def import_data(self): def import_data(self):
raw_data = self.read_json_file() raw_data = self.read_json_file()
self.import_variables(raw_data)
self.import_trajectories(raw_data) self.import_trajectories(raw_data)
self.compute_row_delta_in_all_samples_frames(self.time_key) self.compute_row_delta_in_all_samples_frames(self.time_key)
self.clear_data_frame_list() self.clear_data_frame_list()
self.import_structure(raw_data) self.import_structure(raw_data)
self.import_variables(raw_data, self.sorter) # self.import_variables(raw_data, self.sorter)
def import_trajectories(self, raw_data: pd.DataFrame): def import_trajectories(self, raw_data: pd.DataFrame):
self.normalize_trajectories(raw_data, 0, self.samples_label) self.normalize_trajectories(raw_data, 0, self.samples_label)
@ -51,10 +52,13 @@ class JsonImporter(AbstractImporter):
def import_structure(self, raw_data: pd.DataFrame): def import_structure(self, raw_data: pd.DataFrame):
self._df_structure = self.one_level_normalizing(raw_data, 0, self.structure_label) self._df_structure = self.one_level_normalizing(raw_data, 0, self.structure_label)
def import_variables(self, raw_data: pd.DataFrame, sorter: typing.List): def import_variables(self, raw_data: pd.DataFrame):
self._df_variables = self.one_level_normalizing(raw_data, 0, self.variables_label) self._df_variables = self.one_level_normalizing(raw_data, 0, self.variables_label)
self.sorter = self._df_variables[self.variables_key].to_list()
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].astype("category")
self._df_variables[self.variables_key] = self._df_variables[self.variables_key].cat.set_categories(sorter) self._df_variables[self.variables_key] = self._df_variables[self.variables_key].cat.set_categories(self.sorter)
self._df_variables = self._df_variables.sort_values([self.variables_key]) self._df_variables = self._df_variables.sort_values([self.variables_key])
def read_json_file(self) -> typing.List: def read_json_file(self) -> typing.List:
@ -105,7 +109,7 @@ class JsonImporter(AbstractImporter):
self.df_samples_list = [pd.DataFrame(sample) for sample in raw_data[indx][trajectories_key]] self.df_samples_list = [pd.DataFrame(sample) for sample in raw_data[indx][trajectories_key]]
#for sample_indx, sample in enumerate(raw_data[indx][trajectories_key]): #for sample_indx, sample in enumerate(raw_data[indx][trajectories_key]):
#self.df_samples_list.append(pd.DataFrame(sample)) #self.df_samples_list.append(pd.DataFrame(sample))
self.sorter = list(self.df_samples_list[0].columns.values)[1:] #self.sorter = list(self.df_samples_list[0].columns.values)[1:]
def compute_row_delta_sigle_samples_frame(self, sample_frame: pd.DataFrame, time_header_label: str, def compute_row_delta_sigle_samples_frame(self, sample_frame: pd.DataFrame, time_header_label: str,
columns_header: typing.List, shifted_cols_header: typing.List) \ columns_header: typing.List, shifted_cols_header: typing.List) \
@ -126,6 +130,12 @@ class JsonImporter(AbstractImporter):
self.df_samples_list[indx] = self.compute_row_delta_sigle_samples_frame(sample, self.df_samples_list[indx] = self.compute_row_delta_sigle_samples_frame(sample,
time_header_label, self.sorter, shifted_cols_header) time_header_label, self.sorter, shifted_cols_header)
self._concatenated_samples = pd.concat(self.df_samples_list) self._concatenated_samples = pd.concat(self.df_samples_list)
complete_header = self.sorter[:]
complete_header.insert(0, 'Time')
complete_header.extend(shifted_cols_header)
print("Complete Header", complete_header)
self._concatenated_samples = self._concatenated_samples[complete_header]
print("Concat Samples", self._concatenated_samples)
def build_list_of_samples_array(self, data_frame: pd.DataFrame) -> typing.List: def build_list_of_samples_array(self, data_frame: pd.DataFrame) -> typing.List:
""" """

@ -191,7 +191,7 @@ class StructureEstimator:
while b < len(u): while b < len(u):
#for parent_id in u: #for parent_id in u:
parent_indx = 0 parent_indx = 0
while u and parent_indx < tests_parents_numb and b < len(u): while parent_indx < len(u):
# list_without_test_parent = u.remove(parent_id) # list_without_test_parent = u.remove(parent_id)
removed = False removed = False
#print("b", b) #print("b", b)

@ -32,6 +32,7 @@ class TestStructureEstimator(unittest.TestCase):
lp.print_stats() lp.print_stats()
#se1.ctpc_algorithm() #se1.ctpc_algorithm()
print(se1.complete_graph.edges) print(se1.complete_graph.edges)
print(self.s1.structure.list_of_edges())
def aux_test_complete_test(self, estimator, test_par, test_child, p_set): def aux_test_complete_test(self, estimator, test_par, test_child, p_set):
estimator.complete_test(test_par, test_child, p_set) estimator.complete_test(test_par, test_child, p_set)