1
0
Fork 0

Added parameters aplha_xu and tau_xu and ensambled model simulation

master
Luca Moretti 4 years ago
parent 301ff69a8d
commit bb4745f430
  1. 2
      main_package/classes/estimators/fam_score_calculator.py
  2. 9
      main_package/classes/estimators/structure_constraint_based_estimator.py
  3. 16
      main_package/classes/estimators/structure_estimator.py
  4. 11
      main_package/classes/estimators/structure_score_based_estimator.py
  5. 2
      main_package/classes/optimizers/hill_climbing_search.py
  6. 2
      main_package/classes/optimizers/tabu_search.py
  7. 198
      main_package/tests/results/results.csv
  8. 20
      main_package/tests/results/results16-32RAM.csv
  9. 1153
      main_package/tests/results/results_tabu.csv
  10. 84
      main_package/tests/simulators/test_ensambled_model.py
  11. 134
      main_package/tests/simulators/test_ensambled_model_all.py
  12. 3
      main_package/tests/simulators/test_simulation_score.py

@ -207,7 +207,7 @@ class FamScoreCalculator:
def get_fam_score(self, def get_fam_score(self,
cims: np.array, cims: np.array,
tau_xu: float=1, tau_xu: float=0.1,
alpha_xu: float=1): alpha_xu: float=1):
""" """
calculate the FamScore value of the node identified by the label node_id calculate the FamScore value of the node identified by the label node_id

@ -211,7 +211,7 @@ class StructureConstraintBasedEstimator(se.StructureEstimator):
tot_vars_count = tot_vars_count) tot_vars_count = tot_vars_count)
optimizer_obj.optimize_structure() optimizer_obj.optimize_structure()
@timing_write @timing
def ctpc_algorithm(self): def ctpc_algorithm(self):
""" """
Compute the CTPC algorithm. Compute the CTPC algorithm.
@ -224,4 +224,11 @@ class StructureConstraintBasedEstimator(se.StructureEstimator):
total_vars_numb = self.sample_path.total_variables_count total_vars_numb = self.sample_path.total_variables_count
[ctpc_algo(n, total_vars_numb) for n in self.nodes] [ctpc_algo(n, total_vars_numb) for n in self.nodes]
@timing
def estimate_structure(self):
self.ctpc_algorithm()
return set(self.complete_graph.edges)

@ -10,6 +10,8 @@ from networkx.readwrite import json_graph
from abc import ABC from abc import ABC
import abc
import utility.cache as ch import utility.cache as ch
import structure_graph.conditional_intensity_matrix as condim import structure_graph.conditional_intensity_matrix as condim
import structure_graph.network_graph as ng import structure_graph.network_graph as ng
@ -94,3 +96,17 @@ class StructureEstimator(ABC):
s0, s1 = matrix.strides s0, s1 = matrix.strides
return strided(matrix.ravel()[1:], shape=(m - 1, m), strides=(s0 + s1, s1)).reshape(m, -1) return strided(matrix.ravel()[1:], shape=(m - 1, m), strides=(s0 + s1, s1)).reshape(m, -1)
@abc.abstractmethod
def estimate_structure(self) -> typing.List:
"""
Compute Optimization process for a structure_estimator
Parameters:
Returns:
the estimated structure for the node
"""
pass

@ -41,11 +41,13 @@ class StructureScoreBasedEstimator(se.StructureEstimator):
""" """
def __init__(self, sample_path: sp.SamplePath): def __init__(self, sample_path: sp.SamplePath, tau_xu:int=0.1, alpha_xu:int = 1):
super().__init__(sample_path) super().__init__(sample_path)
self.tau_xu=tau_xu
self.alpha_xu=alpha_xu
@timing_write @timing
def estimate_structure(self, max_parents:int = None, iterations_number:int= 40, def estimate_structure(self, max_parents:int = None, iterations_number:int= 40,
patience:int = None, tabu_length:int = None, tabu_rules_duration:int = None, patience:int = None, tabu_length:int = None, tabu_rules_duration:int = None,
optimizer: str = 'hill',disable_multiprocessing:bool= False ): optimizer: str = 'hill',disable_multiprocessing:bool= False ):
@ -176,7 +178,8 @@ class StructureScoreBasedEstimator(se.StructureEstimator):
return optimizer.optimize_structure() return optimizer.optimize_structure()
def get_score_from_graph(self,graph: ng.NetworkGraph,node_id:str): def get_score_from_graph(self,
graph: ng.NetworkGraph,node_id:str):
""" """
Use the FamScore of a node in order to find the best parent nodes Use the FamScore of a node in order to find the best parent nodes
Parameters: Parameters:
@ -198,7 +201,7 @@ class StructureScoreBasedEstimator(se.StructureEstimator):
'calculate the FamScore for the node' 'calculate the FamScore for the node'
fam_score_obj = fam_score.FamScoreCalculator() fam_score_obj = fam_score.FamScoreCalculator()
score = fam_score_obj.get_fam_score(SoCims.actual_cims) score = fam_score_obj.get_fam_score(SoCims.actual_cims,tau_xu = self.tau_xu,alpha_xu=self.alpha_xu)
#print(f" lo score per {node_id} risulta: {score} ") #print(f" lo score per {node_id} risulta: {score} ")
return score return score

