diff --git a/main_package/classes/estimators/fam_score_calculator.py b/main_package/classes/estimators/fam_score_calculator.py index d8333ec..e256563 100644 --- a/main_package/classes/estimators/fam_score_calculator.py +++ b/main_package/classes/estimators/fam_score_calculator.py @@ -21,7 +21,7 @@ import structure_graph.conditional_intensity_matrix as cim_class ''' -TODO: Parlare dell'idea di ciclare sulle cim senza filtrare + ''' @@ -110,7 +110,7 @@ class FamScoreCalculator: + \ np.sum([self.single_internal_cim_xxu_marginal_likelihood_theta( cim.state_transition_matrix[index,index_x_first], - alpha_xu * cim.state_transition_matrix[index,index_x_first] / cim.state_transition_matrix[index, index]) + alpha_xxu) for index_x_first in values]) diff --git a/main_package/classes/structure_graph/sample_path.py b/main_package/classes/structure_graph/sample_path.py index 018a6d0..c2d470b 100644 --- a/main_package/classes/structure_graph/sample_path.py +++ b/main_package/classes/structure_graph/sample_path.py @@ -6,6 +6,8 @@ import utility.json_importer as imp import structure_graph.structure as st import structure_graph.trajectory as tr +import pandas as pd + class SamplePath(asam.AbstractSamplePath): @@ -41,8 +43,13 @@ class SamplePath(asam.AbstractSamplePath): void """ self.importer.import_data() + + #TODO: VALUTARE PARAMETRO PER DATA AUGMENTATION + trajects_samples = pd.concat([self.importer.concatenated_samples, + self.importer.concatenated_samples]) + self._trajectories = \ - tr.Trajectory(self.importer.build_list_of_samples_array(self.importer.concatenated_samples), + tr.Trajectory(self.importer.build_list_of_samples_array(trajects_samples), len(self.importer.sorter) + 1) #self.trajectories.append(trajectory) self.importer.clear_concatenated_frame() diff --git a/main_package/tests/optimizers/test_tabu_search.py b/main_package/tests/optimizers/test_tabu_search.py index f221300..72c09a6 100644 --- a/main_package/tests/optimizers/test_tabu_search.py +++ b/main_package/tests/optimizers/test_tabu_search.py @@ -23,8 +23,8 @@ class TestTabuSearch(unittest.TestCase): @classmethod def setUpClass(cls): #cls.read_files = glob.glob(os.path.join('../../data', "*.json")) - cls.importer = ji.JsonImporter("../../data/networks_and_trajectories_ternary_data_15.json", - 'samples', 'dyn.str', 'variables', 'Time', 'Name', 0 ) + cls.importer = ji.JsonImporter("../../data/networks_and_trajectories_ternary_data_20.json", + 'samples', 'dyn.str', 'variables', 'Time', 'Name', 2 ) cls.s1 = sp.SamplePath(cls.importer) cls.s1.build_trajectories() cls.s1.build_structure() @@ -40,8 +40,8 @@ class TestTabuSearch(unittest.TestCase): max_parents = None, iterations_number = 100, patience = None, - tabu_length = 20, - tabu_rules_duration = 20, + tabu_length = 15, + tabu_rules_duration = 15, optimizer = 'tabu' ) diff --git a/main_package/tests/results/results.csv b/main_package/tests/results/results.csv index 5ed166d..4a83269 100644 --- a/main_package/tests/results/results.csv +++ b/main_package/tests/results/results.csv @@ -1346,4 +1346,384 @@ Time,Type,Variables,Density_Network,Cardinality,Index,F1,Precision,Recall 2,2,15,0.4,2,2,1.0,1.0,1.0 2,2,20,0.4,2,0,0.961,1.0,0.925 2,2,20,0.4,2,1,0.87,1.0,0.769 -2,2,20,0.4,2,2,0.963,1.0,0.929 \ No newline at end of file +2,2,20,0.4,2,2,0.963,1.0,0.929 +2,2,3,0.1,3,0,1.0,1.0,1.0 +2,2,3,0.1,3,1,1.0,1.0,1.0 +2,2,3,0.1,3,2,1.0,1.0,1.0 +2,2,3,0.1,3,3,0.8,0.667,1.0 +2,2,3,0.1,3,4,1.0,1.0,1.0 +2,2,3,0.1,3,5,1.0,1.0,1.0 +2,2,3,0.1,3,6,0.667,0.5,1.0 +2,2,3,0.1,3,7,0.8,0.667,1.0 +2,2,3,0.1,3,8,0.8,0.667,1.0 +2,2,3,0.1,3,9,1.0,1.0,1.0 +2,2,4,0.1,3,0,0.857,0.75,1.0 +2,2,4,0.1,3,1,0.667,0.5,1.0 +2,2,4,0.1,3,2,0.857,0.75,1.0 +2,2,4,0.1,3,3,1.0,1.0,1.0 +2,2,4,0.1,3,4,1.0,1.0,1.0 +2,2,4,0.1,3,5,0.75,0.6,1.0 +2,2,4,0.1,3,6,1.0,1.0,1.0 +2,2,4,0.1,3,7,1.0,1.0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,0.941,0.889,1.0 +2,2,5,0.4,3,3,0.923,0.857,1.0 +2,2,5,0.4,3,4,0.923,0.857,1.0 +2,2,5,0.4,3,5,0.941,0.889,1.0 +2,2,5,0.4,3,6,0.889,0.8,1.0 +2,2,5,0.4,3,7,1.0,1.0,1.0 +2,2,5,0.4,3,8,1.0,1.0,1.0 +2,2,5,0.4,3,9,0.952,0.909,1.0 +2,2,6,0.4,3,0,1.0,1.0,1.0 +2,2,6,0.4,3,1,0.929,0.867,1.0 +2,2,6,0.4,3,2,0.966,0.933,1.0 +2,2,6,0.4,3,3,0.857,0.75,1.0 +2,2,6,0.4,3,4,0.968,0.938,1.0 +2,2,6,0.4,3,5,1.0,1.0,1.0 +2,2,6,0.4,3,6,0.947,0.9,1.0 +2,2,6,0.4,3,7,0.963,0.929,1.0 +2,2,6,0.4,3,8,0.966,0.933,1.0 +2,2,6,0.4,3,9,0.947,0.9,1.0 +2,2,10,0.4,3,0,1.0,1.0,1.0 +2,2,10,0.4,3,1,0.932,0.971,0.895 +2,2,10,0.4,3,2,1.0,1.0,1.0 +2,2,15,0.4,3,0,0.863,0.985,0.767 +2,2,15,0.4,3,1,0.78,0.982,0.647 +2,2,15,0.4,3,2,0.958,1.0,0.92 +2,2,20,0.4,3,0,0.5,0.98,0.336 +2,2,20,0.4,3,1,0.635,1.0,0.465 +2,2,20,0.4,3,2,0.436,0.936,0.284 +2,2,3,0.1,4,0,1.0,1.0,1.0 +2,2,3,0.1,4,1,0.667,0.5,1.0 +2,2,3,0.1,4,2,0.8,0.667,1.0 +2,2,3,0.1,4,3,0.8,0.667,1.0 +2,2,3,0.1,4,4,0.8,0.667,1.0 +2,2,3,0.1,4,5,1.0,1.0,1.0 +2,2,3,0.1,4,6,0.8,0.667,1.0 +2,2,3,0.1,4,7,1.0,1.0,1.0 +2,2,3,0.1,4,8,0.75,0.6,1.0 +2,2,3,0.1,4,9,0.667,0.5,1.0 +2,2,4,0.1,4,0,0.889,0.8,1.0 +2,2,4,0.1,4,1,0.571,0.4,1.0 +2,2,4,0.1,4,2,1.0,1.0,1.0 +2,2,4,0.1,4,3,0.667,0.5,1.0 +2,2,4,0.1,4,4,0.667,0.5,1.0 +2,2,4,0.1,4,5,0.571,0.4,1.0 +2,2,4,0.1,4,6,0.889,0.8,1.0 +2,2,4,0.1,4,7,0.571,0.4,1.0 +2,2,4,0.1,4,8,0.8,0.667,1.0 +2,2,4,0.1,4,9,0.833,0.714,1.0 +2,2,5,0.1,4,0,0.857,0.75,1.0 +2,2,5,0.1,4,1,0.778,0.636,1.0 +2,2,5,0.1,4,2,0.727,0.571,1.0 +2,2,5,0.1,4,3,0.727,0.571,1.0 +2,2,5,0.1,4,4,0.8,0.667,1.0 +2,2,5,0.1,4,5,0.75,0.6,1.0 +2,2,5,0.1,4,6,0.667,0.5,1.0 +2,2,5,0.1,4,7,0.8,0.667,1.0 +2,2,5,0.1,4,8,0.889,0.8,1.0 +2,2,5,0.1,4,9,0.857,0.75,1.0 +2,2,6,0.1,4,0,0.8,0.667,1.0 +2,2,6,0.1,4,1,0.667,0.5,1.0 +2,2,6,0.1,4,2,0.727,0.571,1.0 +2,2,6,0.1,4,3,0.615,0.444,1.0 +2,2,6,0.1,4,4,0.8,0.667,1.0 +2,2,6,0.1,4,5,0.8,0.667,1.0 +2,2,6,0.1,4,6,0.714,0.556,1.0 +2,2,6,0.1,4,7,0.824,0.7,1.0 +2,2,6,0.1,4,8,0.909,0.833,1.0 +2,2,6,0.1,4,9,0.75,0.6,1.0 +2,2,10,0.1,4,0,0.688,0.524,1.0 +2,2,10,0.1,4,1,0.821,0.696,1.0 +2,2,10,0.1,4,2,0.774,0.632,1.0 +2,2,15,0.1,4,0,0.833,0.714,1.0 +2,2,15,0.1,4,1,0.717,0.559,1.0 +2,2,15,0.1,4,2,0.787,0.649,1.0 +2,2,3,0.2,4,0,0.857,0.75,1.0 +2,2,3,0.2,4,1,1.0,1.0,1.0 +2,2,3,0.2,4,2,0.8,0.667,1.0 +2,2,3,0.2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.2,4,1,0.898,0.815,1.0 +2,2,10,0.2,4,2,0.833,0.714,1.0 +2,2,15,0.2,4,0,0.932,0.872,1.0 +2,2,15,0.2,4,1,0.921,0.891,0.953 +2,2,15,0.2,4,2,0.932,0.873,1.0 +2,2,3,0.3,4,0,0.8,0.667,1.0 +2,2,3,0.3,4,1,0.667,0.5,1.0 +2,2,3,0.3,4,2,1.0,1.0,1.0 +2,2,3,0.3,4,3,1.0,1.0,1.0 +2,2,3,0.3,4,4,1.0,1.0,1.0 +2,2,3,0.3,4,5,0.8,0.667,1.0 +2,2,3,0.3,4,6,0.667,0.5,1.0 +2,2,3,0.3,4,7,1.0,1.0,1.0 +2,2,3,0.3,4,8,0.857,0.75,1.0 +2,2,3,0.3,4,9,0.8,0.667,1.0 +2,2,4,0.3,4,0,0.889,0.8,1.0 +2,2,4,0.3,4,1,0.833,0.714,1.0 +2,2,4,0.3,4,2,0.923,0.857,1.0 +2,2,4,0.3,4,3,0.8,0.667,1.0 +2,2,4,0.3,4,4,0.909,0.833,1.0 +2,2,4,0.3,4,5,0.8,0.667,1.0 +2,2,4,0.3,4,6,0.833,0.714,1.0 +2,2,4,0.3,4,7,0.889,0.8,1.0 +2,2,4,0.3,4,8,0.889,0.8,1.0 +2,2,4,0.3,4,9,0.933,0.875,1.0 +2,2,5,0.3,4,0,0.923,0.857,1.0 +2,2,5,0.3,4,1,0.737,0.583,1.0 +2,2,5,0.3,4,2,0.917,0.846,1.0 +2,2,5,0.3,4,3,0.933,0.875,1.0 +2,2,5,0.3,4,4,0.9,0.818,1.0 +2,2,5,0.3,4,5,0.923,0.857,1.0 +2,2,5,0.3,4,6,0.8,0.667,1.0 +2,2,5,0.3,4,7,0.833,0.714,1.0 +2,2,5,0.3,4,8,0.769,0.625,1.0 +2,2,5,0.3,4,9,0.889,0.8,1.0 +2,2,6,0.3,4,0,0.833,0.714,1.0 +2,2,6,0.3,4,1,0.87,0.769,1.0 +2,2,6,0.3,4,2,0.88,0.786,1.0 +2,2,6,0.3,4,3,0.917,0.846,1.0 +2,2,6,0.3,4,4,0.737,0.583,1.0 +2,2,6,0.3,4,5,0.897,0.812,1.0 +2,2,6,0.3,4,6,0.714,0.556,1.0 +2,2,6,0.3,4,7,0.947,0.9,1.0 +2,2,6,0.3,4,8,0.889,0.8,1.0 +2,2,6,0.3,4,9,0.818,0.692,1.0 +2,2,10,0.3,4,0,0.943,0.893,1.0 +2,2,10,0.3,4,1,0.848,0.8,0.903 +2,2,10,0.3,4,2,0.852,0.742,1.0 +2,2,15,0.3,4,0,0.8,0.667,1.0 +2,2,15,0.3,4,1,0.708,0.548,1.0 +2,2,15,0.3,4,2,0.833,0.714,1.0 +2,2,3,0.4,4,0,0.889,0.8,1.0 +2,2,3,0.4,4,1,0.857,0.75,1.0 +2,2,3,0.4,4,2,0.75,0.6,1.0 +2,2,3,0.4,4,3,0.857,0.75,1.0 +2,2,3,0.4,4,4,0.857,0.75,1.0 +2,2,3,0.4,4,5,1.0,1.0,1.0 +2,2,3,0.4,4,6,0.8,0.667,1.0 +2,2,3,0.4,4,7,0.8,0.667,1.0 +2,2,3,0.4,4,8,0.889,0.8,1.0 +2,2,3,0.4,4,9,1.0,1.0,1.0 +2,2,4,0.4,4,0,0.923,0.857,1.0 +2,2,4,0.4,4,1,0.933,0.875,1.0 +2,2,4,0.4,4,2,1.0,1.0,1.0 +2,2,4,0.4,4,3,0.75,0.6,1.0 +2,2,4,0.4,4,4,1.0,1.0,1.0 +2,2,4,0.4,4,5,0.857,0.75,1.0 +2,2,4,0.4,4,6,0.889,0.8,1.0 +2,2,4,0.4,4,7,0.889,0.8,1.0 +2,2,4,0.4,4,8,0.667,0.5,1.0 +2,2,4,0.4,4,9,0.833,0.714,1.0 +2,2,5,0.4,4,0,0.778,0.636,1.0 +2,2,5,0.4,4,1,0.842,0.727,1.0 +2,2,5,0.4,4,2,0.909,0.833,1.0 +2,2,5,0.4,4,3,0.857,0.75,1.0 +2,2,5,0.4,4,4,0.966,0.933,1.0 +2,2,5,0.4,4,5,0.778,0.636,1.0 +2,2,5,0.4,4,6,0.8,0.667,1.0 +2,2,5,0.4,4,7,0.714,0.556,1.0 +2,2,5,0.4,4,8,0.8,0.667,1.0 +2,2,5,0.4,4,9,0.737,0.583,1.0 +2,2,6,0.4,4,0,0.815,0.688,1.0 +2,2,6,0.4,4,1,0.889,0.8,1.0 +2,2,6,0.4,4,2,0.929,0.867,1.0 +2,2,6,0.4,4,3,0.875,0.778,1.0 +2,2,6,0.4,4,4,0.706,0.545,1.0 +2,2,6,0.4,4,5,0.88,0.786,1.0 +2,2,6,0.4,4,6,0.889,0.8,1.0 +2,2,6,0.4,4,7,0.815,0.688,1.0 +2,2,6,0.4,4,8,0.938,0.882,1.0 +2,2,6,0.4,4,9,0.857,0.75,1.0 +2,2,10,0.4,4,0,0.972,0.946,1.0 +2,2,10,0.4,4,1,0.927,0.95,0.905 +2,2,10,0.4,4,2,0.892,0.967,0.829 +2,2,15,0.4,4,0,0.691,0.923,0.552 +2,2,15,0.4,4,1,0.815,0.948,0.714 +2,2,15,0.4,4,2,0.794,0.945,0.684 \ No newline at end of file diff --git a/main_package/tests/simulators/test_ensambled_model.py b/main_package/tests/simulators/test_ensambled_model.py deleted file mode 100644 index 0375a87..0000000 --- a/main_package/tests/simulators/test_ensambled_model.py +++ /dev/null @@ -1,84 +0,0 @@ -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() - diff --git a/main_package/tests/simulators/test_ensambled_model_all.py b/main_package/tests/simulators/test_ensambled_model_all.py deleted file mode 100644 index fb839fb..0000000 --- a/main_package/tests/simulators/test_ensambled_model_all.py +++ /dev/null @@ -1,134 +0,0 @@ -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() -