Pārlūkot izejas kodu

now use of macop Python package for optimization process

Jérôme BUISINE 4 gadi atpakaļ
vecāks
revīzija
c52c6fae6c
5 mainītis faili ar 31 papildinājumiem un 26 dzēšanām
  1. 0 3
      .gitmodules
  2. 14 10
      find_best_attributes.py
  3. 15 11
      find_best_filters.py
  4. 0 1
      optimization
  5. 2 1
      requirements.txt

+ 0 - 3
.gitmodules

@@ -1,6 +1,3 @@
 [submodule "modules"]
 	path = modules
 	url = https://github.com/prise-3d/Thesis-CommonModules.git
-[submodule "optimization"]
-	path = optimization
-	url = https://github.com/prise-3d/Thesis-OptimizationModules.git

+ 14 - 10
find_best_attributes.py

@@ -25,16 +25,18 @@ sys.path.insert(0, '') # trick to enable import of main folder module
 import custom_config as cfg
 import models as mdl
 
-from optimization.algorithms.IteratedLocalSearch import IteratedLocalSearch as ILS
-from optimization.solutions.BinarySolution import BinarySolution
+from macop.algorithms.IteratedLocalSearch import IteratedLocalSearch as ILS
+from macop.solutions.BinarySolution import BinarySolution
 
-from optimization.operators.mutators.SimpleMutation import SimpleMutation
-from optimization.operators.mutators.SimpleBinaryMutation import SimpleBinaryMutation
-from optimization.operators.crossovers.SimpleCrossover import SimpleCrossover
+from macop.operators.mutators.SimpleMutation import SimpleMutation
+from macop.operators.mutators.SimpleBinaryMutation import SimpleBinaryMutation
+from macop.operators.crossovers.SimpleCrossover import SimpleCrossover
+from macop.operators.crossovers.RandomSplitCrossover import RandomSplitCrossover
 
-from optimization.operators.policies.RandomPolicy import RandomPolicy
+from macop.operators.policies.UCBPolicy import UCBPolicy
 
-from optimization.checkpoints.BasicCheckpoint import BasicCheckpoint
+from macop.checkpoints.BasicCheckpoint import BasicCheckpoint
+from macop.checkpoints.UCBCheckpoint import UCBCheckpoint
 
 # variables and parameters
 models_list         = cfg.models_names_list
@@ -154,13 +156,15 @@ def main():
         os.makedirs(cfg.output_backup_folder)
 
     backup_file_path = os.path.join(cfg.output_backup_folder, p_data_file.split('/')[-1] + '.csv')
+    ucb_backup_file_path = os.path.join(cfg.backup_folder, p_data_file.split('/')[-1] + '_ucbPolicy.csv')
 
     # prepare optimization algorithm
-    updators = [SimpleBinaryMutation(), SimpleMutation(), SimpleCrossover()]
-    policy = RandomPolicy(updators)
+    operators = [SimpleBinaryMutation(), SimpleMutation(), SimpleCrossover(), RandomSplitCrossover()]
+    policy = UCBPolicy(updators)
 
     algo = ILS(init, evaluate, updators, policy, validator, True)
-    algo.addCheckpoint(_class=BasicCheckpoint, _every=1, _filepath=backup_file_path)
+    algo.addCallback(BasicCheckpoint(_every=1, _filepath=backup_file_path))
+    algo.addCallback(UCBCheckpoint(_every=1, _filepath=ucb_backup_file_path))
 
     bestSol = algo.run(ils_iteration, ls_iteration)
 

+ 15 - 11
find_best_filters.py

@@ -24,16 +24,18 @@ sys.path.insert(0, '') # trick to enable import of main folder module
 import custom_config as cfg
 import models as mdl
 
-from optimization.algorithms.IteratedLocalSearch import IteratedLocalSearch as ILS
-from optimization.solutions.BinarySolution import BinarySolution
+from macop.algorithms.IteratedLocalSearch import IteratedLocalSearch as ILS
+from macop.solutions.BinarySolution import BinarySolution
 
-from optimization.operators.mutators.SimpleMutation import SimpleMutation
-from optimization.operators.mutators.SimpleBinaryMutation import SimpleBinaryMutation
-from optimization.operators.crossovers.SimpleCrossover import SimpleCrossover
+from macop.operators.mutators.SimpleMutation import SimpleMutation
+from macop.operators.mutators.SimpleBinaryMutation import SimpleBinaryMutation
+from macop.operators.crossovers.SimpleCrossover import SimpleCrossover
+from macop.operators.crossovers.RandomSplitCrossover import RandomSplitCrossover
 
-from optimization.operators.policies.RandomPolicy import RandomPolicy
+from macop.operators.policies.UCBPolicy import UCBPolicy
 
-from optimization.checkpoints.BasicCheckpoint import BasicCheckpoint
+from macop.checkpoints.BasicCheckpoint import BasicCheckpoint
+from macop.checkpoints.UCBCheckpoint import UCBCheckpoint
 
 # variables and parameters
 models_list         = cfg.models_names_list
@@ -138,13 +140,15 @@ def main():
         os.makedirs(cfg.backup_folder)
 
     backup_file_path = os.path.join(cfg.backup_folder, p_data_file.split('/')[-1] + '.csv')
+    ucb_backup_file_path = os.path.join(cfg.backup_folder, p_data_file.split('/')[-1] + '_ucbPolicy.csv')
 
     # prepare optimization algorithm
-    updators = [SimpleBinaryMutation(), SimpleMutation(), SimpleCrossover()]
-    policy = RandomPolicy(updators)
+    operators = [SimpleBinaryMutation(), SimpleMutation(), SimpleCrossover(), RandomSplitCrossover()]
+    policy = UCBPolicy(operators)
 
-    algo = ILS(init, evaluate, updators, policy, validator, True)
-    algo.addCheckpoint(_class=BasicCheckpoint, _every=1, _filepath=backup_file_path)
+    algo = ILS(init, evaluate, operators, policy, validator, True)
+    algo.addCallback(BasicCheckpoint(_every=1, _filepath=backup_file_path))
+    algo.addCallback(UCBCheckpoint(_every=1, _filepath=ucb_backup_file_path))
 
     bestSol = algo.run(ils_iteration, ls_iteration)
 

+ 0 - 1
optimization

@@ -1 +0,0 @@
-Subproject commit db3538337fc6fcce7796378d50ade263b1c103fd

+ 2 - 1
requirements.txt

@@ -10,4 +10,5 @@ matplotlib
 path.py
 pandas
 opencv-python
-joblib
+joblib
+macop