@ -34,6 +34,8 @@ class HillClimbing(Optimizer):
Compute Optimization process for a structure_estimator Compute Optimization process for a structure_estimator
Parameters: Parameters:
node_id: the node label
structure_estimator: a structure estimator object with the information about the net
max_parents: maximum number of parents for each variable. If None, disabled max_parents: maximum number of parents for each variable. If None, disabled
iterations_number: maximum number of optimization algorithm's iteration iterations_number: maximum number of optimization algorithm's iteration
patience: number of iteration without any improvement before to stop the search.If None, disabled patience: number of iteration without any improvement before to stop the search.If None, disabled

@ -38,6 +38,8 @@ class TabuSearch(Optimizer):
Compute Optimization process for a structure_estimator Compute Optimization process for a structure_estimator
Parameters: Parameters:
node_id: the node label
structure_estimator: a structure estimator object with the information about the net
max_parents: maximum number of parents for each variable. If None, disabled max_parents: maximum number of parents for each variable. If None, disabled
iterations_number: maximum number of optimization algorithm's iteration iterations_number: maximum number of optimization algorithm's iteration
patience: number of iteration without any improvement before to stop the search.If None, disabled patience: number of iteration without any improvement before to stop the search.If None, disabled

@ -1,4 +1,4 @@
Time,Constraint,Variables,Density_Network,Cardinality,Index,F1,Precision,Recall Time,Type,Variables,Density_Network,Cardinality,Index,F1,Precision,Recall
89.185,1,15,0.1,3,0,0.88,0.786,1.0 89.185,1,15,0.1,3,0,0.88,0.786,1.0
96.358,1,15,0.1,3,1,0.939,0.885,1.0 96.358,1,15,0.1,3,1,0.939,0.885,1.0
83.178,1,15,0.1,3,2,0.954,0.913,1.0 83.178,1,15,0.1,3,2,0.954,0.913,1.0
@ -1151,3 +1151,199 @@ Time,Constraint,Variables,Density_Network,Cardinality,Index,F1,Precision,Recall
112.711,0,15,0.4,4,0,0.311,1.0,0.184 112.711,0,15,0.4,4,0,0.311,1.0,0.184
119.185,0,15,0.4,4,1,0.46,1.0,0.299 119.185,0,15,0.4,4,1,0.46,1.0,0.299
119.897,0,15,0.4,4,2,0.383,1.0,0.237 119.897,0,15,0.4,4,2,0.383,1.0,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ardinality Index F1 Precision Recall
2 89.185 1 15 0.1 3 0 0.88 0.786 1.0
3 96.358 1 15 0.1 3 1 0.939 0.885 1.0
4 83.178 1 15 0.1 3 2 0.954 0.913 1.0
1151 112.711 0 15 0.4 4 0 0.311 1.0 0.184
1152 119.185 0 15 0.4 4 1 0.46 1.0 0.299
1153 119.897 0 15 0.4 4 2 0.383 1.0 0.237
1154 2 2 3 0.1 2 0 1.0 1.0 1.0
1155 2 2 3 0.1 2 1 1.0 1.0 1.0
1156 2 2 3 0.1 2 2 1.0 1.0 1.0
1157 2 2 3 0.1 2 3 1.0 1.0 1.0
1158 2 2 3 0.1 2 4 1.0 1.0 1.0
1159 2 2 3 0.1 2 5 1.0 1.0 1.0
1160 2 2 3 0.1 2 6 1.0 1.0 1.0
1161 2 2 3 0.1 2 7 1.0 1.0 1.0
1162 2 2 3 0.1 2 8 1.0 1.0 1.0
1163 2 2 3 0.1 2 9 1.0 1.0 1.0
1164 2 2 4 0.1 2 0 1.0 1.0 1.0
1165 2 2 4 0.1 2 1 1.0 1.0 1.0
1166 2 2 4 0.1 2 2 1.0 1.0 1.0
1167 2 2 4 0.1 2 3 1.0 1.0 1.0
1168 2 2 4 0.1 2 4 1.0 1.0 1.0
1169 2 2 4 0.1 2 5 1.0 1.0 1.0
1170 2 2 4 0.1 2 6 1.0 1.0 1.0
1171 2 2 4 0.1 2 7 1.0 1.0 1.0
1172 2 2 4 0.1 2 8 1.0 1.0 1.0
1173 2 2 4 0.1 2 9 1.0 1.0 1.0
1174 2 2 5 0.1 2 0 1.0 1.0 1.0
1175 2 2 5 0.1 2 1 1.0 1.0 1.0
1176 2 2 5 0.1 2 2 1.0 1.0 1.0
1177 2 2 5 0.1 2 3 1.0 1.0 1.0
1178 2 2 5 0.1 2 4 1.0 1.0 1.0
1179 2 2 5 0.1 2 5 1.0 1.0 1.0
1180 2 2 5 0.1 2 6 1.0 1.0 1.0
1181 2 2 5 0.1 2 7 1.0 1.0 1.0
1182 2 2 5 0.1 2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1.0 1.0
1324 2 2 5 0.4 2 3 1.0 1.0 1.0
1325 2 2 5 0.4 2 4 1.0 1.0 1.0
1326 2 2 5 0.4 2 5 1.0 1.0 1.0
1327 2 2 5 0.4 2 6 1.0 1.0 1.0
1328 2 2 5 0.4 2 7 1.0 1.0 1.0
1329 2 2 5 0.4 2 8 1.0 1.0 1.0
1330 2 2 5 0.4 2 9 1.0 1.0 1.0
1331 2 2 6 0.4 2 0 1.0 1.0 1.0
1332 2 2 6 0.4 2 1 1.0 1.0 1.0
1333 2 2 6 0.4 2 2 1.0 1.0 1.0
1334 2 2 6 0.4 2 3 1.0 1.0 1.0
1335 2 2 6 0.4 2 4 1.0 1.0 1.0
1336 2 2 6 0.4 2 5 1.0 1.0 1.0
1337 2 2 6 0.4 2 6 1.0 1.0 1.0
1338 2 2 6 0.4 2 7 1.0 1.0 1.0
1339 2 2 6 0.4 2 8 1.0 1.0 1.0
1340 2 2 6 0.4 2 9 1.0 1.0 1.0
1341 2 2 10 0.4 2 0 1.0 1.0 1.0
1342 2 2 10 0.4 2 1 1.0 1.0 1.0
1343 2 2 10 0.4 2 2 1.0 1.0 1.0
1344 2 2 15 0.4 2 0 1.0 1.0 1.0
1345 2 2 15 0.4 2 1 1.0 1.0 1.0
1346 2 2 15 0.4 2 2 1.0 1.0 1.0
1347 2 2 20 0.4 2 0 0.961 1.0 0.925
1348 2 2 20 0.4 2 1 0.87 1.0 0.769
1349 2 2 20 0.4 2 2 0.963 1.0 0.929

