TroglodyteDerivations
commited on
Commit
•
3c2f31a
1
Parent(s):
6677a7e
Updated lines 486-487 with: # Initialize the GWO algorithm with the provided parameters gwo = GWO(obj=obj, npart=npart, ndim=ndim, max_iter=max_iter, init=init, bounds=bounds).
Browse files
app.py
CHANGED
@@ -481,36 +481,39 @@ class GWO:
|
|
481 |
|
482 |
|
483 |
def optimize(npart, ndim, max_iter):
|
|
|
|
|
|
|
484 |
|
485 |
-
|
486 |
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
|
495 |
-
|
496 |
-
|
497 |
|
498 |
-
|
499 |
-
|
500 |
|
501 |
-
|
502 |
-
|
503 |
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
|
512 |
-
|
513 |
-
|
514 |
|
515 |
|
516 |
|
|
|
481 |
|
482 |
|
483 |
def optimize(npart, ndim, max_iter):
|
484 |
+
|
485 |
+
# Initialize the GWO algorithm with the provided parameters
|
486 |
+
gwo = GWO(obj=obj, npart=npart, ndim=ndim, max_iter=max_iter, init=init, bounds=bounds)
|
487 |
|
488 |
+
best_positions, best_fitness = gwo.optimize()
|
489 |
|
490 |
+
# Convert best_fitness and best_positions to NumPy arrays if necessary
|
491 |
+
best_fitness_npy = np.array(best_fitness)
|
492 |
+
best_positions_npy = np.array(best_positions)
|
493 |
|
494 |
+
# Calculate dispersion
|
495 |
+
dispersion = self.Dispersion()
|
496 |
+
dispersion_text = f"Dispersion: {dispersion}"
|
497 |
|
498 |
+
# Get the contour plot as a PIL Image
|
499 |
+
contour_plot = self.plot_contour_and_wolves(best_positions)
|
500 |
|
501 |
+
# Plot the dispersion over time
|
502 |
+
dispersion_plot = self.plot_dispersion()
|
503 |
|
504 |
+
# Plot the dispersion heatmap
|
505 |
+
dispersion_heatmap_plot = self.plot_dispersion_heatmap(x_range=(-6,6), y_range=(-6,6))
|
506 |
|
507 |
+
# Load the best fitness and positions from .npy files
|
508 |
+
best_fitness_npy = np.load('best_fitness.npy')
|
509 |
+
best_positions_npy = np.load('best_positions.npy')
|
510 |
|
511 |
+
# Format the output strings
|
512 |
+
best_fitness_text = f"Best Fitness: {best_fitness_npy}"
|
513 |
+
best_positions_text = f"Best Positions: {best_positions_npy}"
|
514 |
|
515 |
+
# Return the images and text
|
516 |
+
return [contour_plot, dispersion_plot, dispersion_heatmap_plot], best_fitness_text, best_positions_text, dispersion_text
|
517 |
|
518 |
|
519 |
|