S1223 commited on
Commit
e8fae83
·
verified ·
1 Parent(s): bf218da

Update geneticAlgorithm.py

Browse files
Files changed (1) hide show
  1. geneticAlgorithm.py +41 -1
geneticAlgorithm.py CHANGED
@@ -47,7 +47,7 @@ def fitness_func(ga_instance, solution, solution_idx):
47
  modelName = ""
48
  for x in solution:
49
  modelName += f"{str(x)}_"
50
- IMC.training_model(epochs=50, modelName=modelName, optimizer=usedOptimizers, lossFunction=usedLossFunction)
51
  IMC.evaluation(labelName=["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"])
52
  output = float(IMC.history.history["val_accuracy"][-1])
53
  fitness = output
@@ -99,3 +99,43 @@ print(ga_instance.run())
99
  solution, solution_fitness, solution_idx = ga_instance.best_solution()
100
  print("Parameters of the best solution : {solution}".format(solution=solution))
101
  print("Fitness value of the best solution = {solution_fitness}".format(solution_fitness=solution_fitness))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  modelName = ""
48
  for x in solution:
49
  modelName += f"{str(x)}_"
50
+ IMC.training_model(epochs=3, modelName=modelName, optimizer=usedOptimizers, lossFunction=usedLossFunction)
51
  IMC.evaluation(labelName=["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"])
52
  output = float(IMC.history.history["val_accuracy"][-1])
53
  fitness = output
 
99
  solution, solution_fitness, solution_idx = ga_instance.best_solution()
100
  print("Parameters of the best solution : {solution}".format(solution=solution))
101
  print("Fitness value of the best solution = {solution_fitness}".format(solution_fitness=solution_fitness))
102
+
103
+ import subprocess
104
+ import sys
105
+
106
+ # Function to install required packages
107
+ def install(package):
108
+ subprocess.check_call([sys.executable, "-m", "pip", "install", package])
109
+
110
+ # List of required packages for the script
111
+ required_packages = ['os', 'shutil', 'zipfile']
112
+
113
+ # Check if the required packages are installed, if not, install them
114
+ for package in required_packages:
115
+ try:
116
+ __import__(package)
117
+ except ImportError:
118
+ install(package)
119
+
120
+ import os
121
+ import shutil
122
+ import zipfile
123
+
124
+ # Create a new directory to store the files
125
+ folder_name = 'data'
126
+ if not os.path.exists(folder_name):
127
+ os.makedirs(folder_name)
128
+
129
+ # Move all .xlsx and .png files to the new directory
130
+ for file in os.listdir('.'):
131
+ if file.endswith('.xlsx') or file.endswith('.png') or file.endswith('.out'):
132
+ shutil.move(file, os.path.join(folder_name, file))
133
+
134
+ # Zip the folder
135
+ zipf = zipfile.ZipFile('data.zip', 'w', zipfile.ZIP_DEFLATED)
136
+ for root, dirs, files in os.walk(folder_name):
137
+ for file in files:
138
+ zipf.write(os.path.join(root, file), arcname=file)
139
+ zipf.close()
140
+
141
+ print("All .xlsx and .png files have been moved and zipped into data.zip")