parent
a20ed4e0eb
commit
4356eee147
@ -1,20 +1,24 @@ |
|||||||
import conditional_intensity_matrix as cim |
import set_of_cims as socim |
||||||
import numpy as np |
import numpy as np |
||||||
|
|
||||||
|
|
||||||
class AmalgamatedCims: |
class AmalgamatedCims: |
||||||
|
|
||||||
def __init__(self, states_number,list_of_keys, list_of_matrices_dims): |
def __init__(self, states_number,list_of_keys, nodes_value, list_of_vars_order): |
||||||
self.actual_cims = {} |
self.actual_cims = {} |
||||||
self.init_cims_structure(list_of_keys, list_of_matrices_dims) |
self.init_cims_structure(list_of_keys, nodes_value, list_of_vars_order) |
||||||
self.states_per_variable = states_number |
self.states_per_variable = states_number |
||||||
|
|
||||||
def init_cims_structure(self, keys, dims): |
def init_cims_structure(self, keys, nodes_val, list_of_vars_order): |
||||||
for key, dim in (keys, dims): |
for key, vars_order in (keys, list_of_vars_order): |
||||||
self.actual_cims[key] = np.empty(dim, dtype=cim.ConditionalIntensityMatrix) |
self.actual_cims[key] = socim.SetOfCims(key, vars_order, nodes_val) |
||||||
for key in self.actual_cims.keys(): |
|
||||||
for indx in range(len(self.actual_cims[key])): |
|
||||||
self.actual_cims[key][indx] = cim.ConditionalIntensityMatrix(self.states_per_variable) |
|
||||||
|
|
||||||
def compute_matrix_indx(self, row, col): |
def compute_matrix_indx(self, row, col): |
||||||
return self.state_per_variable * row + col |
return self.state_per_variable * row + col |
||||||
|
|
||||||
|
def get_vars_order(self, node): |
||||||
|
return self.actual_cims[node][1] |
||||||
|
|
||||||
|
def update_state_transition_for_matrix(self, node, dict_of_indxs, element_indx): |
||||||
|
self.actual_cims[node] |
||||||
|
@ -0,0 +1,35 @@ |
|||||||
|
import numpy as np |
||||||
|
import conditional_intensity_matrix as cim |
||||||
|
|
||||||
|
|
||||||
|
class SetOfCims: |
||||||
|
|
||||||
|
def __init__(self, node_id, ordered_parent_set, value_type): |
||||||
|
self.node_id = node_id |
||||||
|
self.ordered_parent_set = ordered_parent_set |
||||||
|
self.value = value_type |
||||||
|
self.actual_cims = None |
||||||
|
|
||||||
|
def build_actual_cims_structure(self): |
||||||
|
cims_number = self.value**len(self.ordered_parent_set) |
||||||
|
self.actual_cims = np.empty(cims_number, dtype=cim.ConditionalIntensityMatrix) |
||||||
|
for indx, matrix in enumerate(self.actual_cims): |
||||||
|
self.actual_cims[indx] = cim.ConditionalIntensityMatrix(self.value) |
||||||
|
|
||||||
|
def indexes_converter(self, dict_of_indexes): # Si aspetta oggetti del tipo {X:1, Y:1, Z:0} |
||||||
|
literal_index = "" |
||||||
|
for node in self.ordered_parent_set: |
||||||
|
literal_index = literal_index + str(dict_of_indexes[node]) |
||||||
|
return int(literal_index, self.value) |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sofc = SetOfCims('W', ['X','Y', 'Z'], 2) |
||||||
|
#sofc.build_actual_cims_structure(sofc.ordered_parent_set, sofc.value) |
||||||
|
|
||||||
|
sofc.build_actual_cims_structure() |
||||||
|
print(sofc.actual_cims) |
||||||
|
print(sofc.indexes_converter({'X':1, 'Y':1, 'Z':0})) |
||||||
|
|
||||||
|
|
||||||
|
|
Reference in new issue