delo.DElo_ties_and_QI

class delo.DElo_ties_and_QI(population_size, p_best_rate=0.2, use_archive=True, archive_size=50, portion_of_top_players=0.2, players_amount=100, player_elo_rating_rate=0.4, player_elo_rating_rate_MOV=0.4, task_elo_rating_rate=0.4, task_elo_rating_rate_MOV=0.4, history_for_ties_size=20, win_tie=0.5, tie_loss=0.0, expectation_factor=0.1, restart_eps_x=None, restart_eps_y=None, variation_for_CR=0.1, scale_for_F=0.1, logger=None, **logger_kwargs)

Modification of DElo algorithm - Differential Evolution with Elo ranking system

Optimization algorithm from Differential Evolution family. F and CR parameters are adjusted through optimizing using Elo ranking system. Updates in rating are based on relative change of function value and on loss-tie-win odds. Utilized mutation strategy: p-best. Succesful members from past will be stored in archive. Restart condition: minimum absolute dispersion across dimension.

Notes

A history of several (history_for_ties_size) previous function differences is recorded. Whenever a positive new function difference is less than win_tie percentile of previous function differences, it is a tie. Otherwise - a win. Whenever a negative new function difference is less than tie_loss percentile of history, it is a tie. Otherwise - a loss.

Elo ratings, apart from predicting victory odds, are used to predict relative function difference. The prediction function is (rating_difference * expectation_factor).

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_ties_and_QI(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_ties_and_QI(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], 1.1e-11
__init__(population_size, p_best_rate=0.2, use_archive=True, archive_size=50, portion_of_top_players=0.2, players_amount=100, player_elo_rating_rate=0.4, player_elo_rating_rate_MOV=0.4, task_elo_rating_rate=0.4, task_elo_rating_rate_MOV=0.4, history_for_ties_size=20, win_tie=0.5, tie_loss=0.0, expectation_factor=0.1, 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_best mutation strategy.

  • portion_of_top_players (float from (0, 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.

  • player_elo_rating_rate (non-negative float) – Constant used to calculate players’ rating update based on predicted victory odds and observed effect.

  • player_elo_rating_rate_MOV (non-negative float) – Constant used to calculate players’ rating update based on expected and observed relative function difference.

  • task_elo_rating_rate (non-negative float) – Constant used to calculate tasks’ rating update based on predicted victory odds and observed effect.

  • task_elo_rating_rate_MOV (non-negative float) – Constant used to calculate tasks’ rating update based on expected and observed relative function difference.

  • history_for_ties_size (positive int) – Function differences of previous history_for_ties_size will be recorded and used to determine win/tie/loss.

  • win_tie (float from [0,1]) – Whenever a positive new function difference is less than win_tie percentile of previous function differences, it is a tie. Otherwise - a win.

  • tie_loss (float from [0,1]) – Whenever a negative new function difference is bigger than tie_loss percentile of history, it is a tie. Otherwise - a loss.

  • expectation_factor (non-negative float) – Used to calculate expected relative function difference as (rating_difference * expectation_factor).

  • 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.

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=None, 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