utils module¶
- exception utils.SolutionException(message)¶
Bases:
Exception
- utils.eaMuPlusLambda_stop_isl(islands, toolbox, mu, num_ind, cxpb, mutpb, ngen, mut_functs_isl: list, stats=None, stop_after=40, verbose=True)¶
This is the \((\mu + \lambda)\) evolutionary algorithm.
- Parameters:
islands (list) – list List of arrays of islands.
toolbox (deap.base.Toolbox) – deap.base.Toolbox Contains the evolution operators.
mu (int) – int The number of individuals to select for the next generation.
num_ind (int) – int The number of children to produce at each generation.
cxpb (float) – float The probability that an offspring is produced by crossover.
mutpb (float) – float The probability that an offspring is produced by mutation.
ngen (int) – int Number of generations.
mut_functs_isl (list) – list List of mutation functions for every island.
stats (deap.tools.Statistics) – deap.tools.Statistics, optional An object that is updated in place, optional. Defaults to None.
stop_after (int) – int, optional Number of non-improving generations to stop after. Defaults to 100.
verbose (str) – str, optional Verbose. Defaults to __debug__.
- utils.get_removed_from_solution(solution, names)¶
Get set items that were not selected by the minimizer.
- Parameters:
solution (array) – array Minimizer boolean solution.
names (np.array) – np.array Names of the items of the list in the correct order.
- Returns:
- np.array
Set items not selected by minimizer.
- utils.get_results(solutions, fitness, names, upper_bound=0.4, lower_bound=0, min_freq=0.65)¶
Selecting final set of candidate set items from solutions extracted by the minimizer, by taking solutions that appear often in the best solutions.
- Parameters:
solutions (np.array) – np.array All final solutions.
fitness (np.array) – np.array Fitness of extracted solutions.
names (list) – list Names of all set items in the correct order.
upper_bound (float, optional) – float, optional Upper bound on p-value for selected solutions. Defaults to 0.4.
lower_bound (float, optional) – float, optional Lower bound on p-value for selected solutions. Defaults to 0.
min_freq (float, optional) – float, optional Minimal frequency for a solution to appear in the set of best solutions to be selected. Defaults to 0.65.
- Raises:
SolutionException – _description_
- Returns:
- list
Final set of candidate set items from solutions extracted by the minimizer.
- utils.get_sol_from_indices(indices, ind_len)¶
Getting a solution boolean array based on the indices.
- Parameters:
indices (np.array) – np.array Indices of selected items.
ind_len (_type_) – _type_ Size of the set.
- Returns:
- np.array
Returns a solution in the same format as outputted from the optimizer.
- utils.plot_pareto(solutons, pareto, upper_bound=None, lower_bound=None)¶
Plots the final solutions outputted by the minimizer.
- Parameters:
solutions (np.array) – np.array All final solutions.
pareto (np.array) – np.array All solutions on the Pareto front.
upper_bound (float, optional) – float, optional Upper bound on p-value for selected solutions. Defaults to None.
lower_bound (float, optional) – float, optional Lower bound on p-value for selected solutions. Defaults to None.
- Raises:
SolutionException – Exception when no solution found.
- Returns:
- matplotib.pyplot
Plotted solutions with Pareto front.
- utils.varOr(population, toolbox, num_ind, cxpb, mutpb, mutate_funct)¶
Part of an evolutionary algorithm applying only the variation part (crossover and mutation). The modified individuals have their fitness invalidated. The individuals are cloned so returned population is independent of the input population. Same as in the DEAP library except for enabling different mutations for different islands.
- Parameters:
population (list) – array List of individuals to vary.
toolbox (deap.base.Toolbox) – deap.base.Toolbox Contains the evolution operators.
num_ind (int) – int The number of children to produce at each generation.
cxpb (float) – float The probability of mating two individuals.
mutpb (float) – float The probability of mutating an individual.
mutate_funct (function) – function Mutation function.
- Returns:
- _array_: A list of varied individuals that are independent of their
parents.