evox.algorithms.so.de_variants.ode

Module Contents

Classes

ODE

Opposition-based Differential Evolution (ODE) algorithm for optimization.

API

class evox.algorithms.so.de_variants.ode.ODE(pop_size: int, lb: torch.Tensor, ub: torch.Tensor, base_vector: Literal[best, rand] = 'rand', num_difference_vectors: int = 1, differential_weight: float | torch.Tensor = 0.5, cross_probability: float = 0.9, mean: torch.Tensor | None = None, stdev: torch.Tensor | None = None, device: torch.device | None = None)[source]

Bases: evox.core.Algorithm

Opposition-based Differential Evolution (ODE) algorithm for optimization.

Class Methods

  • __init__: Initializes the ODE algorithm with the given parameters, including population size, bounds, mutation strategy, and other hyperparameters.

  • init_step: Performs the initial evaluation of the population’s fitness and proceeds to the first optimization step.

  • step: Executes a single optimization step of the ODE algorithm, involving mutation, crossover, selection, and opposition-based mechanisms.

Note that the evaluate method is not defined in this class. It is expected to be provided by the Problem class or another external component.

Initialization

Initialize the Opposition-based Differential Evolution (ODE) algorithm with the given 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.

  • base_vector – The base vector type used in mutation. Either “best” or “rand”. Defaults to “rand”.

  • num_difference_vectors – The number of difference vectors used in mutation. Must be at least 1 and less than half of the population size. Defaults to 1.

  • differential_weight – The differential weight(s) (F) applied to difference vectors. Can be a float or a tensor of shape [num_difference_vectors]. Defaults to 0.5.

  • cross_probability – The crossover probability (CR). Must be in (0, 1]. Defaults to 0.9.

  • mean – The mean for initializing the population with a normal distribution. Must be provided with stdev if used. Defaults to None.

  • stdev – The standard deviation for initializing the population with a normal distribution. Must be provided with mean if used. Defaults to None.

  • device – The device to use for tensor computations. Defaults to None.

init_step()[source]

Perform the initial evaluation of the population’s fitness and proceed to the first optimization step.

This method evaluates the fitness of the initial population and then calls the step method to perform the first optimization iteration.

step()[source]

Execute a single optimization step of the ODE algorithm.

This involves the following sub-steps:

  1. Mutation: Generate mutant vectors based on the specified base vector strategy (best or rand) and the number of difference vectors.

  2. Crossover: Perform crossover between the current population and the mutant vectors based on the crossover probability.

  3. Selection: Evaluate the fitness of the new population and select the better individuals between the current and new populations.

  4. Opposition-Based Mechanism: Generate opposition-based population, evaluate their fitness, and perform selection to potentially replace current individuals with their opposites if they are better.

The method ensures that all new population vectors are clamped within the specified bounds.