evox.algorithms.so.de_variants.de
¶
Module Contents¶
Classes¶
Differential Evolution (DE) algorithm for optimization. |
API¶
- class evox.algorithms.so.de_variants.de.DE(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
Differential Evolution (DE) algorithm for optimization.
Class Methods
__init__
: Initializes the DE 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 DE algorithm, involving mutation, crossover, and selection processes.
Note that the
evaluate
method is not defined in this class. It is expected to be provided by theProblem
class or another external component.Initialization
Initialize the DE algorithm with the given parameters.
- Parameters:
pop_size – The size of the population.
lb – The lower bounds of the search space. Must be a 1D tensor.
ub – The upper bounds of the search space. 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. Defaults to 0.5.
cross_probability – The crossover probability (CR). Defaults to 0.9.
mean – The mean for initializing the population with a normal distribution. Defaults to None.
stdev – The standard deviation for initializing the population with a normal distribution. 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 DE algorithm.
This involves the following sub-steps:
Mutation: Generate mutant vectors based on the specified base vector strategy (
best
orrand
) and the number of difference vectors.Crossover: Perform crossover between the current population and the mutant vectors based on the crossover probability.
Selection: Evaluate the fitness of the new population and select the better individuals between the current and new populations.
The method ensures that all new population vectors are clamped within the specified bounds.