Steady-State (Asynchronous) Algorithm#
- class SteadyStateEA(search_space, n_iterations: int, population_size: int, selection_size: int, evaluation, save_dir, models=None, pop_path=None, crossover=<dragon.search_operators.crossover.DAGTwoPoint object>, verbose=False, **args)[source]
Bases:
SearchAlgorithm
Search algorithm implementing the steady-state (asynchronous) search algorithm inheriting from the SearchAlgorithm class. It implements a select_next_configuration and a process_evaluated_configuration methods, specific to the evolutionary algorithm.
- Parameters:
search_space (Variable) – Variable containing all the design choices from the search space. It should implement a random method and a neighbor one.
n_iterations (int) – Number of iterations.
population_size (int) – Size of the population.
selection_size (int:) – Size of the tournament selection.
crossover (function, default=DAGTwoPoint()) – Crossover function to use.
evaluation (function) – Performance evaluation function. Takes as argument a set of configuration and the unique index of this configuration. Returns the performance and the model built.
save_dir (str) – Path towards saving directory. If not empty, the content will be replaced.
models (list, default=None) – List of configurations that should be included into the initial population.
pop_path (str, default=None) – Path towards a directory containing an former evaluation that we aim to continue.
verbose (bool, default=False) – Verbose boolean.
- selection_size
Size of the tournament selection.
- Type:
int:
- crossover
Crossover function to use.
- Type:
function, default=DAGTwoPoint()
- sent
Dictionary containing the configurations that are currently evaluated and thus are temporarly removed from the population.
- Type:
dict, default={}
- search_space
Variable containing all the design choices from the search space. It should implement a random method and a neighbor one if necessary.
- Type:
Variable
- n_iterations
Number of iterations.
- Type:
int
- population_size
Size of the randomly initialized population.
- Type:
int
- evaluation
Performance evaluation function. Takes as argument a set of configuration and the unique index of this configuration. Returns the performance and the model built.
- Type:
function
- save_dir
Path towards saving directory. If not empty, the content will be replaced.
- Type:
str
- models
List of configurations that should be included into the initial population.
- Type:
list, default=None
- pop_path
Path towards a directory containing an former evaluation that we aim to continue.
- Type:
str, default=None
- verbose
Verbose boolean.
- Type:
bool, default=False
- run
Run function to use: MPI (run_mpi) or not (run_no_mpi).
- Type:
function
- set_mpi
Dictionary containing the MPI parameters.
- Type:
dict
- storage
Dictionary storing the configurations from the population.
- Type:
dict, default={}
- min_loss
Current minimum loss found.
- Type:
float, default=np.min
Example
>>> from dragon.search_space.base_variables import ArrayVar >>> from dragon.search_operators.base_neighborhoods import ArrayInterval >>> from dragon.search_algorithm.ssea import SteadyStateEA >>> search_space = ArrayVar(dag, label="Search Space", neighbor=ArrayInterval()) >>> search_algorithm = SteadyStateEA(search_space, save_dir="save/test_ssea", n_iterations=20, population_size=5, selection_size=3, evaluation=loss_function) >>> search_algorithm.run()
- select_next_configurations()[source]
Defines a selection strategy for SSEA. Uses tournament selection of size self.selection_size to select two parent configurations. Creates two offsprings by mutating (through the neighbor attribute of the configuration) and with the crossover function.
- Returns:
[self.K-1, self.K] – List containing the indexes of the two offsprings.
- Return type:
list
- process_evaluated_configuration(idx, loss)[source]
Determines if the configuration should be added to the population or not by calling self.replace_worst_individual(idx, loss).
- Parameters:
idx (int) – Index of the configuration.
loss (float) – Loss of the evaluation.
- Returns:
delete (True) – Boolean indicating if the configuration extra-information should be deleted. In SSEA, only extra-information of the best model are kept.
row_pop (dict) – Dictionary containing evaluation information to be saved within a .csv file called computation_file.csv.
loss (float) – Loss of the configuration.
- replace_worst_individual(idx, loss)[source]
replace_worst_individualidx, loss) Determines if the configuration is better than the worst one from the population. If this is the case, removes the worst one from the population and returns True. Else, returns False.
- Parameters:
idx (int) – Index of the configuration.
loss (float) – Loss of the evaluation.
- Returns:
add – Boolean indicating if the configuration should be added to the population.
- Return type:
boolean