Tools
Operators
- fevovaq.tools.operators.cx_blx_alpha(parents, cx_mask, xp, alpha=0.5)[source]
BLX-alpha crossover.
- Parameters:
parents – Parents as arrays of real parameters with (pop_size,`n_params`) shape.
cx_mask – Crossover mask.
xp – Numpy or Cupy backend.
alpha – Positive real hyperparameter.
- Returns:
Resulting offspring.
- fevovaq.tools.operators.cx_one_point(parents, cx_mask, xp)[source]
One-point crossover.
- Parameters:
parents – Parents as arrays of real parameters with (pop_size,`n_params`) shape.
cx_mask – Crossover mask.
xp – Numpy or Cupy backend.
- Returns:
Resulting offspring.
- fevovaq.tools.operators.cx_two_point(parents, cx_mask, xp)[source]
Two-point crossover.
- Parameters:
parents – Parents as arrays of real parameters with (pop_size,`n_params`) shape.
cx_mask – Crossover mask.
xp – Numpy or Cupy backend.
- Returns:
Resulting offspring.
- fevovaq.tools.operators.cx_uniform(parents, cx_mask, xp, cx_indpb=0.5)[source]
Uniform crossover.
- Parameters:
parents – Parents as arrays of real parameters with (pop_size,`n_params`) shape.
cx_mask – Crossover mask.
xp – Numpy or Cupy backend.
cx_indpb – Independent probability for each parameter to be exchanged.
- Returns:
Resulting offspring.
- fevovaq.tools.operators.mut_gaussian(population, mut_mask, xp, mu=0, sigma=1, mut_indpb=0.1)[source]
Gaussian mutation.
- Parameters:
population – A population of individuals as array of real parameters with (pop_size, n_params) shape.
mut_mask – Mask of mutation.
xp – Numpy or Cupy backend.
mu – Mean or sequence of means for the gaussian addition mutation.
sigma – Standard deviation or sequence of standard deviations for the gaussian addition mutation.
mut_indpb – Independent probability for each parameter to be mutated.
- Returns:
Resulting mutated population.
- fevovaq.tools.operators.sel_best(population, fitness, k, xp)[source]
Selection of the first k best individuals (with the smallest objective values) in the population.
- Parameters:
population – A population of individuals as array of real parameters with (pop_size, n_params) shape.
fitness – A set of fitness values associated to the population as array of real values with (pop_size, ) shape.
k – Number of individuals to be selected.
xp – Numpy or Cupy backend.
- Returns:
Indices of selected individuals.
- fevovaq.tools.operators.sel_permutation(population, fitness, xp)[source]
Selection of the individuals by permuting the population.
- Parameters:
population – A population of individuals as array of real parameters with (pop_size, n_params) shape.
fitness – A set of fitness values associated to the population as array of real values with (pop_size, ) shape.
xp – Numpy or Cupy backend.
- Returns:
Indices of selected individuals.
- fevovaq.tools.operators.sel_random(population, fitness, k, xp, replace=True)[source]
Selection of k individuals randomly.
- Parameters:
population – A population of individuals as array of real parameters with (pop_size, n_params) shape.
fitness – A set of fitness values associated to the population as array of real values with (pop_size, ) shape.
k – Number of individuals to be selected.
xp – Numpy or Cupy backend.
replace – Whether the sample is with or without replacement. Default is True, meaning that an element can be selected multiple times.
- Returns:
Indices of selected individuals.
- fevovaq.tools.operators.sel_tournament(population, fitness, k, xp, tournament_size=3)[source]
Selection of the best individual among tournament_size randomly chosen individuals, k times.
- Parameters:
population – A population of individuals as array of real parameters with (pop_size, n_params) shape.
fitness – A set of fitness values associated to the population as array of real values with (pop_size, ) shape.
k – Number of individuals to be selected.
xp – Numpy or Cupy backend.
tournament_size – Size of the tournament.
- Returns:
Indices of selected individuals.
Distances
Support facilities
- class fevovaq.tools.support.BestIndividualTracker(xp)[source]
Bases:
objectClass used to track the best solution ever found during the algorithm execution.
- Parameters:
xp – Numpy or Cupy backend.
- class fevovaq.tools.support.Logbook[source]
Bases:
dictClass used to store info during the evolution.
- fevovaq.tools.support.compute_statistics(fitness, xp) dict[source]
Compute the statistics of fitness values.
- Parameters:
fitness – Fitness values as an array of real values with (pop_size, ) shape.
xp –
Numpy or Cupy backend.
- Returns:
Dictionary containing the min, max, mean, and standard deviation value.
- fevovaq.tools.support.print_info(n_run: int, header: bool = False, **kwargs)[source]
Print info.
- Parameters:
n_run – Independent execution number of the algorithm.
header – If True, the string indicating the independent execution number is printed.
kwargs – Information to be printed defined in a dictionary.
- fevovaq.tools.support.set_progress_bar(max_gen: int, max_nfev: int | None, desc: str | None = None, unit: str | None = None) tqdm[source]
Set the progress bar based on the stopping criterion.
- Parameters:
max_gen – Maximum number of generations.
max_nfev – Maximum number of fitness evaluations.
desc – Description related to the stopping criterion.
unit – Unit describing the progress.
- Returns:
The progress bar.