1
0
Fork 0

Updated mono process version of both the algorithms

master
Luca Moretti 4 years ago
parent d0593726d2
commit 9251de0fb6
  1. 13
      main_package/classes/estimators/structure_constraint_based_estimator.py
  2. 9
      main_package/classes/estimators/structure_score_based_estimator.py
  3. 2
      main_package/tests/estimators/test_structure_score_based_estimator.py

@ -236,9 +236,7 @@ class StructureConstraintBasedEstimator(se.StructureEstimator):
'get the number of CPU' 'get the number of CPU'
cpu_count = multiprocessing.cpu_count() cpu_count = multiprocessing.cpu_count()
if disable_multiprocessing:
print("DISABILITATO")
cpu_count = 1
'Remove all the edges from the structure' 'Remove all the edges from the structure'
self.sample_path.structure.clean_structure_edges() self.sample_path.structure.clean_structure_edges()
@ -246,8 +244,13 @@ class StructureConstraintBasedEstimator(se.StructureEstimator):
'Estimate the best parents for each node' 'Estimate the best parents for each node'
#with multiprocessing.Pool(processes=cpu_count) as pool: #with multiprocessing.Pool(processes=cpu_count) as pool:
#with get_context("spawn").Pool(processes=cpu_count) as pool: #with get_context("spawn").Pool(processes=cpu_count) as pool:
with concurrent.futures.ProcessPoolExecutor(max_workers=cpu_count) as executor: if disable_multiprocessing:
list_edges_partial = executor.map(ctpc_algo, print("DISABILITATO")
cpu_count = 1
list_edges_partial = [ctpc_algo(n,total_vars_numb) for n in self.nodes]
else:
with concurrent.futures.ProcessPoolExecutor(max_workers=cpu_count) as executor:
list_edges_partial = executor.map(ctpc_algo,
self.nodes, self.nodes,
total_vars_numb_array) total_vars_numb_array)
#list_edges_partial = [ctpc_algo(n,total_vars_numb) for n in self.nodes] #list_edges_partial = [ctpc_algo(n,total_vars_numb) for n in self.nodes]

@ -102,8 +102,11 @@ class StructureScoreBasedEstimator(se.StructureEstimator):
#with multiprocessing.Pool(processes=cpu_count) as pool: #with multiprocessing.Pool(processes=cpu_count) as pool:
'Estimate the best parents for each node' 'Estimate the best parents for each node'
with concurrent.futures.ProcessPoolExecutor(max_workers=cpu_count) as executor: if disable_multiprocessing:
list_edges_partial = executor.map(estimate_parents, list_edges_partial = [estimate_parents(n,max_parents,iterations_number,patience,tabu_length,tabu_rules_duration,optimizer) for n in self.nodes]
else:
with concurrent.futures.ProcessPoolExecutor(max_workers=cpu_count) as executor:
list_edges_partial = executor.map(estimate_parents,
self.nodes, self.nodes,
l_max_parents, l_max_parents,
l_iterations_number, l_iterations_number,
@ -114,8 +117,6 @@ class StructureScoreBasedEstimator(se.StructureEstimator):
# list_edges_partial = [estimate_parents(n,max_parents,iterations_number,patience,tabu_length,tabu_rules_duration,optimizer) for n in self.nodes]
#list_edges_partial = p.map(estimate_parents, self.nodes) #list_edges_partial = p.map(estimate_parents, self.nodes)
#list_edges_partial= estimate_parents('Q',max_parents,iterations_number,patience,tabu_length,tabu_rules_duration,optimizer) #list_edges_partial= estimate_parents('Q',max_parents,iterations_number,patience,tabu_length,tabu_rules_duration,optimizer)

@ -23,7 +23,7 @@ class TestStructureScoreBasedEstimator(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
#cls.read_files = glob.glob(os.path.join('../../data', "*.json")) #cls.read_files = glob.glob(os.path.join('../../data', "*.json"))
cls.importer = ji.JsonImporter("../../data/networks_and_trajectories_binary_data_10.json", 'samples', 'dyn.str', 'variables', 'Time', 'Name') cls.importer = ji.JsonImporter("../../data/networks_and_trajectories_binary_data_15.json", 'samples', 'dyn.str', 'variables', 'Time', 'Name')
cls.s1 = sp.SamplePath(cls.importer) cls.s1 = sp.SamplePath(cls.importer)
cls.s1.build_trajectories() cls.s1.build_trajectories()
cls.s1.build_structure() cls.s1.build_structure()