@ -0,0 +1,20 @@
6.255,0,3,0.2,2,0,1.0,1.0,1.0
7.305,0,4,0.2,2,0,1.0,1.0,1.0
13.017,0,5,0.2,2,0,1.0,1.0,1.0
18.742,0,6,0.2,2,0,1.0,1.0,1.0
47.785,0,10,0.2,2,0,1.0,1.0,1.0
161.731,0,15,0.2,2,0,1.0,1.0,1.0
284.029,0,20,0.2,2,0,0.989,0.978,1.0
7.5,0,3,0.2,3,0,1.0,1.0,1.0
11.541,0,4,0.2,3,0,1.0,1.0,1.0
19.318,0,5,0.2,3,0,1.0,1.0,1.0
29.8,0,6,0.2,3,0,1.0,1.0,1.0
106.663,0,10,0.2,3,0,1.0,1.0,1.0
265.436,0,15,0.2,3,0,0.876,1.0,0.78
511.009,0,20,0.2,3,0,0.95,1.0,0.905
9.866,0,3,0.2,4,0,1.0,1.0,1.0
16.127,0,4,0.2,4,0,1.0,1.0,1.0
25.694,0,5,0.2,4,0,1.0,1.0,1.0
44.268,0,6,0.2,4,0,1.0,1.0,1.0
146.875,0,10,0.2,4,0,1.0,1.0,1.0
403.063,0,15,0.2,4,0,0.935,1.0,0.878
1 6.255 0 3 0.2 2 0 1.0 1.0 1.0
2 7.305 0 4 0.2 2 0 1.0 1.0 1.0
3 13.017 0 5 0.2 2 0 1.0 1.0 1.0
4 18.742 0 6 0.2 2 0 1.0 1.0 1.0
5 47.785 0 10 0.2 2 0 1.0 1.0 1.0
6 161.731 0 15 0.2 2 0 1.0 1.0 1.0
7 284.029 0 20 0.2 2 0 0.989 0.978 1.0
8 7.5 0 3 0.2 3 0 1.0 1.0 1.0
9 11.541 0 4 0.2 3 0 1.0 1.0 1.0
10 19.318 0 5 0.2 3 0 1.0 1.0 1.0
11 29.8 0 6 0.2 3 0 1.0 1.0 1.0
12 106.663 0 10 0.2 3 0 1.0 1.0 1.0
13 265.436 0 15 0.2 3 0 0.876 1.0 0.78
14 511.009 0 20 0.2 3 0 0.95 1.0 0.905
15 9.866 0 3 0.2 4 0 1.0 1.0 1.0
16 16.127 0 4 0.2 4 0 1.0 1.0 1.0
17 25.694 0 5 0.2 4 0 1.0 1.0 1.0
18 44.268 0 6 0.2 4 0 1.0 1.0 1.0
19 146.875 0 10 0.2 4 0 1.0 1.0 1.0
20 403.063 0 15 0.2 4 0 0.935 1.0 0.878

