Skip to main content

GPU and CPU modular genetic algorithm framework.

Project description

Finch

About

Finch 3 is a genetic algorithm framework. It aims to be:

  • understandable
  • fast
  • and capable

This is a very early version but here are some things you can expect:

  • The ability to run genetic algorithms on a GPU
  • Much better documentation than Finch2 (although this is a work in progress)
  • Overall much faster, more consistent, and far less bugs.

Docs

Here are the docs:

https://Finch-1.gitbook.io/Finch3/

Note: They are accurate but horribly formatted (will fix this soon)

Colab Notebooks

1: Simple Finch Colab Demo

  • Very simple genetic algorithm

2: Trick Clip

  • A genetic algorithm built to create 'adversarial images' against the Clip image recognition model.

Many Google Colab notebooks will be added here soon!

Installation

From Pip

pip install finch-genetics

From Git

run git clone https://github.com/dadukhankevin/Finch

Example

This example demonstrates the usage of Finch3, a genetic programming library, to evolve individuals in a sequential environment.

  1. Import Finch:

    from Finch.environments import Sequential
    from Finch.genepools import FloatPool
    from Finch.layers import *
    
  2. Define a fitness function fit that evaluates the performance of an individual. This is a very simple fitness function, and will essentially help us evolve a list floats to slowly become higher and higher numbers. The fitness function could also simply turn the floats into weights in a neural network and then evaluate their performance, this concept is called neuroevolution.

    def fit(individual):
        return sum(individual.genes)  # You can modify the fitness function to make it interesting
    
  3. Configure the genetic algorithm parameters in the Config section.

    # Config section
    length = 100
    pool_minimum = 0
    pool_maximum = 10
    population_size = 100
    amount_to_mutate = 10
    gene_selection = 5
    parent_count = 20
    children_count = 2
    max_population = 99
    evolution_steps = 1000
    min_mutation = -2
    max_mutation = 2
    
  4. Create a FloatPool to define the gene pool for individuals.

    # Creating the FloatPool
    pool = FloatPool(length=length, minimum=pool_minimum, maximum=pool_maximum)
    
  5. Create a Sequential environment with various layers representing different genetic operations.

    # Creating the Sequential environment
    environment = Sequential(layers=[
        Populate(pool, population=population_size),
        FloatMutateRange(individual_selection=amount_to_mutate, gene_selection=gene_selection,
                         min_mutation=min_mutation, max_mutation=max_mutation, keep_within_genepool_bounds=True),
        ParentSimple(parent_count, children=children_count),
        SortByFitness(),
        CapPopulation(max_population=max_population),
    ])
    
  6. Run the genetic algorithm.

    if __name__ == "__main__":
        # Compiling the environment with the fitness function
        environment.compile(fitness_function=fit)
        environment.evolve(evolution_steps)
    
        # Printing the best individual
        print("Here is the best individual:\n", environment.best_ever.genes)
    
        # Plotting the environment
        environment.plot()
    

Another example can be found in the /examples directory!

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.0.5.tar.gz (17.5 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.0.5-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: finch-genetics-3.0.5.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for finch-genetics-3.0.5.tar.gz
Algorithm Hash digest
SHA256 e5d50ec2ba1108127f8b27c2029f6aa914ec938438babdb45f67118d39271461
MD5 1fd3bb516b8ffe8b92b117d06ed6142c
BLAKE2b-256 8d59c2d239dbfa688ba102ce30468335fc83968440a5c5c3dd1c9f1500c1aa1d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: finch_genetics-3.0.5-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for finch_genetics-3.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 829bc0470aea921867ec05731c394c4cb060d262aab0c1d350246705f0ec32ae
MD5 9305cdb67c85b173d5b872366ad27f17
BLAKE2b-256 4034b1f8e5e3c56660d2a6a51d91b560eff4bf39d7cfa9b670b66fa922f16e27

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