Parcourir la source

Merge branch 'release/v0.4.0'

Jérôme BUISINE il y a 3 ans
Parent
commit
c945da58a7
2 fichiers modifiés avec 21 ajouts et 4 suppressions
  1. 18 3
      find_best_attributes_surrogate.py
  2. 3 1
      optimization/ILSPopSurrogate.py

+ 18 - 3
find_best_attributes_surrogate.py

@@ -259,9 +259,24 @@ def main():
                 filters_counter += 1
 
 
-    line_info = p_data_file + ';' + str(p_ils_iteration) + ';' + str(p_ls_iteration) + ';' + str(bestSol.data) + ';' + str(list(bestSol.data).count(1)) + ';' + str(filters_counter) + ';' + str(bestSol.fitness)
-    with open(filename_path, 'a') as f:
-        f.write(line_info + '\n')
+    line_info = p_output + ';' + p_data_file + ';' + str(bestSol.data) + ';' + str(list(bestSol.data).count(1)) + ';' + str(filters_counter) + ';' + str(bestSol.fitness)
+
+    # check if results are already saved...
+    already_saved = False
+
+    if os.path.exists(filename_path):
+        with open(filename_path, 'r') as f:
+            lines = f.readlines()
+
+            for line in lines:
+                output_name = line.split(';')[0]
+                
+                if p_output == output_name:
+                    already_saved = True
+
+    if not already_saved:
+        with open(filename_path, 'a') as f:
+            f.write(line_info + '\n')
     
     print('Result saved into %s' % filename_path)
 

+ 3 - 1
optimization/ILSPopSurrogate.py

@@ -322,11 +322,13 @@ class ILSPopSurrogate(Algorithm):
                 training_surrogate_every = int(r_squared * self._ls_train_surrogate)
                 print(f"=> R² of surrogate is of {r_squared}.")
                 print(f"=> MAE of surrogate is of {mae}.")
-                print(f'=> Retraining model every {training_surrogate_every} LS ({self._ls_local_search % training_surrogate_every} of {training_surrogate_every})')
+                
                 # avoid issue when lauching every each local search
                 if training_surrogate_every <= 0:
                     training_surrogate_every = 1
 
+                print(f'=> Retraining model every {training_surrogate_every} LS ({self._ls_local_search % training_surrogate_every} of {training_surrogate_every})')
+
 
                 # increase number of local search done
                 self._n_local_search += 1