src.baseline.bbo.sdmspso

Module Contents

Classes

SDMSPSO

Introduction

The sDMS-PSO is a self-adaptive dynamic multi-swarm particle swarm optimizer that incorporates parameter adaptation, cooperative coevolution among multiple swarms, and a quasi-Newton local search to enhance convergence speed and optimization performance.

API

class src.baseline.bbo.sdmspso.SDMSPSO(config)[source]

Bases: src.environment.optimizer.basic_optimizer.Basic_Optimizer

Introduction

The sDMS-PSO is a self-adaptive dynamic multi-swarm particle swarm optimizer that incorporates parameter adaptation, cooperative coevolution among multiple swarms, and a quasi-Newton local search to enhance convergence speed and optimization performance.

Original paper

A self-adaptive dynamic particle swarm optimizer.” 2015 IEEE Congress on Evolutionary Computation (CEC). IEEE, 2015.

Initialization

Introduction

Initializes the SDMS-PSO (Sub-swarm Dynamic Multi-Swarm Particle Swarm Optimization) algorithm with the provided configuration, setting up algorithm parameters, population structure, and tracking variables.

Args:

  • config (object):

    • The Attributes needed for the SDMSPSO optimizer in config are the following:

      • maxFEs (int): Maximum number of function evaluations allowed.Default directly depends on the type of the problem.

      • n_logpoint (int): Number of log points for tracking progress. Default is 50.

      • log_interval (int): Interval at which logs are recorded. Default is maxFEs // n_logpoint.

      • full_meta_data (bool): Flag indicating whether to store complete solution history. Default is False.

      • seed (int): Random seed for reproducibility. Used for initializing positions and velocities.

Attributes:

  • __w (float): Inertia weight parameter. Default is 0.729.

  • __c1 (float): Cognitive learning factor. Default is 1.49445.

  • __c2 (float): Social learning factor. Default is 1.49445.

  • __m (int): Sub-swarm size. Default is 3.

  • __R (int): Regrouping interval. Default is 10.

  • __LP (int): Learning period. Default is 10.

  • __LA (int): Length of archives. Default is 8.

  • __L (int): Local refining period. Default is 100.

  • __L_FEs (int): Max fitness evaluations using in the local search. Default is 200.

  • __NP (int): Total population size. Default is 99.

  • __n_swarm (int): Number of sub-swarms (NP/m). Default is 33.

  • __w_decay (bool): Whether to use weight decay strategy. Default is True.

__str__()[source]

Introduction

Returns the string representation of the SDMSPSO class.

Returns:

  • str: The string ‘SDMSPSO’, representing the class name.

__get_costs(problem, position)[source]

Introduction

Computes the cost(s) for a given set of positions using the provided problem’s evaluation function, optionally adjusting by the problem’s optimum. Also stores metadata if enabled.

Args:

  • problem: The problem object.

  • position (np.ndarray): An array of candidate solutions (positions) to be evaluated.

Returns:

  • np.ndarray or float: The computed cost(s) for the provided positions.

Side Effects:

  • Increments the function evaluation counter (self.__fes) by the number of positions evaluated.

  • If self.full_meta_data is True, appends the computed costs and positions to self.meta_Cost and self.meta_X, respectively.

__initilize(problem)[source]

Introduction

Initializes the particle swarm for the optimization problem, setting up positions, velocities, and best values.

Args:

  • problem: The problem object.

Side Effects:

  • Initializes and sets the following instance attributes:

    • __dim: Dimension of the problem.

    • __max_velocity: Maximum velocity for particles.Decided by the problem’s bounds.

    • __particles: Dictionary containing particle positions, velocities, and best values.

    • __max_cost: Minimum cost found during initialization.

Notes:

  • Uses a random number generator (self.rng) to initialize particle positions and velocities within the specified bounds.

  • Computes initial costs and identifies global and personal bests for the swarm.

__reset(problem)[source]

Introduction

Resets the internal state and parameters of the optimizer for a new optimization run on the given problem instance.

Args:

  • problem: The problem object to be optimized.

Attributes:

  • __dim (int): Problem dimension, obtained from problem.dim.

  • __w (float): Inertia weight parameter, reset to 0.9 if __w_decay is True, otherwise maintains default value of 0.729.

  • __gen (int): Generation counter, reset to 0.

  • __fes (int): Function evaluation counter, reset to 0.

  • __per_no_improve (numpy.ndarray): Counter for number of iterations without improvement for each particle, reset to 0.

  • __lbest_no_improve (numpy.ndarray): Counter for number of iterations without improvement for each subswarm’s local best, reset to 0.

  • __learning_period (bool): Learning period flag, reset to True, indicating a new learning phase.

  • __parameter_set (list): Parameter set storage, reset to empty list.

  • __success_num (numpy.ndarray): Counter for successful updates for each subswarm, reset to zeros.

  • __cur_mode (str): Current operating mode, set to ‘ls’ (local search mode).

  • __fes_eval (numpy.ndarray): Copy of function evaluation counter, reset to 0, used for specific calculations.

  • log_index (int): Logging index, reset to 1, used to control logging frequency.

  • cost (list): Storage for best cost values during optimization, initialized with current global best value.

Returns:

  • None