File diff suppressed because it is too large Load Diff

@ -0,0 +1,84 @@
import sys
sys.path.append("../../classes/")
import glob
import math
import os
import unittest
import networkx as nx
import numpy as np
import psutil
from line_profiler import LineProfiler
import copy
import utility.cache as ch
import structure_graph.sample_path as sp
import estimators.structure_score_based_estimator as se
import estimators.structure_constraint_based_estimator as se_
import utility.json_importer as ji
class TestHybridMethod(unittest.TestCase):
@classmethod
def setUpClass(cls):
#cls.read_files = glob.glob(os.path.join('../../data', "*.json"))
cls.importer = ji.JsonImporter("../../data/networks_and_trajectories_binary_data_04_3.json", 'samples', 'dyn.str', 'variables', 'Time', 'Name')
cls.s1 = sp.SamplePath(cls.importer)
cls.s1.build_trajectories()
cls.s1.build_structure()
def test_structure(self):
true_edges = copy.deepcopy(self.s1.structure.edges)
true_edges = set(map(tuple, true_edges))
s2= copy.deepcopy(self.s1)
se1 = se.StructureScoreBasedEstimator(self.s1,1,1)
edges_score = se1.estimate_structure(
max_parents = None,
iterations_number = 100,
patience = 50,
tabu_length = 20,
tabu_rules_duration = 20,
optimizer = 'tabu'
)
se2 = se_.StructureConstraintBasedEstimator(s2, 0.1, 0.1)
edges_constraint = se2.estimate_structure()
set_list_edges = set.union(edges_constraint,edges_score)
n_added_fake_edges = len(set_list_edges.difference(true_edges))
n_missing_edges = len(true_edges.difference(set_list_edges))
n_true_positive = len(true_edges) - n_missing_edges
precision = n_true_positive / (n_true_positive + n_added_fake_edges)
recall = n_true_positive / (n_true_positive + n_missing_edges)
f1_measure = round(2* (precision*recall) / (precision+recall),3)
# print(f"n archi reali non trovati: {n_missing_edges}")
# print(f"n archi non reali aggiunti: {n_added_fake_edges}")
print(true_edges)
print(set_list_edges)
print(f"precision: {precision} ")
print(f"recall: {recall} ")
print(f"F1: {f1_measure} ")
self.assertEqual(set_list_edges, true_edges)
if __name__ == '__main__':
unittest.main()

