flexs.baselines.explorers.genetic_algorithm

Define a baseline genetic algorithm implementation.

class flexs.baselines.explorers.genetic_algorithm.GeneticAlgorithm(model, rounds, starting_sequence, sequences_batch_size, model_queries_per_batch, alphabet, population_size, parent_selection_strategy, children_proportion, log_file=None, parent_selection_proportion=None, beta=None, seed=None)[source]

Bases: flexs.explorer.Explorer

A genetic algorithm explorer with single point mutations and recombination.

Based on the parent_selection_strategy, this class implements one of three genetic algorithms:

  1. If parent_selection_strategy == ‘top-k’, we have a traditional genetic algorithm where the top-k scoring sequences in the population become parents.

  2. If parent_selection_strategy == ‘wright-fisher’, we have a genetic algorithm based off of the Wright-Fisher model of evolution, where members of the population become parents with a probability exponential to their fitness (softmax the scores then sample).

propose_sequences(measured_sequences)[source]

Propose top sequences_batch_size sequences for evaluation.

Return type

Tuple[ndarray, ndarray]