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.TerminatorChecks if all
Terminatorobjects returnTrue.Methods
terminate(self, progress)Checks to see if all exit conditions have been satisfied.
-
__init__(self, *Terminators)¶ Initialize a
AllTerminatorinstance.- Parameters
*Terminators (
Terminator) –Terminatorobjects 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
Trueif allTerminatorobjects inTerminatorshave satisfied its exit condition.- Return type
bool
-
-
class
AnyTerminator(*Terminators)¶ Bases:
stk.calculators.ea.terminators.TerminatorChecks if any
Terminatorhas satisfied its exit condition.Methods
terminate(self, progress)Check to see if any exit condition has been satisfied.
-
__init__(self, *Terminators)¶ Initialize a
AnyTerminatorinstance.- Parameters
*Terminators (
Terminator) –Terminatorobjects 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
Trueif anyTerminatorinTerminatorshas satisfied its exit condition.- Return type
bool
-
-
class
FitnessPlateau(num_generations, top_members=1)¶ Bases:
stk.calculators.ea.terminators.TerminatorChecks 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
FitnessPlateauinstance.- 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
Trueif thetop_membershave not changed over the lastnum_gensgenerations.- Return type
bool
-
-
class
MoleculePresent(mol)¶ Bases:
stk.calculators.ea.terminators.TerminatorStops the EA if a specific molecule has been found.
Methods
terminate(self, progress)Return
Trueifmolis in progress.-
__init__(self, mol)¶ Initialize a
MoleculePresentinstance.- Parameters
mol (
Molecule) – A molecule which if present in any of the EA’s generations causes it to stop running.
-
terminate(self, progress)¶ Return
Trueifmolis in progress.- Parameters
progress (
Population) – A population where every generation is a subpopulation.- Returns
Trueifmolin progress,Falseotherwise.- Return type
bool
-
-
class
NumGenerations(num_generations)¶ Bases:
stk.calculators.ea.terminators.TerminatorStop 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
NumGenerationsinstance.- 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
Trueifnum_generationsor more has passed.
-
-
class
Terminator¶ Bases:
objectChecks 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
Trueif the EA should stop andFalseotherwise.- Return type
bool
-