Normalizer Sequence

class NormalizerSequence(fitness_normalizers)[source]

Bases: stk.ea.fitness_normalizers.fitness_normalizer.FitnessNormalizer

Applies other normalizers in sequence.

Examples

Using Multiple Fitness Normalizers

You want to apply multiple fitness normalizations in sequence, for example, by first using DivideByMean, followed by Sum

import stk
import numpy as np

building_block = stk.BuildingBlock(
    smiles='BrCCBr',
    functional_groups=[stk.BromoFactory()],
)

population = (
    stk.MoleculeRecord(
        topology_graph=stk.polymer.Linear(
            building_blocks=(building_block, ),
            repeating_unit='A',
            num_repeating_units=2,
        ),
    ).with_fitness_value(
        fitness_value=(1, 100, 1000),
        normalized=False,
    ),
)

# Create the normalizer.
normalizer = stk.NormalizerSequence(
    fitness_normalizers=(
        stk.DivideByMean(),
        stk.Sum(),
    ),
)
normalized_population = normalizer.normalize(population)
normalized_record, = normalized_population
assert normalized_record.get_fitness_value() == 3

Methods

normalize(population)

Normalize the fitness values in population.

__init__(fitness_normalizers)[source]

Initialize a NormalizerSequence.

Parameters

fitness_normalizers (iterable) – The FitnessNormalizer instances which should be used in sequence.

normalize(population)[source]

Normalize the fitness values in population.

Parameters

population (tuple of MoleculeRecord) – The molecules which need to have their fitness values normalized.

Yields

MoleculeRecord – A record with a normalized fitness value.