1
0
Fork 0

Merge branch 'develop' into parameters_estimation_by_variable

parallel_struct_est
philipMartini 4 years ago committed by GitHub
commit 71c7197e7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      main_package/classes/amalgamated_cims.py
  2. 1
      main_package/classes/conditional_intensity_matrix.py
  3. 24
      main_package/classes/json_importer.py
  4. 4
      main_package/classes/parameters_estimator.py
  5. 4
      main_package/classes/sample_path.py

@ -20,8 +20,9 @@ class AmalgamatedCims:
self.sets_of_cims.append( self.sets_of_cims.append(
socim.SetOfCims(key, list_of_parents_states_number[indx], states_number_per_node[indx])) 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): def get_cims_of_node(self, node_indx, cim_indx):
return self.sets_of_cims[node_indx].get_cim(cim_indx) return self.sets_of_cims[node_indx].get_cim(cim_indx)

@ -18,6 +18,7 @@ class ConditionalIntensityMatrix:
#print("Time updating In state", state, time) #print("Time updating In state", state, time)
self.state_residence_times[state] += time self.state_residence_times[state] += time
def compute_cim_coefficients(self): def compute_cim_coefficients(self):
np.fill_diagonal(self.cim, self.cim.diagonal() * -1) np.fill_diagonal(self.cim, self.cim.diagonal() * -1)
self.cim = ((self.cim.T + 1) / (self.state_residence_times + 1)).T self.cim = ((self.cim.T + 1) / (self.state_residence_times + 1)).T

@ -27,6 +27,7 @@ class JsonImporter(AbstractImporter):
self._df_structure = pd.DataFrame() self._df_structure = pd.DataFrame()
self._df_variables = pd.DataFrame() self._df_variables = pd.DataFrame()
self._concatenated_samples = None self._concatenated_samples = None
super(JsonImporter, self).__init__(files_path) super(JsonImporter, self).__init__(files_path)
def import_data(self): 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ù 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] 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): def build_list_of_samples_array(self, data_frame):
""" """
Costruisce una lista contenente le colonne presenti nel dataframe data_frame convertendole in numpy_array 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): def variables(self):
return self._df_variables return self._df_variables
@property @property
def structure(self): def structure(self):
return self._df_structure return self._df_structure
@ -165,3 +187,5 @@ print(ij.df_structure)
print(ij.df_variables) print(ij.df_variables)
print(ij.concatenated_samples)""" print(ij.concatenated_samples)"""

@ -1,4 +1,5 @@
import os import os
from line_profiler import LineProfiler from line_profiler import LineProfiler
import numba as nb import numba as nb
@ -20,6 +21,7 @@ class ParametersEstimator:
self.net_graph.get_nodes(), self.net_graph.get_nodes(),
self.net_graph.get_ordered_by_indx_parents_values_for_all_nodes()) self.net_graph.get_ordered_by_indx_parents_values_for_all_nodes())
def compute_parameters(self): def compute_parameters(self):
for node_indx, set_of_cims in enumerate(self.amalgamated_cims_struct.sets_of_cims): 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, 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) self.transition_scalar_index_converter[node_indx], set_of_cims.transition_matrices)
# Simple Test # # Simple Test #
os.getcwd() os.getcwd()
os.chdir('..') os.chdir('..')
@ -146,3 +149,4 @@ lp_wrapper()
#print(cond.cim) #print(cond.cim)
print(pe.amalgamated_cims_struct.get_cims_of_node(1,[2])) print(pe.amalgamated_cims_struct.get_cims_of_node(1,[2]))
lp.print_stats() lp.print_stats()

@ -40,6 +40,9 @@ class SamplePath:
def structure(self): def structure(self):
return self._structure return self._structure
"""os.getcwd()
os.chdir('..')
path = os.getcwd() + '/data'
"""os.getcwd() """os.getcwd()
@ -50,3 +53,4 @@ s1 = SamplePath(path)
s1.build_trajectories() s1.build_trajectories()
s1.build_structure() s1.build_structure()
print(s1.trajectories[0].get_complete_trajectory())""" print(s1.trajectories[0].get_complete_trajectory())"""