Commit
•
0d0f645
1
Parent(s):
a13d33d
Updated the optimize method with removal of contour_plot functionality. Updated plot_contour_and_wolves method lines 344-346 with: best_positions_loaded_array = np.load('best_positions_array.npy') wolf_positions = best_positions_loaded_array. And modified the optimize function with: # Load best_positions_loaded_array best_positions_loaded_array = np.load('best_positions_array.npy') # Plot the contour_and_wolves plot_contour_and_wolves = gwo.plot_contour_and_wolves(best_positions_loaded_array) Removed the contour_plot from gwo.optimize also only the other two variables remain
Browse files
app.py
CHANGED
@@ -222,16 +222,16 @@ class GWO:
|
|
222 |
|
223 |
# Convert the list of best positions to a NumPy array
|
224 |
best_positions_array = np.array(best_positions)
|
|
|
225 |
|
226 |
-
|
227 |
-
contour_plot = self.plot_contour_and_wolves(best_positions_array)
|
228 |
|
229 |
# Print the best positions and fitness found
|
230 |
print("Best Positions:", best_positions)
|
231 |
print("Best Fitness:", best_fitness)
|
232 |
|
233 |
# Return the best positions and fitness after the optimization
|
234 |
-
return best_positions, best_fitness
|
235 |
|
236 |
def Step(self):
|
237 |
"""Do one swarm step"""
|
@@ -341,9 +341,9 @@ class GWO:
|
|
341 |
}
|
342 |
def plot_contour_and_wolves(self, wolf_positions):
|
343 |
# Ensure wolf_positions is a 2D array
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
|
348 |
# Define the objective function
|
349 |
def objective_function(x, y):
|
@@ -491,7 +491,7 @@ def optimize(npart, ndim, max_iter):
|
|
491 |
# Initialize the GWO algorithm with the provided parameters
|
492 |
gwo = GWO(obj=obj, npart=npart, ndim=ndim, max_iter=max_iter, init=init, bounds=bounds)
|
493 |
|
494 |
-
best_positions, best_fitness
|
495 |
|
496 |
# Convert best_fitness and best_positions to NumPy arrays if necessary
|
497 |
best_fitness_npy = np.array(best_fitness)
|
@@ -501,6 +501,12 @@ def optimize(npart, ndim, max_iter):
|
|
501 |
dispersion = gwo.Dispersion()
|
502 |
dispersion_text = f"Dispersion: {dispersion}"
|
503 |
|
|
|
|
|
|
|
|
|
|
|
|
|
504 |
# Plot the dispersion over time
|
505 |
dispersion_plot = gwo.plot_dispersion()
|
506 |
|
|
|
222 |
|
223 |
# Convert the list of best positions to a NumPy array
|
224 |
best_positions_array = np.array(best_positions)
|
225 |
+
np.save('best_positions_array', best_positions_array)
|
226 |
|
227 |
+
|
|
|
228 |
|
229 |
# Print the best positions and fitness found
|
230 |
print("Best Positions:", best_positions)
|
231 |
print("Best Fitness:", best_fitness)
|
232 |
|
233 |
# Return the best positions and fitness after the optimization
|
234 |
+
return best_positions, best_fitness
|
235 |
|
236 |
def Step(self):
|
237 |
"""Do one swarm step"""
|
|
|
341 |
}
|
342 |
def plot_contour_and_wolves(self, wolf_positions):
|
343 |
# Ensure wolf_positions is a 2D array
|
344 |
+
best_positions_loaded_array = np.load('best_positions_array.npy')
|
345 |
+
|
346 |
+
wolf_positions = best_positions_loaded_array
|
347 |
|
348 |
# Define the objective function
|
349 |
def objective_function(x, y):
|
|
|
491 |
# Initialize the GWO algorithm with the provided parameters
|
492 |
gwo = GWO(obj=obj, npart=npart, ndim=ndim, max_iter=max_iter, init=init, bounds=bounds)
|
493 |
|
494 |
+
best_positions, best_fitness= gwo.optimize()
|
495 |
|
496 |
# Convert best_fitness and best_positions to NumPy arrays if necessary
|
497 |
best_fitness_npy = np.array(best_fitness)
|
|
|
501 |
dispersion = gwo.Dispersion()
|
502 |
dispersion_text = f"Dispersion: {dispersion}"
|
503 |
|
504 |
+
# Load best_positions_loaded_array
|
505 |
+
best_positions_loaded_array = np.load('best_positions_array.npy')
|
506 |
+
|
507 |
+
# Plot the contour_and_wolves
|
508 |
+
plot_contour_and_wolves = gwo.plot_contour_and_wolves(best_positions_loaded_array)
|
509 |
+
|
510 |
# Plot the dispersion over time
|
511 |
dispersion_plot = gwo.plot_dispersion()
|
512 |
|