culebra.trainer.ea.abc.CooperativeEA
class¶
- class CooperativeEA(solution_classes: Sequence[Type[Individual]], species: Sequence[Species], fitness_function: FitnessFunction, subtrainer_cls: Type[SinglePopEA], max_num_iters: int | None = None, custom_termination_func: Callable[[SinglePopEA], bool] | None = None, pop_sizes: int | Sequence[int] | None = None, crossover_funcs: Callable[[Individual, Individual], Tuple[Individual, Individual]] | Sequence[Callable[[Individual, Individual], Tuple[Individual, Individual]]] | None = None, mutation_funcs: Callable[[Individual, float], Tuple[Individual]] | Sequence[Callable[[Individual, float], Tuple[Individual]]] | None = None, selection_funcs: Callable[[List[Individual], int, Any], List[Individual]] | Sequence[Callable[[List[Individual], int, Any], List[Individual]]] | None = None, crossover_probs: float | Sequence[float] | None = None, mutation_probs: float | Sequence[float] | None = None, gene_ind_mutation_probs: float | Sequence[float] | None = None, selection_funcs_params: Dict[str, Any] | Sequence[Dict[str, Any]] | None = None, num_subtrainers: int | None = None, representation_size: int | None = None, representation_freq: int | None = None, representation_selection_func: Callable[[List[Individual], Any], Individual] | None = None, representation_selection_func_params: Dict[str, Any] | None = None, checkpoint_enable: bool | None = None, checkpoint_freq: int | None = None, checkpoint_filename: str | None = None, verbose: bool | None = None, random_seed: int | None = None, **subtrainer_params: Any)¶
Create a new trainer.
Each species is evolved in a different subpopulation.
- Parameters:
solution_classes (
Sequence
ofIndividual
subclasses) – The individual class for each species.fitness_function (
FitnessFunction
) – The training fitness functionsubtrainer_cls (Any subclass of
SinglePopEA
) – Single-species trainer class to handle the subpopulations.max_num_iters (
int
, optional) – Maximum number of iterations. If set toNone
,DEFAULT_MAX_NUM_ITERS
will be used. Defaults toNone
custom_termination_func (
Callable
, optional) – Custom termination criterion. If set toNone
, the default termination criterion is used. Defaults toNone
pop_sizes (
int
orSequence
ofint
, optional) – The population size for each subpopulation (species). If only a single value is provided, the same size will be used for all the subpopulations. Different sizes can be provided in aSequence
. All the sizes must be greater then zero. If set toNone
,DEFAULT_POP_SIZE
will be used. Defaults toNone
crossover_funcs (
Callable
orSequence
ofCallable
, optional) – The crossover function for each subpopulation (species). If only a single value is provided, the same function will be used for all the subpopulations. Different functions can be provided in aSequence
. If set toNone
, the solution_clscrossover()
method will be used. Defaults toNone
mutation_funcs (
Callable
orSequence
ofCallable
, optional) – The mutation function for each subpopulation (species). If only a single value is provided, the same function will be used for all the subpopulations. Different functions can be provided in aSequence
. If set toNone
, the solution_clsmutate()
method will be used. Defaults toNone
selection_funcs (
Callable
orSequence
ofCallable
, optional) – The selection function for each subpopulation (species). If only a single value is provided, the same function will be used for all the subpopulations. Different functions can be provided in aSequence
. If set toNone
,DEFAULT_SELECTION_FUNC
will be used. Defaults toNone
crossover_probs (
float
orSequence
offloat
, optional) – The crossover probability for each subpopulation (species). If only a single value is provided, the same probability will be used for all the subpopulations. Different probabilities can be provided in aSequence
. All the probabilities must be in (0, 1). If set toNone
,DEFAULT_CROSSOVER_PROB
will be used. Defaults toNone
mutation_probs (
float
orSequence
offloat
, optional) – The mutation probability for each subpopulation (species). If only a single value is provided, the same probability will be used for all the subpopulations. Different probabilities can be provided in aSequence
. All the probabilities must be in (0, 1). If set toNone
,DEFAULT_MUTATION_PROB
will be used. Defaults toNone
gene_ind_mutation_probs (
float
orSequence
offloat
, optional) – The gene independent mutation probability for each subpopulation (species). If only a single value is provided, the same probability will be used for all the subpopulations. Different probabilities can be provided in aSequence
. All the probabilities must be in (0, 1). If set toNone
,DEFAULT_GENE_IND_MUTATION_PROB
will be used. Defaults toNone
selection_funcs_params (
dict
orSequence
ofdict
, optional) – The parameters for the selection function of each subpopulation (species). If only a single value is provided, the same probability will be used for all the subpopulations. Different probabilities can be provided in aSequence
. If set toNone
,DEFAULT_SELECTION_FUNC_PARAMS
will be used. Defaults toNone
num_subtrainers (
int
, optional) – The number of subpopulations (species). If set toNone
, the number of species evolved by the trainer is will be used, otherwise it must match the number of species. Defaults toNone
representation_size (
int
, optional) – Number of representative individuals that will be sent to the other subpopulations. If set toNone
,DEFAULT_REPRESENTATION_SIZE
will be used. Defaults toNone
representation_freq (
int
, optional) – Number of iterations between representatives sendings. If set toNone
,DEFAULT_REPRESENTATION_FREQ
will be used. Defaults toNone
representation_selection_func (
Callable
, optional) – Policy function to choose the representatives from each subpopulation (species). If set toNone
,DEFAULT_REPRESENTATION_SELECTION_FUNC
will be used. Defaults toNone
representation_selection_func_params (
dict
, optional) – Parameters to obtain the representatives with the selection policy function. If set toNone
,DEFAULT_REPRESENTATION_SELECTION_FUNC_PARAMS
will be used. Defaults toNone
checkpoint_enable (
bool
, optional) – Enable/disable checkpoining. If set toNone
,DEFAULT_CHECKPOINT_ENABLE
will be used. Defaults toNone
checkpoint_freq (
int
, optional) – The checkpoint frequency. If set toNone
,DEFAULT_CHECKPOINT_FREQ
will be used. Defaults toNone
checkpoint_filename (
str
, optional) – The checkpoint file path. If set toNone
,DEFAULT_CHECKPOINT_FILENAME
will be used. Defaults toNone
verbose (
bool
, optional) – The verbosity. If set toNone
,__debug__
will be used. Defaults toNone
subtrainer_params (keyworded variable-length argument list) – Custom parameters for the subpopulations (species) trainer
- Raises:
TypeError – If any argument is not of the appropriate type
ValueError – If any argument has an incorrect value
Class attributes¶
- CooperativeEA.stats_names = ('Iter', 'Pop', 'NEvals')¶
Statistics calculated each iteration.
- CooperativeEA.objective_stats = {'Avg': <function mean>, 'Max': <function max>, 'Min': <function min>, 'Std': <function std>}¶
Statistics calculated for each objective.
Class methods¶
- classmethod CooperativeEA.load_pickle(filename: str) Base ¶
Load a pickled object from a file.
- Parameters:
filename (
str
) – The file name.- Raises:
TypeError – If filename is not a valid file name
ValueError – If the filename extension is not
PICKLE_FILE_EXTENSION
Properties¶
- property CooperativeEA.solution_classes: Sequence[Type[Solution]]¶
Get and set the solution classes.
- property CooperativeEA.fitness_function: FitnessFunction¶
Get and set the training fitness function.
- Getter:
Return the fitness function
- Setter:
Set a new fitness function
- Type:
- Raises:
TypeError – If set to a value which is not a fitness function
- property CooperativeEA.subtrainer_cls: Type[SinglePopEA]¶
Get and set the trainer class to handle the subpopulations.
Each subpopulation will be handled by a single-population evolutionary trainer.
- Getter:
Return the trainer class
- Setter:
Set new trainer class
- Type:
A
SinglePopEA
subclass- Raises:
TypeError – If set to a value which is not a
SinglePopEA
subclass
- property CooperativeEA.max_num_iters: int¶
Get and set the maximum number of iterations.
- Getter:
Return the current maximum number of iterations
- Setter:
Set a new value for the maximum number of iterations. If set to
None
, the default maximum number of iterations,DEFAULT_MAX_NUM_ITERS
, is chosen- Type:
- Raises:
TypeError – If set to a value which is not an integer
ValueError – If set to a value which is not a positive number
- property CooperativeEA.custom_termination_func: Callable[[Trainer], bool]¶
Get and set the custom termination criterion.
The custom termination criterion must be a function which receives the trainer as its unique argument and returns a boolean value,
True
if the search should terminate orFalse
otherwise.If more than one arguments are needed to define the termniation condition,
functools.partial()
can be used:from functools import partial def my_crit(trainer, max_iters): if trainer.current_iter < max_iters: return False return True trainer.custom_termination_func = partial(my_crit, max_iters=10)
- property CooperativeEA.pop_sizes: Sequence[int | None]¶
Get and set the population size for each subtrainer.
- Getter:
Return the current size of each subtrainer
- Setter:
Set a new size for each subtrainer. If only a single value is provided, the same size will be used for all the subtrainers. Different sizes can be provided in a
Sequence
. All the sizes must be greater then zero. If set toNone
,DEFAULT_POP_SIZE
is chosen- Type:
- Raises:
TypeError – If set to a value which is not an
int
or aSequence
ofint
ValueError – If any population size is not greater than zero
- property CooperativeEA.crossover_funcs: Sequence[Callable[[Individual, Individual], Tuple[Individual, Individual]] | None]¶
Get and set the crossover function for each subpopulation.
- Getter:
Return the current crossover functions
- Setter:
Set the new crossover functions. If only a single value is provided, the same function will be used for all the subpopulations. Different functions can be provided in a
Sequence
. If set toNone
, thecrossover()
method of the individual class evolved by the trainer is chosen- Type:
- Raises:
TypeError – If set to a value which is not
Callable
or aSequence
ofCallable
- property CooperativeEA.mutation_funcs: Sequence[Callable[[Individual, float], Tuple[Individual]] | None]¶
Get and set the mutation function for each subpopulation.
- Getter:
Return the current mutation functions
- Setter:
Set the new mutation functions. If only a single value is provided, the same function will be used for all the subpopulations. Different functions can be provided in a
Sequence
. If set toNone
, themutate()
method of the individual class evolved by the trainer is chosen- Type:
- Raises:
TypeError – If set to a value which is not
Callable
or aSequence
ofCallable
- property CooperativeEA.selection_funcs: Sequence[Callable[[List[Individual], int, Any], List[Individual]] | None]¶
Get and set the selection function for each subpopulation.
- Getter:
Return the current selection functions
- Setter:
Set the new selection functions. If only a single value is provided, the same function will be used for all the subpopulations. Different functions can be provided in a
Sequence
. If set toNone
,DEFAULT_SELECTION_FUNC
is chosen- Type:
- Raises:
TypeError – If set to a value which is not
Callable
or aSequence
ofCallable
- property CooperativeEA.crossover_probs: Sequence[float | None]¶
Get and set the crossover probability for each subpopulation.
- Getter:
Return the current crossover probabilities
- Setter:
Set the new crossover probabilities. If only a single value is provided, the same probability will be used for all the subpopulations. Different probabilities can be provided in a
Sequence
. All the probabilities must be in (0, 1). If set toNone
,DEFAULT_CROSSOVER_PROB
is chosen- Type:
- Raises:
TypeError – If set to a value which is not a real number or a
Sequence
of real numbersValueError – If any probability is not in (0, 1)
- property CooperativeEA.mutation_probs: Sequence[float | None]¶
Get and set the mutation probability for each subpopulation.
- Getter:
Return the current mutation probabilities
- Setter:
Set the new mutation probabilities. If only a single value is provided, the same probability will be used for all the subpopulations. Different probabilities can be provided in a
Sequence
. All the probabilities must be in (0, 1). If set toNone
,DEFAULT_MUTATION_PROB
is chosen- Type:
- Raises:
TypeError – If set to a value which is not a real number or a
Sequence
of real numbersValueError – If probabilities are not in (0, 1)
- property CooperativeEA.gene_ind_mutation_probs: Sequence[float | None]¶
Get and set the gene independent mutation probabilities.
- Getter:
Return the current gene independent mutation probability for each subpopulation
- Setter:
Set new values for the gene independent mutation probabilities. If only a single value is provided, the same probability will be used for all the subpopulations. Different probabilities can be provided in a
Sequence
. All the probabilities must be in (0, 1). If set toNone
,DEFAULT_GENE_IND_MUTATION_PROB
is chosen- Type:
- Raises:
TypeError – If set to a value which is not a real number or a
Sequence
of real numbersValueError – If probabilities are not in (0, 1)
- property CooperativeEA.selection_funcs_params: Sequence[Dict[str, Any] | None]¶
Get and set the parameters of the selection functions.
- Getter:
Return the current parameters for the selection function of each subpopulation
- Setter:
Set new parameters. If only a single value is provided, the same probability will be used for all the subpopulations. Different probabilities can be provided in a
Sequence
. If set toNone
,DEFAULT_SELECTION_FUNC_PARAMS
is chosen- Type:
- Raises:
- property CooperativeEA.num_subtrainers: int¶
Get and set the number of subtrainers.
- Getter:
Return the current number of subtrainers
- Setter:
Set a new value for the number of subtrainers. If set to
None
, the number of species evolved by the trainer is chosen, otherwise it must match the number of species- Type:
- Raises:
TypeError – If set to a value which is not an integer
ValueError – If set to a value which is different of the number of species
- property CooperativeEA.representation_size: int¶
Get and set the representation size.
The representation size is the number of representatives sent to the other subtrainers
- Getter:
Return the current representation size
- Setter:
Set the new representation size. If set to
None
,DEFAULT_REPRESENTATION_SIZE
is chosen- Type:
- Raises:
TypeError – If set to a value which is not an integer
ValueError – If set to a value which is not positive
- property CooperativeEA.representation_freq: int¶
Get and set the number of iterations between representatives sendings.
- Getter:
Return the current frequency
- Setter:
Set a new value for the frequency. If set to
None
,DEFAULT_REPRESENTATION_FREQ
is chosen- Type:
- Raises:
TypeError – If set to a value which is not an integer
ValueError – If set to a value which is not a positive number
- property CooperativeEA.representation_topology_func: Callable[[int, int, Any], List[int]]¶
Get the representation topology function.
- Type:
- property CooperativeEA.representation_topology_func_params: Dict[str, Any]¶
Get the parameters of the representation topology function.
- Type:
- property CooperativeEA.representation_selection_func: Callable[[List[Solution], Any], Solution]¶
Get and set the representation selection policy function.
The representation selection policy func chooses which solutions are selected as representatives of each subtrainer.
- Getter:
Return the representation selection policy function
- Setter:
Set new representation selection policy function. If set to
None
,DEFAULT_REPRESENTATION_SELECTION_FUNC
is chosen- Type:
- Raises:
TypeError – If set to a value which is not callable
- property CooperativeEA.representation_selection_func_params: Dict[str, Any]¶
Get and set the parameters of the representation selection function.
- Getter:
Return the current parameters for the representation selection policy function
- Setter:
Set new parameters. If set to
None
,DEFAULT_REPRESENTATION_SELECTION_FUNC_PARAMS
is chosen- Type:
- Raises:
- property CooperativeEA.checkpoint_freq: int¶
Get and set the checkpoint frequency.
- Getter:
Return the checkpoint frequency
- Setter:
Set a value for the checkpoint frequency. If set to
None
,DEFAULT_CHECKPOINT_FREQ
is chosen- Type:
- Raises:
TypeError – If set to a value which is not an integer
ValueError – If set to a value which is not a positive number
- property CooperativeEA.checkpoint_filename: str¶
Get and set the checkpoint file path.
- Getter:
Return the checkpoint file path
- Setter:
Set a new value for the checkpoint file path. If set to
None
,DEFAULT_CHECKPOINT_FILENAME
is chosen- Type:
- Raises:
TypeError – If set to a value which is not a a valid file name
ValueError – If set to a value whose extension is not
PICKLE_FILE_EXTENSION
- property CooperativeEA.random_seed: int¶
Get and set the initial random seed used by this trainer.
- Getter:
Return the seed
- Setter:
Set a new value for the random seed
- Type:
- property CooperativeEA.logbook: Logbook | None¶
Get the training logbook.
Return a logbook with the statistics of the search or
None
if the search has not been done yet.- Type:
- property CooperativeEA.num_evals: int | None¶
Get the number of evaluations performed while training.
Return the number of evaluations or
None
if the search has not been done yet.- Type:
- property CooperativeEA.runtime: float | None¶
Get the training runtime.
Return the training runtime or
None
if the search has not been done yet.- Type:
- property CooperativeEA.index: int¶
Get and set the trainer index.
The trainer index is only used by distributed trainers. For the rest of trainers
DEFAULT_INDEX
is used.- Getter:
Return the trainer index
- Setter:
Set a new value for trainer index. If set to
None
,DEFAULT_INDEX
is chosen- Type:
- Raises:
TypeError – If set to a value which is not an integer
ValueError – If set to a value which is a negative number
- property CooperativeEA.container: Trainer | None¶
Get and set the container of this trainer.
The trainer container is only used by distributed trainers. For the rest of trainers defaults to
None
.
- property CooperativeEA.representatives: Sequence[Sequence[Solution | None]] | None¶
Return the representatives of all the species.
- property CooperativeEA.subtrainer_params: Dict[str, Any]¶
Get and set the custom parameters of the subtrainers.
- property CooperativeEA.subtrainer_checkpoint_filenames: Generator[str, None, None]¶
Checkpoint file name of all the subtrainers.
- property CooperativeEA.subtrainers: List[SingleSpeciesTrainer] | None¶
Return the subtrainers.
One single-species trainer for each subtrainer
- Type:
list
ofSingleSpeciesTrainer
trainers
Private properties¶
Static methods¶
- static CooperativeEA.receive_representatives(subtrainer) None ¶
Receive representative individuals.
- Parameters:
subtrainer (
SingleSpeciesTrainer
) – The subtrainer receiving representatives
- static CooperativeEA.send_representatives(subtrainer) None ¶
Send representatives.
- Parameters:
subtrainer (
SingleSpeciesTrainer
) – The sender subtrainer
Private static methods¶
- static CooperativeEA._init_subtrainer_representatives(subtrainer, solution_classes, species, representation_size)¶
Init the representatives of the other species for a subtrainer.
This method is used to override dynamically the
_init_representatives()
of all the subtrainers, when they are generated with the_generate_subtrainers()
method, to let them initialize the list of representative individuals of the other species- Parameters:
subtrainer (
SingleSpeciesTrainer
) – The subtrainer. The representatives from the remaining subtrainers will be initialized for this subtrainersolution_classes (
Sequence
ofSolution
subclasses) – The individual class for each species.species (
Sequence
ofSpecies
) – The species to be evolved by this trainerrepresentation_size (
int
) – Number of representative individuals generated for each species
Methods¶
- CooperativeEA.save_pickle(filename: str) None ¶
Pickle this object and save it to a file.
- Parameters:
filename (
str
) – The file name.- Raises:
TypeError – If filename is not a valid file name
ValueError – If the filename extension is not
PICKLE_FILE_EXTENSION
- CooperativeEA.reset() None ¶
Reset the trainer.
Delete the state of the trainer (with
_reset_state()
) and also all the internal data structures needed to perform the search (with_reset_internals()
).This method should be invoqued each time a hyper parameter is modified.
- CooperativeEA.evaluate(sol: Solution, fitness_func: FitnessFunction | None = None, index: int | None = None, representatives: Sequence[Sequence[Solution | None]] | None = None) None ¶
Evaluate one solution.
Its fitness will be modified according with the fitness function results. Besides, if called during training, the number of evaluations will be also updated.
- Parameters:
sol (
Solution
) – The solutionfitness_func (
FitnessFunction
, optional) – The fitness function. If omitted, the default training fitness function (fitness_function
) is usedindex (
int
, optional) – Index where sol should be inserted in the representatives sequence to form a complete solution for the problem. If omitted,index
is usedrepresentatives (
Sequence
ofSequence
ofSolution
orNone
, optional) – Sequence of representatives of other species orNone
(if no representatives are needed to evaluate sol). If omitted, the current value ofrepresentatives
is used
- CooperativeEA.best_solutions() Sequence[HallOfFame] ¶
Get the best individuals found for each species.
- Returns:
A sequence containing
HallOfFame
of individuals. One hof for each species- Return type:
list
ofHallOfFame
- CooperativeEA.best_representatives() List[List[Solution]] | None ¶
Return a list of representatives from each species.
- CooperativeEA.train(state_proxy: DictProxy | None = None) None ¶
Perform the training process.
- Parameters:
state_proxy (
DictProxy
, optional) – Dictionary proxy to copy the output state of the trainer procedure. Only used if train is executed within amultiprocessing.Process
. Defaults toNone
- CooperativeEA.test(best_found: Sequence[HallOfFame], fitness_func: FitnessFunction | None = None, representatives: Sequence[Sequence[Solution]] | None = None) None ¶
Apply the test fitness function to the solutions found.
Update the solutions in best_found with their test fitness.
- Parameters:
best_found (
Sequence
ofHallOfFame
) – The best solutions found for each species. OneHallOfFame
for each speciesfitness_func (
FitnessFunction
, optional) – Fitness function used to evaluate the final solutions. If ommited, the default training fitness function (fitness_function
) will be usedrepresentatives (
Sequence
ofSequence
ofSolution
) – Sequence of representatives of other species orNone
(if no representatives are needed). If omitted, the current value ofrepresentatives
is used
- Raises:
TypeError – If any parameter has a wrong type
ValueError – If any parameter has an invalid value.
Private methods¶
- CooperativeEA._generate_subtrainers() None ¶
Generate the subpopulation trainers.
Also assign an
index
and acontainer
to each subpopulationSinglePopEA
trainer, change the subpopulation trainers’checkpoint_filename
according to the container checkpointing file name and each subpopulation index.Finally, the
_preprocess_iteration()
and_postprocess_iteration()
methods of thesubtrainer_cls
class are dynamically overridden, in order to allow individuals exchange between subpopulation trainers, if necessary- Raises:
RuntimeError – If the length of any properties sequence does not match the number of subpopulations.
- CooperativeEA._get_state() Dict[str, Any] ¶
Return the state of this trainer.
Default state is a dictionary composed of the values of the
logbook
,num_evals
,runtime
,current_iter
, andrepresentatives
trainer properties, along with a private boolean attribute that informs if the search has finished and also the states of therandom
andnumpy.random
modules.If subclasses use any more properties to keep their state, the
_get_state()
and_set_state()
methods must be overridden to take into account such properties.- Type:
- CooperativeEA._set_state(state: Dict[str, Any]) None ¶
Set the state of this trainer.
If subclasses use any more properties to keep their state, the
_get_state()
and_set_state()
methods must be overridden to take into account such properties.- Parameters:
state (
dict
) – The last loaded state
- CooperativeEA._save_state() None ¶
Save the state at a new checkpoint.
- Raises:
Exception – If the checkpoint file can’t be written
- CooperativeEA._load_state() None ¶
Load the state of the last checkpoint.
- Raises:
Exception – If the checkpoint file can’t be loaded
- CooperativeEA._new_state() None ¶
Generate a new trainer state.
Overridden to set the logbook to
None
, since the final logbook will be generated from the subtrainers’ logbook, once the trainer has finished.
- CooperativeEA._init_state() None ¶
Init the trainer state.
If there is any checkpoint file, the state is initialized from it with the
_load_state()
method. Otherwise a new initial state is generated with the_new_state()
method.
- CooperativeEA._reset_state() None ¶
Reset the trainer state.
If subclasses overwrite the
_new_state()
method to add any new property to keep their state, this method should also be overridden to reset the full state of the trainer.
- CooperativeEA._init_internals() None ¶
Set up the trainer internal data structures to start searching.
Overridden to create the subtrainers and communication queues.
- CooperativeEA._reset_internals() None ¶
Reset the internal structures of the trainer.
Overridden to reset the subtrainers and communication queues.
- CooperativeEA._init_search() None ¶
Init the search process.
Initialize the state of the trainer (with
_init_state()
) and all the internal data structures needed (with_init_internals()
) to perform the search.
- CooperativeEA._search() None ¶
Apply the search algorithm.
Execute the trainer until the termination condition is met. Each iteration is composed by the following steps:
- CooperativeEA._finish_search() None ¶
Finish the search process.
This method is called after the search has finished. It can be overridden to perform any treatment of the solutions found.
- CooperativeEA._start_iteration() None ¶
Start an iteration.
Prepare the iteration metrics (number of evaluations, execution time) before each iteration is run.
- CooperativeEA._preprocess_iteration() None ¶
Preprocess before doing the iteration.
Subclasses should override this method to make any preprocessment before performing an iteration.
- abstract CooperativeEA._do_iteration() None ¶
Implement an iteration of the search process.
This abstract method should be implemented by subclasses in order to implement the desired behavior.
- CooperativeEA._postprocess_iteration() None ¶
Postprocess after doing the iteration.
Subclasses should override this method to make any postprocessment after performing an iteration.
- CooperativeEA._finish_iteration() None ¶
Finish an iteration.
Finish the iteration metrics (number of evaluations, execution time) after each iteration is run.
- CooperativeEA._do_iteration_stats() None ¶
Perform the iteration stats.
This method should be implemented by subclasses in order to perform the adequate stats.
- CooperativeEA._default_termination_func() bool ¶
Set the default termination criterion.
Return
True
ifmax_num_iters
iterations have been run.
- CooperativeEA._termination_criterion() bool ¶
Return true if the search should terminate.
Returns
True
if either the default termination criterion or a custom termination criterion is met. The default termination criterion is implemented by the_default_termination_func()
method. Another custom termination criterion can be set withcustom_termination_func
method.
- CooperativeEA._init_representatives() None ¶
Init the representatives of the other species.
Only used for cooperative approaches, which need representatives of all the species to form a complete solution for the problem. Cooperative subclasses of the
Trainer
class should override this method to get the representatives of the other species initialized.