Skip to main content

A flexible framework for evolutionary algorithms in Python

Project description

Finch: Evolutionary Algorithm Framework

Finch is a Python framework for implementing evolutionary algorithms. It provides a modular approach to building and experimenting with various evolutionary computation techniques.

Key Features

  • Modular design with customizable components
  • Support for different types of genes (float arrays, strings, arrays)
  • Various selection, crossover, and mutation operators
  • GPU acceleration support using CuPy
  • Visualization tools for monitoring evolution progress

Main Components

  1. GenePool: Generates initial populations

    • FloatPool, StringPool, ArrayPool, ImagePool
  2. Individual: Represents a single solution in the population

  3. Layer: Defines genetic operators

    • Selection layers
    • Crossover layers (e.g., N-Point, Uniform)
    • Mutation layers (e.g., Gaussian, Uniform, Polynomial, Swap, Inversion, Scramble)
  4. Environment: Manages the evolution process

  5. Competition: Allows comparing multiple evolutionary strategies

Usage

  1. Define your fitness function
  2. Create a GenePool
  3. Set up Layers for selection, crossover, and mutation
  4. Initialize an Environment with your layers and individuals
  5. Run the evolution process

Example

from Finch import (FloatPool, Environment, RandomSelection,
                   GaussianMutation, ParentNPoint, Populate,
                   CapPopulation, SortByFitness)

def fitness_function(individual):
    return sum(individual.item)

gene_pool = 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 = [
    Populate(population=500, gene_pool=gene_pool),
    ParentNPoint(selection_function=crossover_selection.select, families=4, children=4),
    GaussianMutation(mutation_rate=0.1, sigma=0.5, selection_function=mutation_selection.select),
    SortByFitness(),
    CapPopulation(1000),
]

env = Environment(layers)
env.compile()
env.evolve(generations=1000)

print(env.best_ever.item)
env.plot()

Installation

pip install finch-genetics

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

finch-genetics-3.5.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

finch_genetics-3.5.1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file finch-genetics-3.5.1.tar.gz.

File metadata

  • Download URL: finch-genetics-3.5.1.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for finch-genetics-3.5.1.tar.gz
Algorithm Hash digest
SHA256 e1fb2a33f2a94df2f87bdc3e73010660188c447901ad67df75e5ba962c315bd2
MD5 96d4d90fa44c4d4a741f47d77c56c2ad
BLAKE2b-256 4b060c6545e0d6a98a8eae5193e88173359159ff9a8e86cc851252a5a81a6e07

See more details on using hashes here.

File details

Details for the file finch_genetics-3.5.1-py3-none-any.whl.

File metadata

  • Download URL: finch_genetics-3.5.1-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for finch_genetics-3.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 081aca49087d3fadd17881353545a9f33f1d115eb95c40cd09a2e0a231bcc610
MD5 8d0bb9c6fd778b66d88d4b1e0b489355
BLAKE2b-256 d313c3ed469820a9e2f5f1cc8e69193289dc8c2bfcab54273290e09bdeb04286

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page