Filter Batches
- class FilterBatches(filter, selector)[source]
Bases:
Selector
Allows a
Selector
to select only some batches.Examples
Using a Selection Algorithm on a Subset of Batches
You only want the
Best
10 batches to participate inRoulette
import stk # Select the 10 best batches first, and then run roulette on # those. selector = stk.FilterBatches( filter=stk.Best(10), selector=stk.Roulette(7), ) population = tuple( stk.MoleculeRecord( topology_graph=stk.polymer.Linear( building_blocks=( stk.BuildingBlock( smiles='BrCCBr', functional_groups=[stk.BromoFactory()], ), ), repeating_unit='A', num_repeating_units=2, ), ).with_fitness_value(i) for i in range(100) ) for batch in selector.select(population): # Do stuff with batch. It is one of the 10 best batches and # was selected using roulette selection. pass
Methods
select
(population[, included_batches, ...])Yield batches of molecule records from population.
- __init__(filter, selector)[source]
Initialize a
FilterBatches
instance.
- select(population, included_batches=None, excluded_batches=None)[source]
Yield batches of molecule records from population.
- Parameters:
population (
tuple
ofMoleculeRecord
) – A collection of molecules from which batches are selected.included_batches (
set
, optional) – The identity keys of batches which are allowed to be yielded, ifNone
all batches can be yielded. If notNone
only batches included_batches will be yielded.excluded_batches (class:set, optional) – The identity keys of batches which are not allowed to be yielded. If
None
, no batch is forbidden from being yielded.
- Yields:
Batch
ofMoleculeRecord
– A batch of selected molecule records.