metaheuristic_designer.operators.operator_functions.swarm module#

Swarm intelligence operator implementations.

pso_operator(population_matrix, population_speed, historical_best, global_best, rng=None, w=0.7, c1=1.5, c2=1.5)[source]#

Perform a single step of the standard Particle Swarm optimization (PSO).

Velocity is updated as: :rtype: tuple[ndarray[tuple[int, int], floating] | ndarray[tuple[int, int], integer] | ndarray[tuple[int, int], uint8 | bool], ndarray[tuple[int, int], floating] | ndarray[tuple[int, int], integer] | ndarray[tuple[int, int], uint8 | bool]]

\[v_{i} = w v_{i} + c_1 r_1 (p_{i} - x_{i}) + c_2 r_2 (g - x_{i})\]

where \(p_{i}\) is the historical best of particle i, \(g\) is the global best, and \(r_1\), \(r_2\) are uniform random numbers in [0, 1].

The new position is \(x_{i} + v_{i}\).

Parameters:
population_matrixMatrixLike

Current positions, shape (N, D).

population_speedMatrixLike

Current velocities, shape (N, D).

historical_bestMatrixLike

Personal best positions, shape (N, D).

global_bestMatrixLike

Global best position, shape (D,) (broadcast to (N, D)).

rngRNGLike, optional

Random number generator.

wfloat, optional

Inertia weight (default 0.7).

c1float, optional

Cognitive acceleration coefficient (default 1.5).

c2float, optional

Social acceleration coefficient (default 1.5).

Returns:
tuple[MatrixLike, MatrixLike]

The new positions and the new velocities, both shape (N, D).

Parameters:
  • population_matrix (ndarray[tuple[int, int], floating] | ndarray[tuple[int, int], integer] | ndarray[tuple[int, int], uint8 | bool])

  • population_speed (ndarray[tuple[int, int], floating] | ndarray[tuple[int, int], integer] | ndarray[tuple[int, int], uint8 | bool])

  • historical_best (ndarray[tuple[int, int], floating] | ndarray[tuple[int, int], integer] | ndarray[tuple[int, int], uint8 | bool])

  • global_best (ndarray[tuple[int, int], floating] | ndarray[tuple[int, int], integer] | ndarray[tuple[int, int], uint8 | bool])

  • rng (int | Generator | None)

  • w (float)

  • c1 (float)

  • c2 (float)

Return type:

tuple[ndarray[tuple[int, int], floating] | ndarray[tuple[int, int], integer] | ndarray[tuple[int, int], uint8 | bool], ndarray[tuple[int, int], floating] | ndarray[tuple[int, int], integer] | ndarray[tuple[int, int], uint8 | bool]]

pso_operator_wrapper(population, rng=None, w=0.7, c1=1.5, c2=1.5)[source]#

Wrapper that integrates the PSO operator with the library’s Population API.

Extracts the solution and velocity parts from the population (which must use a ParameterExtendingEncoding with a "speed" parameter), applies the standard PSO update, and encodes the result back into the population’s genotype matrix.

Return type:

Population

Parameters:
populationPopulation

Current population. Its encoding must be a ParameterExtendingEncoding that includes a "speed" parameter.

_initializerInitializer

Initializer (unused; kept for interface compatibility).

rngRNGLike, optional

Random number generator.

wfloat, optional

Inertia weight (default 0.7).

c1float, optional

Cognitive coefficient (default 1.5).

c2float, optional

Social coefficient (default 1.5).

Returns:
Population

The updated population with new positions and velocities.

Parameters:
  • population (Population)

  • rng (int | Generator | None)

  • w (float)

  • c1 (float)

  • c2 (float)