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 finch_genetics2 (although this is a work in progress)
  • Overall much faster, more consistent, and far less bugs.

Docs

Here are the docs:

https://finch_genetics-1.gitbook.io/finch_genetics3/

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

Colab Notebooks

1: Simple finch_genetics 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_genetics

Example

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

  1. Import finch_genetics:

    from finch_genetics.environments import Sequential
    from finch_genetics.genepools import FloatPool
    from finch_genetics.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.3.tar.gz (10.1 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.3-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: finch-genetics-3.0.3.tar.gz
  • Upload date:
  • Size: 10.1 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.3.tar.gz
Algorithm Hash digest
SHA256 f296c656bc22e79cc9f9976646035e03c22159553dd02e10ca8dd583347d92c8
MD5 51e324f8133a7e9f1ac2077cfca91b00
BLAKE2b-256 ceedd6b69c77683a197dd187ebcb2bcf1dfc66b1007d02a96ead8b5cf6e36e1d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: finch_genetics-3.0.3-py3-none-any.whl
  • Upload date:
  • Size: 12.8 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5ce5e01a6c1d6200405e5957049da239a0c10ef85b761febbfb983b1e699c297
MD5 606615835f398607fb566b1d4d79751c
BLAKE2b-256 b32205c36504d02262de0a3a75406f0f902a22e4f34c4c25ade8944235e1bdc3

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