Remove Batches

class RemoveBatches(remover, selector)[source]

Bases: Selector

Prevents a Selector from selecting some batches.

Examples

Removing Batches From Selection

You want to use Roulette selection on all but the 5 Worst batches

import stk

selector = stk.RemoveBatches(
    remover=stk.Worst(5),
    selector=stk.Roulette(20),
)
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 was selected with roulette
    # selection and is not one of the worst 5 batches.
    pass

Methods

select(population[, included_batches, ...])

Yield batches of molecule records from population.

__init__(remover, selector)[source]

Initialize a RemoveBatches instance.

Parameters:
  • remover (Selector) – Selects batches of molecules, which cannot be yielded by selector.

  • selector (Selector) – Selects batches of molecules, except those selected by remover.

select(population, included_batches=None, excluded_batches=None)[source]

Yield batches of molecule records from population.

Parameters:
  • population (tuple of MoleculeRecord) – A collection of molecules from which batches are selected.

  • included_batches (set, optional) – The identity keys of batches which are allowed to be yielded, if None all batches can be yielded. If not None 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 of MoleculeRecord – A batch of selected molecule records.