|
|
@ -1,5 +1,7 @@ |
|
|
|
import os |
|
|
|
import os |
|
|
|
import time as tm |
|
|
|
import time as tm |
|
|
|
|
|
|
|
from line_profiler import LineProfiler |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import network_graph as ng |
|
|
|
import network_graph as ng |
|
|
|
import sample_path as sp |
|
|
|
import sample_path as sp |
|
|
@ -30,34 +32,11 @@ class ParametersEstimator: |
|
|
|
print("Elapsed Time ", t1) |
|
|
|
print("Elapsed Time ", t1) |
|
|
|
|
|
|
|
|
|
|
|
def parameters_estimation_single_trajectory(self, trajectory): |
|
|
|
def parameters_estimation_single_trajectory(self, trajectory): |
|
|
|
#t0 = tm.time() |
|
|
|
|
|
|
|
row_length = trajectory.shape[1] |
|
|
|
row_length = trajectory.shape[1] |
|
|
|
for indx, row in enumerate(trajectory[:-1]): |
|
|
|
for indx, row in enumerate(trajectory[:-1]): |
|
|
|
self.compute_sufficient_statistics_for_row(trajectory[indx], trajectory[indx + 1], row_length) |
|
|
|
self.compute_sufficient_statistics_for_row(trajectory[indx], trajectory[indx + 1], row_length) |
|
|
|
"""if trajectory[indx + 1][1] != -1: |
|
|
|
|
|
|
|
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] |
|
|
|
|
|
|
|
self.amalgamated_cims_struct.update_state_transition_for_matrix(which_node, which_matrix, which_element) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#changed_node = which_node |
|
|
|
|
|
|
|
time = self.compute_time_delta(trajectory[indx], trajectory[indx + 1]) |
|
|
|
|
|
|
|
which_element = transition[1][0] |
|
|
|
|
|
|
|
self.amalgamated_cims_struct.update_state_residence_time_for_matrix(which_node, which_matrix, which_element, |
|
|
|
|
|
|
|
time) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for node_indx in range(0, 3): |
|
|
|
|
|
|
|
if node_indx != transition[0]: |
|
|
|
|
|
|
|
# print(node) |
|
|
|
|
|
|
|
which_node = node_indx |
|
|
|
|
|
|
|
which_matrix = self.which_matrix_to_update(row, node_indx) |
|
|
|
|
|
|
|
which_element = row[node_indx + 1] |
|
|
|
|
|
|
|
self.amalgamated_cims_struct.update_state_residence_time_for_matrix( |
|
|
|
|
|
|
|
which_node, which_matrix, which_element, time)""" |
|
|
|
|
|
|
|
#t1 = tm.time() - t0 |
|
|
|
|
|
|
|
#print("Elapsed Time ", t1) |
|
|
|
|
|
|
|
def compute_sufficient_statistics_for_row(self, current_row, next_row, row_length): |
|
|
|
def compute_sufficient_statistics_for_row(self, current_row, next_row, row_length): |
|
|
|
#time = self.compute_time_delta(current_row, next_row) |
|
|
|
#time = self.compute_time_delta(current_row, next_row) |
|
|
|
time = current_row[0] |
|
|
|
time = current_row[0] |
|
|
@ -80,7 +59,6 @@ class ParametersEstimator: |
|
|
|
which_node, which_matrix, which_element, time) |
|
|
|
which_node, which_matrix, which_element, time) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def find_transition(self, current_row, next_row, row_length): |
|
|
|
def find_transition(self, current_row, next_row, row_length): |
|
|
|
for indx in range(1, row_length): |
|
|
|
for indx in range(1, row_length): |
|
|
|
if current_row[indx] != next_row[indx]: |
|
|
|
if current_row[indx] != next_row[indx]: |
|
|
@ -90,8 +68,8 @@ class ParametersEstimator: |
|
|
|
def compute_time_delta(self, current_row, next_row): |
|
|
|
def compute_time_delta(self, current_row, next_row): |
|
|
|
return next_row[0] - current_row[0] |
|
|
|
return next_row[0] - current_row[0] |
|
|
|
|
|
|
|
|
|
|
|
def which_matrix_to_update(self, current_row, node_indx): # produce strutture {'X':1, 'Y':2} dove X e Y sono i parent di node_id |
|
|
|
def which_matrix_to_update(self, current_row, node_indx): |
|
|
|
return current_row[self.fancy_indexing_structure[node_indx]] |
|
|
|
return tuple(current_row.take(self.fancy_indexing_structure[node_indx])) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -116,6 +94,12 @@ 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()) |
|
|
|
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_single_trajectory(pe.sample_path.trajectories[0].get_trajectory()) |
|
|
|
pe.parameters_estimation() |
|
|
|
pe.parameters_estimation() |
|
|
|
|
|
|
|
"""lp = LineProfiler() |
|
|
|
|
|
|
|
lp.add_function(pe.compute_sufficient_statistics_for_row) # add additional function to profile |
|
|
|
|
|
|
|
lp_wrapper = lp(pe.parameters_estimation_single_trajectory) |
|
|
|
|
|
|
|
#lp_wrapper = lp(pe.parameters_estimation) |
|
|
|
|
|
|
|
lp_wrapper(pe.sample_path.trajectories[0].get_trajectory()) |
|
|
|
|
|
|
|
lp.print_stats()""" |
|
|
|
for matrix in pe.amalgamated_cims_struct.get_set_of_cims(1).actual_cims: |
|
|
|
for matrix in pe.amalgamated_cims_struct.get_set_of_cims(1).actual_cims: |
|
|
|
print(matrix.state_residence_times) |
|
|
|
print(matrix.state_residence_times) |
|
|
|
print(matrix.state_transition_matrix) |
|
|
|
print(matrix.state_transition_matrix) |
|
|
|