Skip to main content

Python genetic algorithm package

Project description

pystrand

build

Quickstart

In order to define a genetic algorithm you only need to determine how should genotypes, or candidate solutions, look and which operators should apply to them.

The rest is simply matter of providing training data.

In our case the data was generated by function f(x) = 5 + 5x + 2x^2.

   >>>x = [i for i in range(10)]
   >>>y = [5 + (5*i) +(2*(i**2)) for i in x]

After importing the model class we define which values can genes take.

   >>>from pystrand.models.polymodels import PowerPolyModel
   >>>domain = [i/10 for i in range(-100, 100)]

At the model initialization we can provide constraints on operator behavior, population size and maximum allowed runtime. This is particulary useful if we are looking for approximate solution.

 >>> model = PowerPolyModel(domain, population_size=500, max_iterations=1000, crossover_prob=0.5)

We can also initialize the model with no constraints on the behavior of the algorithm, which will set parameters to pre-determined defaults. The only required parameter is the domain of gene values.

 >>> model = PowerPolyModel(domain)

Model is then fitted on provided data.

   >>>model.fit(x, y, verbose=0)
   >>>model.solution
   ... (1., Genotype([5., 5., 2., 0., 0., 0., 0., 0., 0., 0.]))

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

pystrand-0.0.1.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

pystrand-0.0.1-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

Details for the file pystrand-0.0.1.tar.gz.

File metadata

  • Download URL: pystrand-0.0.1.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/28.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.51.0 importlib-metadata/4.11.3 keyring/18.0.1 rfc3986/1.4.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for pystrand-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9298b725ee644a8d7df7e91f30d2925cb1ea5846b9c82f7e47810d2e4b93bb15
MD5 80ff5331e07903c8e4b0b862336ab3c2
BLAKE2b-256 5f0f6d2ef54ef1b793f0beb93911da7bd743fe47ff9737d013bc879adc11060c

See more details on using hashes here.

File details

Details for the file pystrand-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pystrand-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 25.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/28.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.51.0 importlib-metadata/4.11.3 keyring/18.0.1 rfc3986/1.4.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for pystrand-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0ab0c939b442fe24d9e8ff1cef8ee48525a2977f17ffd26614eb9c7c9a7a820b
MD5 d024a8cb0dba055e4d3a9f2aec6ca047
BLAKE2b-256 66ab128fff24b0c9dc773f484ffe52aed6c8d1bac04b38eb966f17a74508efae

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