stk.Worst
- class stk.Worst(num_batches=None, batch_size=1, duplicate_molecules=True, duplicate_batches=True, key_maker=Inchi(), fitness_modifier=<function Worst.<lambda>>)[source]
Bases:
Selector[T]Selects batches of molecules, lowest fitness value first.
Examples
Yielding Batches Holding Multiple Molecules
Select the worst 5 batches of size 3
import stk worst = stk.Worst(num_batches=5, batch_size=3) population = { stk.MoleculeRecord( topology_graph=stk.polymer.Linear( building_blocks=[ stk.BuildingBlock('BrCCBr', stk.BromoFactory()), ], repeating_unit='A', num_repeating_units=2, ), ): i for i in range(10) } for batch in worst.select(population): # Do stuff with batch. pass
- Parameters:
num_batches (int | None) – The number of batches to yield. If
Nonethen yielding will continue forever or until the generator is exhausted, whichever comes first.batch_size (int) – The number of molecules yielded at once.
duplicate_molecules (bool) – If
Truethe same molecule can be yielded in more than one batch.duplicate_batches (bool) – If
Truethe same batch can be yielded more than once. Duplicate batches can occur if the same molecule is found multiple times in a population.key_maker (MoleculeKeyMaker) – Used to get the keys of molecules, which are used to determine if two molecules are duplicates of each other.
fitness_modifier (Callable[[dict[T, float]], dict[T, float]]) – Takes the population on which
select()is called and returns adict, which maps records in the population to the fitness values theSelectorshould use. IfNone, the regular fitness values of the records are used.
Methods
Yield batches of molecule records from population.
- select(population, included_batches=None, excluded_batches=None)
Yield batches of molecule records from population.
- Parameters:
population (dict[T, float]) – A collection of molecules from which batches are selected.
included_batches (set[BatchKey] | None) – The identity keys of batches which are allowed to be yielded, if
Noneall batches can be yielded. If notNoneonly batches included_batches will be yielded.excluded_batches (set[BatchKey] | None) – The identity keys of batches which are not allowed to be yielded. If
None, no batch is forbidden from being yielded.
- Yields:
A batch of selected molecule records.
- Return type: