porcupy.utils.interactive_visualization

Interactive visualization module for the Crested Porcupine Optimizer (CPO).

This module provides interactive visualization tools and dashboard components for monitoring and analyzing the CPO algorithm’s performance in real-time.

Classes

OptimizationDashboard

Interactive dashboard for monitoring CPO optimization in real-time.

ParameterTuningDashboard

Interactive dashboard for parameter tuning and sensitivity analysis.

Functions

create_interactive_optimization_plot(objective_func, ...)

Create an interactive plot for exploring the optimization landscape.

Module Contents

class porcupy.utils.interactive_visualization.OptimizationDashboard(objective_func: Callable, bounds: Tuple[numpy.ndarray, numpy.ndarray], dimensions: int = 2, update_interval: float = 0.5, figsize: Tuple[int, int] = (15, 10))[source]

Interactive dashboard for monitoring CPO optimization in real-time.

This dashboard displays multiple visualizations simultaneously, including: - Convergence history - Population size history - Diversity metrics - Defense mechanism usage - Current porcupine positions

The dashboard updates in real-time during optimization.

objective_func[source]
bounds[source]
dimensions = 2[source]
update_interval = 0.5[source]
figsize = (15, 10)[source]
iterations = [][source]
best_costs = [][source]
pop_sizes = [][source]
diversity_history = [][source]
defense_counts[source]
position_history = [][source]
best_position_history = [][source]
is_running = False[source]
current_iteration = 0[source]
update(iteration: int, best_cost: float, pop_size: int, positions: numpy.ndarray, best_position: numpy.ndarray, defense_types: List[str])[source]

Update the dashboard with new optimization data.

Parameters:
  • iteration (int) – Current iteration number.

  • best_cost (float) – Current best cost value.

  • pop_size (int) – Current population size.

  • positions (ndarray) – Current positions of the porcupines, shape (pop_size, dimensions).

  • best_position (ndarray) – Current global best position, shape (dimensions,).

  • defense_types (list) – List of defense mechanisms used by each porcupine.

start_monitoring()[source]

Start the dashboard monitoring thread.

stop_monitoring()[source]

Stop the dashboard monitoring thread.

save_dashboard(save_path: str, dpi: int = 300)[source]

Save the current dashboard state as an image.

Parameters:
  • save_path (str) – Path to save the dashboard image.

  • dpi (int, optional) – DPI for the saved image (default: 300).

close()[source]

Close the dashboard and clean up resources.

class porcupy.utils.interactive_visualization.ParameterTuningDashboard(parameter_name: str, parameter_range: List[float], result_metric: str = 'Best Cost', figsize: Tuple[int, int] = (12, 8))[source]

Interactive dashboard for parameter tuning and sensitivity analysis.

This dashboard allows for real-time visualization of how different parameter values affect the performance of the CPO algorithm.

parameter_name[source]
parameter_range[source]
result_metric = 'Best Cost'[source]
figsize = (12, 8)[source]
results = [][source]
update(parameter_value: float, result: float, convergence_history: List[float] | None = None)[source]

Update the dashboard with new parameter tuning results.

Parameters:
  • parameter_value (float) – Value of the parameter being tested.

  • result (float) – Result metric value (e.g., best cost).

  • convergence_history (list, optional) – Convergence history for this parameter value.

save_dashboard(save_path: str, dpi: int = 300)[source]

Save the current dashboard state as an image.

Parameters:
  • save_path (str) – Path to save the dashboard image.

  • dpi (int, optional) – DPI for the saved image (default: 300).

close()[source]

Close the dashboard and clean up resources.

porcupy.utils.interactive_visualization.create_interactive_optimization_plot(objective_func: Callable, bounds: Tuple[numpy.ndarray, numpy.ndarray], initial_positions: numpy.ndarray, figsize: Tuple[int, int] = (10, 8))[source]

Create an interactive plot for exploring the optimization landscape.

Parameters:
  • objective_func (callable) – The objective function to visualize.

  • bounds (tuple) – A tuple (lb, ub) containing the lower and upper bounds.

  • initial_positions (ndarray) – Initial positions of the porcupines, shape (pop_size, 2).

  • figsize (tuple, optional) – Figure size as (width, height) in inches (default: (10, 8)).

Returns:

A tuple containing (fig, ax, scatter) for further customization.

Return type:

tuple