Termination

  1. NumGenerations

  2. MoleculePresent

  3. FitnessPlateau

  4. AnyTerminator

  5. AllTerminators

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 return True.

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 all Terminator objects in Terminators 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 any Terminator in Terminators 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 the top_members have not changed over the last num_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 if mol 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 if mol is in progress.

Parameters

progress (Population) – A population where every generation is a subpopulation.

Returns

True if mol 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 if num_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 and False otherwise.

Return type

bool