delo.DElo¶
- class delo.DElo(population_size, p_best_rate=0.1, use_archive=True, archive_size=50, portion_of_top_players=0.1, players_amount=100, player_elo_rating_rate=0.4, task_elo_rating_rate=0.4, restart_eps_x=None, restart_eps_y=None, variation_for_CR=0.1, scale_for_F=0.1, logger=None, **logger_kwargs)¶
Differential Evolution with Elo ranking system
Optimization algorithm from Differential Evolution family. F and CR parameters are adjusted through optimizing using Elo ranking system. Utilized mutation strategy:
p-best. Succesful members from past will be stored in archive. Restart condition: minimum absolute dispersion across dimension.Examples
>>> # Optimize quadratic function in 2D:: >>> import delo >>> import numpy as np >>> >>> def square(x): ... return np.sum(x ** 2, axis=1) >>> >>> described_function = delo.DescribedFunction(square, dimension=2, domain_lower_limit=-10, domain_upper_limit=10) >>> algorithm = delo.DElo(100) >>> >>> solution, best_f_value = algorithm.optimize(described_function) >>> print(solution, best_f_value) 0.0, 0.0
>>> # If one have a function that takes a single argument and returns a single value, one have to wrap it like this:: >>> import delo >>> import numpy as np >>> >>> def my_single_argument_function(x): ... return np.sum(x ** 2) >>> >>> def my_multi_argument_wrapping(x): ... return np.array([my_single_argument_function(xi) for xi in x]) >>> >>> described_my_function = delo.DescribedFunction(my_multi_argument_wrapping, ... dimension=5, ... domain_lower_limit=-5, ... domain_upper_limit=5) >>> algorithm = delo.DElo(100) >>> >>> solution, best_f_value = algorithm.optimize(described_my_function, max_f_evals=10000) >>> print(solution, best_f_value) [0.0 0.0 -0.0 0.0 0.0], 8.5e-09
- __init__(population_size, p_best_rate=0.1, use_archive=True, archive_size=50, portion_of_top_players=0.1, players_amount=100, player_elo_rating_rate=0.4, task_elo_rating_rate=0.4, restart_eps_x=None, restart_eps_y=None, variation_for_CR=0.1, scale_for_F=0.1, logger=None, **logger_kwargs)¶
Initialise the algorithm, but not run in yet (see optimize).
- Parameters
population_size (positive int) –
p_best_rate (float from (0,1]) – Fraction of members chosen in
p_bestmutation strategy.portion_of_top_players (float from [1/population_size, 1]) – Fraction of top players to use as starting values in mutation.
players_amount (positive int) – How many players will be created. Has to be a square of natural number.
restart_eps_x (float, optional) – Minimal acceptable absolute distance between members. If smaller, a restart occurs. If
None, restarting will never occur.restart_eps_y (float, optional) – Minimal acceptable absolute difference between function values. If smaller, a restart occurs. If None, this will be same as
restart_eps_x.logger (Logger, PickleLogger, optional) – If provided, logs to the file information on the process of optimizing
Methods
__init__(population_size[, p_best_rate, ...])Initialise the algorithm, but not run in yet (see optimize).
get_solution()Get solution found during optimization process
optimize(described_function[, max_f_evals, ...])Optimize the described function.
- get_solution()¶
Get solution found during optimization process
- Returns
solution (member with lowest f-value), best_f_value.
- Return type
Tuple
- optimize(described_function, max_f_evals=1000, print_every=None, restarts_handled_externally=False, rng_seed=None)¶
Optimize the described function.
Pass the target function and start the optimization process.
- Parameters
described_function (DescribedFunction) – Function to be optimized with attributes.
max_f_evals (int) – Number of times that algorithm is allowed to evaluate function. When exceeded, the optimization process is terminated and the found minimum is returned.
print_every (int, optional) – Info about verbosity. Every print_every generation information about state of optimization will be printed on console. If print_every is omitted, no information will be printed.
restarts_handled_externally (bool) – If True and restarting conditions are met, the algorithm ends. If False and restarting conditions are met, the algorithm restarts.
rng_seed (int, optional) – seed to be used in pseudorandom number generation. Same seed leads to same run for the algorithm.
- Returns
solution (member with lowest f-value), best_f_value.
- Return type
Tuple