@ -0,0 +1,134 @@
import sys
sys.path.append("../../classes/")
import glob
import math
import os
import unittest
import networkx as nx
import numpy as np
import psutil
from line_profiler import LineProfiler
import copy
import utility.cache as ch
import structure_graph.sample_path as sp
import estimators.structure_score_based_estimator as se
import estimators.structure_constraint_based_estimator as se_
import utility.json_importer as ji
class TestTabuSearch(unittest.TestCase):
@classmethod
def setUpClass(cls):
pass
def test_constr(self):
list_vals= [3,4,5,6,10,15,20]
list_card=[[3,"ternary"],[4,"quaternary"]]
list_dens = [["0.1","_01"],["0.2","_02"], ["0.3",""], ["0.4","_04"] ]
for card in list_card:
for dens in list_dens:
list_vals= [3,4,5,6,10,15,20]
if card[0]==4:
list_vals.remove(20)
for var_n in list_vals:
patience = 20
var_number= var_n
if var_number > 11:
patience = 25
if var_number > 16:
patience = 35
cardinality = card[0]
cardinality_string = card[1]
density= dens[0]
density_string = dens[1]
constraint = 2
index = 0
num_networks=10
if var_number > 9:
num_networks=3
while index < num_networks:
#cls.read_files = glob.glob(os.path.join('../../data', "*.json"))
self.importer = ji.JsonImporter(f"../../data/networks_and_trajectories_{cardinality_string}_data{density_string}_{var_number}.json",
'samples', 'dyn.str', 'variables', 'Time', 'Name', index )
self.s1 = sp.SamplePath(self.importer)
self.s1.build_trajectories()
self.s1.build_structure()
true_edges = copy.deepcopy(self.s1.structure.edges)
true_edges = set(map(tuple, true_edges))
s2= copy.deepcopy(self.s1)
se1 = se.StructureScoreBasedEstimator(self.s1,1,1)
edges_score = se1.estimate_structure(
max_parents = None,
iterations_number = 100,
patience = patience,
tabu_length = var_number,
tabu_rules_duration = var_number,
optimizer = 'tabu'
)
se2 = se_.StructureConstraintBasedEstimator(s2, 0.1, 0.1)
edges_constraint = se2.estimate_structure()
set_list_edges = set.union(edges_constraint,edges_score)
n_added_fake_edges = len(set_list_edges.difference(true_edges))
n_missing_edges = len(true_edges.difference(set_list_edges))
n_true_positive = len(true_edges) - n_missing_edges
precision = n_true_positive / (n_true_positive + n_added_fake_edges)
recall = n_true_positive / (n_true_positive + n_missing_edges)
f1_measure = round(2* (precision*recall) / (precision+recall),3)
# print(f"n archi reali non trovati: {n_missing_edges}")
# print(f"n archi non reali aggiunti: {n_added_fake_edges}")
print(true_edges)
print(set_list_edges)
print(f"precision: {precision} ")
print(f"recall: {recall} ")
with open("../results/results.csv", 'a+') as fi:
fi.write(f"\n2,{constraint},{var_number},{density},{cardinality},{index},{f1_measure},{round(precision,3)},{round(recall,3)}")
index += 1
self.assertEqual(set_list_edges, true_edges)
if __name__ == '__main__':
unittest.main()

@ -61,6 +61,7 @@ class TestTabuSearch(unittest.TestCase):
if var_number > 9: if var_number > 9:
num_networks=3 num_networks=3
while index < num_networks: while index < num_networks:
#cls.read_files = glob.glob(os.path.join('../../data', "*.json")) #cls.read_files = glob.glob(os.path.join('../../data', "*.json"))
self.importer = ji.JsonImporter(f"../../data/networks_and_trajectories_{cardinality_string}_data{density_string}_{var_number}.json", self.importer = ji.JsonImporter(f"../../data/networks_and_trajectories_{cardinality_string}_data{density_string}_{var_number}.json",
@ -80,7 +81,7 @@ class TestTabuSearch(unittest.TestCase):
patience = patience, patience = patience,
tabu_length = var_number, tabu_length = var_number,
tabu_rules_duration = var_number, tabu_rules_duration = var_number,
optimizer = 'tabu' optimizer = 'hill'
) )