evox.algorithms.so.pso_variants.pso

Module Contents

Classes

PSO

The basic Particle Swarm Optimization (PSO) algorithm.

API

class evox.algorithms.so.pso_variants.pso.PSO(pop_size: int, lb: torch.Tensor, ub: torch.Tensor, w: float = 0.6, phi_p: float = 2.5, phi_g: float = 0.8, device: torch.device | None = None)[source]

Bases: evox.core.Algorithm

The basic Particle Swarm Optimization (PSO) algorithm.

Class Methods

  • __init__: Initializes the PSO algorithm with given parameters (population size, lower and upper bounds, inertia weight, cognitive weight, and social weight).

  • step: Performs a single optimization step using Particle Swarm Optimization (PSO), updating local best positions and fitness values, and adjusting velocity and positions based on inertia, cognitive, and social components.

Note that the evaluate method is not defined in this class, it is a proxy function of Problem.evaluate set by workflow; therefore, it cannot be used in class methods other than step.

Initialization

Initialize the PSO algorithm with the given parameters.

Parameters:
  • pop_size – The size of the population.

  • w – The inertia weight. Defaults to 0.6.

  • phi_p – The cognitive weight. Defaults to 2.5.

  • phi_g – The social weight. Defaults to 0.8.

  • lb – The lower bounds of the particle positions. Must be a 1D tensor.

  • ub – The upper bounds of the particle positions. Must be a 1D tensor.

  • device – The device to use for the tensors. Defaults to None.

step()[source]

Perform a normal optimization step using PSO.

This function evaluates the fitness of the current population, updates the local best positions and fitness values, and adjusts the velocity and positions of particles based on inertia, cognitive, and social components. It ensures that the updated positions and velocities are clamped within the specified bounds.

The local best positions and fitness values are updated if the current fitness is better than the recorded local best. The global best position and fitness are determined using helper functions.

The velocity is updated based on the weighted sum of the previous velocity, the cognitive component (personal best), and the social component (global best). The population positions are then updated using the new velocities.

init_step()[source]

Perform the first step of the PSO optimization.

See step for more details.