Skip to main content

Genetic Algorithms in Python

Project description

Big Bird

Big Bird is a (hopefully useful) package designed to facilitate the quick and convenient creation of basic genetic algorithms in python.

Examples

import bigbird

# Config Parameters for Big Bird
pop_size = 2000             # Size of each generation's population
layer_counts = [8, 5, 5, 3] # No. of nodes in each layer
m_r8 = 0.3                  # Chance of weight mutation
step_ratio = 1/3.6          # Size of weight perturbation
reinit_r = 0.015            # Chance of weight reinitialization on mutation
immune = 20                 # No. of non-mutated from top of previous generation

# When to automatically stop training
max_generation = 300

# Create a population with configuration parameters
population = bigbird.SimplePopulation(pop_size, layer_counts)

for generation in range(max_generation):
    for bird in population.birds:
        # Evaluates a bird's fitness based on a given input
        bird_inp = your_input_generation_fn()
        bird_out = bird.eval(bird_inp)
        decision = output.tolist().index(max(output))
        bird.fitness = your_fitness_fn(decision)

    # Saves the best performing bird's weight matrices
    champ = sorted(population.birds, key=lambda x: x.fitness)[-1]
    champ.save(fname='./hall-of-fame/champ-' + str(generation) + '.json')

    # Iniitializes next generation
    population.store(immune)
    population.breed()
    population.mutate(m_r8, step_ratio, reinit=reinit_r)
    population.retrieve()

Find more examples here

License

MIT

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

bigbird-0.1.2.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

bigbird-0.1.2-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file bigbird-0.1.2.tar.gz.

File metadata

  • Download URL: bigbird-0.1.2.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for bigbird-0.1.2.tar.gz
Algorithm Hash digest
SHA256 129222c90bc9e947aeb88c100e5d5b7e4482c43210ad12f114fa2fb7ac02dd7f
MD5 47ef0493fe7b83591254139b0cfbd039
BLAKE2b-256 48f7dadda323034b8872482c1874a54e3a66f1d820df58759c1321b63f30e0d8

See more details on using hashes here.

File details

Details for the file bigbird-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: bigbird-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for bigbird-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 98974274a3d0c15e0e0c560e53d2d80957da65a96f982a48bb83603adf90f80e
MD5 a7d0c3c2fac170225e949c987307365d
BLAKE2b-256 9e6285bb2d5d5e5327571645d4c344075dd0e69678e492e27f009abcc185d710

See more details on using hashes here.

Supported by

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