Side Effects:

  • Resets or reinitializes various internal attributes such as generation count, function evaluation counters, learning period flags, parameter sets, and success counters.

  • Reinitializes the swarm, regrouping particles and updating local bests.

  • Resets logging and cost tracking variables.

__random_regroup()[source]

Introduction

Randomly shuffles the order of particles in the swarm and resets improvement counters.

Attributes:

  • Rearranges the following particle parameters according to the random permutation:

    • current_position: Current positions of all particles are rearranged

    • c_cost: Current cost values are reordered to match the new particle arrangement

    • pbest_position: Personal best positions are maintained but reassigned to different sub-swarms

    • pbest: Personal best costs are reordered accordingly

    • velocity: Particle velocities are preserved but reassigned

    • __per_no_improve: Personal improvement counters follow their respective particles

__update_lbest(init=False)[source]

Introduction

Updates the local best (lbest) positions and costs for each swarm in a particle swarm optimization (PSO) algorithm. Handles both initialization and iterative update of lbest values, tracking improvements and updating relevant counters.

Args:

  • init (bool, optional): If True, performs initialization of lbest values using the current personal bests (pbest) of the particles. If False, updates lbest values based on new pbest values and tracks improvements. Default is False.

Updates:

  • self.__particles[‘lbest_cost’]: The best cost found in each swarm.

  • self.__particles[‘lbest_position’]: The position corresponding to the best cost in each swarm.

  • self.__lbest_index: The index of the lbest particle in each swarm.

  • self.__success_num: The number of times a new lbest is found for each swarm.

  • self.__lbest_no_improve: The number of iterations since the last improvement for each swarm.

Notes:

  • Assumes that self.__particles[‘pbest’] and self.__particles[‘pbest_position’] are properly shaped and populated.

  • Uses numpy operations for efficient batch updates.

__get_iwt()[source]

Introduction

Computes and updates the inertia weight (__iwt) for the swarm based on the current state of the parameter set and success count.

Description

The method determines the inertia weight for each particle in the swarm. If the number of parameters in the set is less than a threshold (__LA) or the sum of successful updates is less than or equal to another threshold (__LP), the inertia weight is set to a random value in the range [0.4, 0.9) for each particle. Otherwise, it is sampled from a normal distribution centered at the median of the parameter set with a standard deviation of 0.1.

Args

None

Returns

None

Side Effects

  • Updates the __iwt attribute with a numpy array of inertia weights for the swarm.

Notes

  • Relies on the attributes: __parameter_set, __LA, __success_num, __LP, rng, and __n_swarm.

__update(problem)[source]

Introduction

Updates the state of the particle swarm in the PSO (Particle Swarm Optimization) algorithm for a given optimization problem. This includes updating particle velocities, positions, personal bests, local/global bests, and logging progress.

Args:

  • problem: An object representing the optimization problem, which must provide lower and upper bounds (lb, ub) and a cost evaluation method.

Updates:

  • Particle velocities and positions based on the current mode (ls for local best, gs for global best).

  • Personal best positions and costs for each particle.

  • Global best position and value across all particles.

  • Local best positions and costs if in local search mode.

  • Internal logging of global best cost at specified intervals.

Notes:

  • Uses random coefficients and inertia weights for velocity updates.

  • Applies boundary constraints to particle positions.

  • Assumes internal state variables such as self.__particles, self.__c1, self.__c2, self.__w, etc., are properly initialized.

  • Logging is performed at intervals defined by self.log_interval.

__update_parameter_set()[source]

Introduction

Updates the internal parameter set by selecting the parameter corresponding to the highest success count. Maintains the parameter set size within the limit specified by self.__LA.

Args:

None

Modifies:

  • self.__parameter_set (list): Updates the list by appending the most successful parameter and removing the oldest if the size limit is reached.

Returns:

None

__quasi_Newton()[source]

Introduction

Applies a quasi-Newton (BFGS) local refinement to the best-performing particles in the swarm to improve their positions and costs.

Args:

None

Modifies:

  • Updates self.__particles['lbest_position'] and self.__particles['lbest_cost'] for selected particles if a better solution is found.

  • Updates self.__particles['pbest_position'] and self.__particles['pbest'] for corresponding personal bests.

  • Increments self.__fes by the number of function evaluations used in the local optimization.

Notes:

  • Selects the top quarter of particles with the lowest local best cost for refinement.

  • Uses the BFGS algorithm with a maximum of 9 iterations for local optimization.

  • Only updates positions and costs if the local optimization finds a better solution.

run_episode(problem)[source]

Introduction

Executes a single optimization episode using a metaheuristic algorithm, managing the optimization process, updating parameters, and collecting results and optional metadata.

Args:

  • problem (object): The optimization problem instance, which should provide an evaluation interface and may have an optimum attribute.

Returns:

  • dict: A dictionary containing:

    • ‘cost’ (list): The cost values logged during the episode.

    • ‘fes’ (int): The total number of function evaluations performed.

    • ‘metadata’ (dict, optional): If self.full_meta_data is True, includes:

      • ‘X’ (list): The meta-level solution data collected during the run.

      • ‘Cost’ (list): The meta-level cost data collected during the run.

Notes:

  • The method manages both local search and global search phases, parameter updates, and logging.

  • If the problem’s optimum is not specified, the episode ends when the maximum number of function evaluations is reached.

  • Ensures the cost log is filled up to the configured number of log points.