Termination¶
Terminator
objects check to see if an exit condition for the
EA has been fulfilled.
Making New Terminators¶
A new Terminator
class should inherit Terminator
and
define an terminate()
method, which takes a progress
population as its only argument and returns True
or False
depending on if an exit condition has been satisfied. The progress
population is a Population
instance which holds each EA
generation as a subpopulation.
-
class
AllTerminators
(*Terminators)¶ Bases:
stk.calculators.ea.terminators.Terminator
Checks if all
Terminator
objects returnTrue
.Methods
terminate
(self, progress)Checks to see if all exit conditions have been satisfied.
-
__init__
(self, *Terminators)¶ Initialize a
AllTerminator
instance.- Parameters
*Terminators (
Terminator
) –Terminator
objects which are checked to see if their exit conditions have been satisfied.
-
terminate
(self, progress)¶ Checks to see if all exit conditions have been satisfied.
- Parameters
progress (
Population
) – A population where every generation is a subpopulation.- Returns
True
if allTerminator
objects inTerminators
have satisfied its exit condition.- Return type
bool
-
-
class
AnyTerminator
(*Terminators)¶ Bases:
stk.calculators.ea.terminators.Terminator
Checks if any
Terminator
has satisfied its exit condition.Methods
terminate
(self, progress)Check to see if any exit condition has been satisfied.
-
__init__
(self, *Terminators)¶ Initialize a
AnyTerminator
instance.- Parameters
*Terminators (
Terminator
) –Terminator
objects which are checked to see if their exit conditions have been satisfied.
-
terminate
(self, progress)¶ Check to see if any exit condition has been satisfied.
- Parameters
progress (
Population
) – A population where every generation is a subpopulation.- Returns
True
if anyTerminator
inTerminators
has satisfied its exit condition.- Return type
bool
-
-
class
FitnessPlateau
(num_generations, top_members=1)¶ Bases:
stk.calculators.ea.terminators.Terminator
Checks if the fittest molecules remain the same.
Methods
terminate
(self, progress)Check if the fittest molecules changed between generations.
-
__init__
(self, num_generations, top_members=1)¶ Initialize a
FitnessPlateau
instance.- Parameters
num_generations (
int
) – Number of generations in which the fittest molecules did not change.top_members (
int
, optional) – The number of fittest molecules which are checked. This number needs to be smaller than the population size.
-
terminate
(self, progress)¶ Check if the fittest molecules changed between generations.
- Parameters
progress (
Population
) – A population where every generation is a subpopulation.- Returns
True
if thetop_members
have not changed over the lastnum_gens
generations.- Return type
bool
-
-
class
MoleculePresent
(mol)¶ Bases:
stk.calculators.ea.terminators.Terminator
Stops the EA if a specific molecule has been found.
Methods
terminate
(self, progress)Return
True
ifmol
is in progress.-
__init__
(self, mol)¶ Initialize a
MoleculePresent
instance.- Parameters
mol (
Molecule
) – A molecule which if present in any of the EA’s generations causes it to stop running.
-
terminate
(self, progress)¶ Return
True
ifmol
is in progress.- Parameters
progress (
Population
) – A population where every generation is a subpopulation.- Returns
True
ifmol
in progress,False
otherwise.- Return type
bool
-
-
class
NumGenerations
(num_generations)¶ Bases:
stk.calculators.ea.terminators.Terminator
Stop the EA after a certain number of generations.
Methods
terminate
(self, progress)Check if a number of generations has passed.
-
__init__
(self, num_generations)¶ Initialize a
NumGenerations
instance.- Parameters
num_generations (
int
) – The number of generations after which the EA should stop.
-
terminate
(self, progress)¶ Check if a number of generations has passed.
- Parameters
progress (
Population
) – A population where every generation is a subpopulation.- Returns
- Return type
True
ifnum_generations
or more has passed.
-
-
class
Terminator
¶ Bases:
object
Checks if the exit criterion for the EA has been satisfied.
Methods
terminate
(self, progress)Check to see the the EA should stop.
-
__init__
(self, /, *args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
terminate
(self, progress)¶ Check to see the the EA should stop.
- Parameters
progress (
Population
) – A population where every generation is a subpopulation.- Returns
True
if the EA should stop andFalse
otherwise.- Return type
bool
-