TroglodyteDerivations commited on
Commit
a13d33d
1 Parent(s): daa9a67

Updated lines 490-515 with: def optimize(npart, ndim, max_iter): # Initialize the GWO algorithm with the provided parameters gwo = GWO(obj=obj, npart=npart, ndim=ndim, max_iter=max_iter, init=init, bounds=bounds) best_positions, best_fitness, contour_plot = gwo.optimize() # Convert best_fitness and best_positions to NumPy arrays if necessary best_fitness_npy = np.array(best_fitness) best_positions_npy = np.array(best_positions) # Calculate dispersion dispersion = gwo.Dispersion() dispersion_text = f"Dispersion: {dispersion}" # Plot the dispersion over time dispersion_plot = gwo.plot_dispersion() # Plot the dispersion heatmap dispersion_heatmap_plot = gwo.plot_dispersion_heatmap(x_range=(-6,6), y_range=(-6,6)) # Format the output strings best_fitness_text = f"Best Fitness: {best_fitness_npy}" best_positions_text = f"Best Positions: {best_positions_npy}" # Return the images and text return [contour_plot, dispersion_plot, dispersion_heatmap_plot], best_fitness_text, best_positions_text, best_fitness_npy, best_positions_npy, dispersion_text

Browse files
Files changed (1) hide show
  1. app.py +1 -9
app.py CHANGED
@@ -488,11 +488,10 @@ class GWO:
488
 
489
 
490
  def optimize(npart, ndim, max_iter):
491
-
492
  # Initialize the GWO algorithm with the provided parameters
493
  gwo = GWO(obj=obj, npart=npart, ndim=ndim, max_iter=max_iter, init=init, bounds=bounds)
494
 
495
- best_positions, best_fitness = gwo.optimize()
496
 
497
  # Convert best_fitness and best_positions to NumPy arrays if necessary
498
  best_fitness_npy = np.array(best_fitness)
@@ -502,19 +501,12 @@ def optimize(npart, ndim, max_iter):
502
  dispersion = gwo.Dispersion()
503
  dispersion_text = f"Dispersion: {dispersion}"
504
 
505
- # Get the contour plot as a PIL Image
506
- contour_plot = gwo.plot_contour_and_wolves(best_positions_array)
507
-
508
  # Plot the dispersion over time
509
  dispersion_plot = gwo.plot_dispersion()
510
 
511
  # Plot the dispersion heatmap
512
  dispersion_heatmap_plot = gwo.plot_dispersion_heatmap(x_range=(-6,6), y_range=(-6,6))
513
 
514
- # Load the best fitness and positions from .npy files
515
- best_fitness_npy = np.load('best_fitness.npy')
516
- best_positions_npy = np.load('best_positions.npy')
517
-
518
  # Format the output strings
519
  best_fitness_text = f"Best Fitness: {best_fitness_npy}"
520
  best_positions_text = f"Best Positions: {best_positions_npy}"
 
488
 
489
 
490
  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, contour_plot = 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
  # Plot the dispersion over time
505
  dispersion_plot = gwo.plot_dispersion()
506
 
507
  # Plot the dispersion heatmap
508
  dispersion_heatmap_plot = gwo.plot_dispersion_heatmap(x_range=(-6,6), y_range=(-6,6))
509
 
 
 
 
 
510
  # Format the output strings
511
  best_fitness_text = f"Best Fitness: {best_fitness_npy}"
512
  best_positions_text = f"Best Positions: {best_positions_npy}"