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.1.0.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

pystrand-0.1.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pystrand-0.1.0.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.10.4 Linux/5.15.0-47-generic

File hashes

Hashes for pystrand-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0f074a95d427221c28396390ef0bbbfc720fdade1bbb40207bcb000397eb11a6
MD5 fbfbe6f59afaefc71e8b69f9af9ef0e2
BLAKE2b-256 239383e3b99d9b0f95cabbcce253e31d4ed44aaa6757802542964efdfd8a7ff5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pystrand-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.10.4 Linux/5.15.0-47-generic

File hashes

Hashes for pystrand-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b24921375ed004de9cadad71385845cfa8bfbea14bbbe6c084d2e819abc48202
MD5 67f3c199e022943bbb82352bdeaa1e0c
BLAKE2b-256 418c1363b6fc19c1b2a14ec11977e759a5e6fa7cae000f217b6de9e6a564c0d0

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