evox.algorithms.so.pso_variants.clpso

Module Contents

Classes

CLPSO

The basic CSO algorithm.

API

class evox.algorithms.so.pso_variants.clpso.CLPSO(pop_size: int, lb: torch.Tensor, ub: torch.Tensor, inertia_weight: float = 0.5, const_coefficient: float = 1.5, learning_probability: float = 0.05, device: torch.device | None = None)[source]

Bases: evox.core.Algorithm

The basic CSO algorithm.

Class Methods

  • __init__: Initializes the CLPSO algorithm with given static parameters including lower and upper bounds for particle positions.

  • setup: Initializes the CLPSO algorithm and sets up initial population, velocity, and buffers for tracking best local and global positions and fitness values.

  • step: Performs a single optimization step using CLPSO, 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 CLPSO algorithm with the given static parameters.

Parameters:
  • pop_size – The size of the population.

  • 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.

  • inertia_weight – The inertia weight (w). Defaults to 0.5.

  • const_coefficient – The cognitive weight (c). Defaults to 1.5.

  • learning_probability – The social weight (P_c). Defaults to 0.05.

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

init_step()[source]
step()[source]

Perform a single optimization step using CLPSO.

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.