Finch is a Python framework for implementing evolutionary algorithms. It provides a modular approach to building and experimenting with various evolutionary computation techniques.
GenePool: Generates initial populations
Individual: Represents a single solution in the population
Layer: Defines genetic operators
Environment: Manages the evolution process
Competition: Allows comparing multiple evolutionary strategies
import Finch.layers as layers
from Finch.selectors import *
from Finch.generic import *
def fitness_function(individual):
return sum(individual.item)
gene_pool = layers.float_arrays.FloatPool(ranges=[[-5, 5]] * 10, length=10, fitness_function=fitness_function)
mutation_selection = RandomSelection(percent_to_select=.1)
crossover_selection = RandomSelection(amount_to_select=2)
# Set up layers
layers = [
layers.universal_layers.Populate(population=500, gene_pool=gene_pool),
layers.array_layers.ParentNPoint(selection_function=crossover_selection.select, families=4, children=4),
layers.float_arrays.GaussianMutation(mutation_rate=0.1, sigma=0.5, selection_function=mutation_selection.select),
layers.universal_layers.SortByFitness(),
layers.universal_layers.CapPopulation(1000),
]
env = Environment(layers)
env.compile()
env.evolve(generations=1000)
print(env.best_ever.item)
env.plot()
pip install finch-genetics
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.