Tools
Operators
- evovaq.tools.operators.cx_blx_alpha(par1: ndarray, par2: ndarray, alpha: float = 0.5) tuple[numpy.ndarray, numpy.ndarray][source]
BLX-alpha crossover.
- Parameters:
par1 – The first parent as array of real parameters with (n_params,) shape.
par2 – The second parent as array of real parameters with (n_params,) shape.
alpha – Positive real hyperparameter.
- Returns:
The two resulting children.
- evovaq.tools.operators.cx_one_point(par1: ndarray, par2: ndarray) tuple[numpy.ndarray, numpy.ndarray][source]
One-point crossover.
- Parameters:
par1 – The first parent as array of real parameters with (n_params,) shape.
par2 – The second parent as array of real parameters with (n_params,) shape.
- Returns:
The two resulting children.
- evovaq.tools.operators.cx_two_point(par1: ndarray, par2: ndarray) tuple[numpy.ndarray, numpy.ndarray][source]
Two-point crossover.
- Parameters:
par1 – The first parent as array of real parameters with (n_params,) shape.
par2 – The second parent as array of real parameters with (n_params,) shape.
- Returns:
The two resulting children.
- evovaq.tools.operators.cx_uniform(par1: ndarray, par2: ndarray, cx_indpb: float = 0.5) tuple[numpy.ndarray, numpy.ndarray][source]
Uniform crossover.
- Parameters:
par1 – The first parent as array of real parameters with (n_params,) shape.
par2 – The second parent as array of real parameters with (n_params,) shape.
cx_indpb – Independent probability for each parameter to be exchanged.
- Returns:
The two resulting children.
- evovaq.tools.operators.mut_flip_bit(individual: ndarray, mut_indpb: float = 0.1) ndarray[source]
Flip-bit mutation.
- Parameters:
individual – Individual to be mutated as array of real parameters with (n_params,) shape.
mut_indpb – Independent probability for each parameter to be mutated.
- Returns:
Resulting mutated individual.
- evovaq.tools.operators.mut_gaussian(individual: ndarray, mu: Union[float, Sequence] = 0, sigma: Union[float, Sequence] = 1, mut_indpb: float = 0.1) ndarray[source]
Gaussian mutation.
- Parameters:
individual – Individual to be mutated as array of real parameters with (n_params,) shape.
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 individual.
- evovaq.tools.operators.sel_best(population: ndarray, fitness: ndarray, k: int) tuple[numpy.ndarray, numpy.ndarray][source]
Select 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.
- Returns:
Subsets of k best individuals and fitness values.
- evovaq.tools.operators.sel_permutation(population: ndarray, fitness: ndarray) tuple[numpy.ndarray, numpy.ndarray][source]
Select the mating pool by permutation of the population indices.
- 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.
- Returns:
Mating pool with individuals and fitness values with new indices.
- evovaq.tools.operators.sel_random(population: ndarray, fitness: ndarray, k: int, replace: bool = True) tuple[numpy.ndarray, numpy.ndarray][source]
Select 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.
replace – Whether the sample is with or without replacement. Default is True, meaning that an element can be selected multiple times.
- Returns:
Subsets of k individuals and fitness values randomly chosen.
- evovaq.tools.operators.sel_tournament(population: ndarray, fitness: ndarray, k: int, tournsize: int = 3) tuple[numpy.ndarray, numpy.ndarray][source]
Select the best individual among tournsize 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.
tournsize – Number of random individuals participating in each tournament.
- Returns:
Subsets of k individuals and fitness values.
Distance metrics
Support facilities
- class evovaq.tools.support.BestIndividualTracker[source]
Bases:
objectClass used to track the best solution ever found during the algorithm execution.
- class evovaq.tools.support.Logbook[source]
Bases:
dictClass used to store info during the evolution.
- class evovaq.tools.support.Particle(position: ndarray, velocity: ndarray, fitness: float)[source]
Bases:
objectClass used to define a particle described by position, velocity and fitness in
PSOalgorithm.- Parameters:
position – A possible solution as array of real parameters with (n_params,) shape.
velocity – Velocity as array of real parameters with (n_params,) shape.
fitness – The corresponding fitness value.
- update_fitness(new_fitness: float)[source]
Update the fitness value.
- Parameters:
new_fitness – New fitness value computed.
- update_position(param_bounds: Union[tuple, list[tuple]])[source]
Update the position of the particle by adding the updated velocity.
- Parameters:
param_bounds – Parameter bounds expressed as a tuple (min, max) or as a list of these tuples of n_params size.
- update_velocity(gbest: ndarray, inertia_weight: float, phi1: float, phi2: float, vmin: Optional[Union[float, ndarray]], vmax: Optional[Union[float, ndarray]])[source]
Update the velocity of the particle according to the equation proposed in [1].
References
[1] Shi, Y., & Eberhart, R. C., “A modified particle swarm optimizer”, Proceedings of the IEEE international conference on evolutionary computation, pp. 69–73, 1998.
- Parameters:
gbest – Global best position ever visited.
inertia_weight – Inertia weight.
phi1 – Acceleration coefficient determining the magnitude of the random force in the direction of personal best solution.
phi2 – Acceleration coefficient determining the magnitude of the random force in the direction of global best solution.
vmin – Lower value(s) of the velocity. If None, no limits are considered.
vmax – Upper value(s) of the velocity. If None, no limits are considered.
- evovaq.tools.support.compute_statistics(fitness: ndarray) dict[source]
Compute the statistics of fitness values.
- Parameters:
fitness –
Fitness values as an array of real values with (pop_size,) shape.
- Returns:
Dictionary containing the min, max, mean, and standard deviation value.
- evovaq.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.
- evovaq.tools.support.set_progress_bar(max_gen: int, max_nfev: Optional[int], desc: Optional[str] = None, unit: Optional[str] = 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.
Utilities
- evovaq.tools.utils.read_excel_file(filename: str, sheet_title: Optional[str] = None)[source]
Read an Excel file.
- evovaq.tools.utils.show_boxplot(data: Union[list, ndarray], xlabels: str, ylabel: str, filename: Optional[str] = None, colors: Optional[Union[str, list]] = None)[source]
Show the boxplot of numerical data.
- Parameters:
data – Numerical dataset(s).
xlabels – Labels for each dataset. Length must be compatible with dimensions of data.
ylabel – Label of y-axis.
filename – Filename of the figure to be saved. If None, the figure is not saved.
colors – Colors for each boxplot. If None, random colors are generated for each boxplot.