示例#1
0
fitness_calculator = stk.PropertyVector(
    pore_diameter,
    window_std,
    sa_score,
)


def valid_fitness(population, mol):
    return None not in population.get_fitness_values()[mol]


fitness_normalizer = stk.Sequence(
    stk.Power([1, -1, 1], filter=valid_fitness),
    stk.DivideByMean(filter=valid_fitness),
    stk.Multiply([1.0, 1.0, 10.0], filter=valid_fitness),
    stk.Sum(filter=valid_fitness),
    stk.ReplaceFitness(
        replacement_fn=lambda population: min(f for _, f in population.
                                              get_fitness_values().items()
                                              if not isinstance(f, list)) / 2,
        filter=lambda p, m: isinstance(p.get_fitness_values()[m], list),
    ))

# #####################################################################
# Exit condition.
# #####################################################################

terminator = stk.NumGenerations(60)

# #####################################################################
    elif isinstance(f, list):
        return None not in population.get_fitness_values()[mol]

    else:
        return False


# Minimize synthetic accessibility and asymmetry.
# Maximise pore volume and window size.
fitness_normalizer = stk.TryCatch(
    stk.Sequence(
        save_fitness,
        stk.Power([1, 1, -1, -1], filter=valid_fitness),
        stk.DivideByMean(filter=valid_fitness),
        stk.Multiply([0, 0, 0, 0], filter=valid_fitness),
        stk.Sum(filter=valid_fitness),
        # Replace all fitness values that are lists or None with
        # a small value.
        stk.ReplaceFitness(replacement_fn=lambda population: 1e-8,
                           filter=lambda p, m: isinstance(
                               p.get_fitness_values()[m],
                               (list, type(None)),
                           )),
    ),
    stk.ReplaceFitness(replacement_fn=lambda population: 1e-8, ))

# #####################################################################
# Exit condition.
# #####################################################################
    elif isinstance(f, list):
        return None not in population.get_fitness_values()[mol]

    else:
        return False


# Minimize synthetic accessibility and asymmetry.
# Maximise pore volume and window size.
fitness_normalizer = stk.TryCatch(
    stk.Sequence(
        save_fitness,
        stk.Power([1, 1, -1, -1], filter=valid_fitness),
        stk.DivideByMean(filter=valid_fitness),
        stk.Multiply([10, 0, 5, 5], filter=valid_fitness),
        stk.Sum(filter=valid_fitness),
        # Replace all fitness values that are lists or None with
        # a small value.
        stk.ReplaceFitness(
            replacement_fn=lambda population: 1e-8,
            filter=lambda p, m:
                isinstance(
                    p.get_fitness_values()[m],
                    (list, type(None)),
                )
        ),
    ),
    stk.ReplaceFitness(replacement_fn=lambda population: 1e-8,)
)
    elif isinstance(f, list):
        return None not in population.get_fitness_values()[mol]

    else:
        return False


# Minimize synthetic accessibility and asymmetry.
# Maximise pore volume and window size.
fitness_normalizer = stk.TryCatch(
    stk.Sequence(
        save_fitness,
        stk.Power([1, 1, -1, -1], filter=valid_fitness),
        stk.DivideByMean(filter=valid_fitness),
        stk.Multiply([5, 1, 10, 5], filter=valid_fitness),
        stk.Sum(filter=valid_fitness),
        # Replace all fitness values that are lists or None with
        # a small value.
        stk.ReplaceFitness(replacement_fn=lambda population: 1e-8,
                           filter=lambda p, m: isinstance(
                               p.get_fitness_values()[m],
                               (list, type(None)),
                           )),
    ),
    stk.ReplaceFitness(replacement_fn=lambda population: 1e-8, ))

# #####################################################################
# Exit condition.
# #####################################################################