porcupy.base
Classes
Base class for optimization algorithms in Porcupy. |
Module Contents
- class porcupy.base.Optimizer(dimensions: int, bounds: Tuple[numpy.ndarray, numpy.ndarray], pop_size: int = 30, max_iter: int = 100, options: Dict[str, Any] | None = None, ftol: float = -np.inf, ftol_iter: int = 1)[source]
Bases:
abc.ABCBase class for optimization algorithms in Porcupy.
This abstract base class provides the foundation for all optimization algorithms in the Porcupy library. It defines the common interface and functionality that all optimizers should implement.
- Parameters:
dimensions (int) – Number of dimensions in the search space.
bounds (tuple of numpy.ndarray) – A tuple of size 2 where the first entry is the minimum bound while the second entry is the maximum bound. Each array must be of shape (dimensions,).
pop_size (int, optional) – Number of search agents in the population (default: 30).
max_iter (int, optional) – Maximum number of iterations (default: 100).
options (dict, optional) – A dictionary containing algorithm-specific parameters.
ftol (float, optional) – Relative error in objective_func(best_pos) acceptable for convergence (default: -np.inf).
ftol_iter (int, optional) – Number of iterations over which the relative error in objective_func(best_pos) is acceptable for convergence (default: 1).
- reset()[source]
Reset the attributes of the optimizer
This method reinitializes all history tracking attributes and prepares the optimizer for a new optimization run.
- abstract optimize(objective_func: Callable, n_processes: int | None = None, verbose: bool = False, **kwargs) Tuple[numpy.ndarray, float, numpy.ndarray][source]
Optimize the objective function
- Parameters:
- Returns:
A tuple containing (best_position, best_cost, cost_history)
- Return type: