Skip to main content

PyGA

Build Status

PyGA is an extensible toolkit for Genetic Algorithms (GA) in Python.

The library aims to provide a high-level declarative interface which ensures that GAs can be implemented and customised with ease. PyGA features an extensible framework which allows researchers to provide custom implementations which interface with existing functionality.

  • License: MIT
  • Python Versions: 3.6+

Features:

  • High-level module for Genetic Algorithms.
  • Extensible API for implementing new functionality.

Basic Usage:

PyGA aims to provide a high-level interface for Genetic Algorithms - the code below demonstrates just how easy running an optimisation procedure can be.

import pyga
from pyga.utils.functions import single_objective as fx


bounds = {
    'x0': [-1e6, 1e6],
    'x1': [-1e6, 1e6],
    'x2': [-1e6, 1e6]
}

optimiser = pyga.SOGA(bounds, n_individuals=30, n_iterations=100)
optimiser.optimise(fx.sphere)

History:

The optimisation history is written to a History data structure to allow the user to further investigate the optimisation procedure upon completion. This is a powerful tool, letting the user define custom history classes which can record whichever data the user desires.

Tracking the history of the optimisation process allows for plotting of the results, an example demonstration is seen in the plot_fitness_history function - this can be further customised through the designation of a PlotDesigner object which provides formatting instructions for the graphing tools.

Constraints:

PyGA allows the user to define a set of constraints for the optimisation problem - this is achieved through inheriting a template class and implementing the designated method. An example of which is demonstrated below:

from pyga.constraints.base_constraints import PositionConstraint


class UserConstraint(PositionConstraint):

    def constrain(self, position):
        return position['x0'] > 0 and position['x1'] < 0


optimiser.constraint_manager.register_constraint(UserConstraint())

This provides the user with a large amount of freedom to define the appropriate constraints and allows the ConstraintManager to deal with the relevant constraints at the appropriate time.

Customisation:

Though the base SOGA will work for many, there maybe aspects that one may want to change, such as the selection / recombination methods. A common interface has been designed for these, this ensures that the user can alter the functionality at will and researchers can implement additional functionality with ease.

Attributes of the SOGA instance can be modified to implement alternative methods, this is demonstrated below:

# using 'uniform crossover' as the crossover method
from pyga.utils.crossovers import UniformCrossover
optimiser.crossover = UniformCrossover(p_swap=0.25)
# using 'fitness-proportionate selection' as the selection method
from pyga.utils.selections import FitnessProportionateSelection
optimiser.selection = FitnessProportionateSelection()

It is also possible to define alternative termination criteria through implementation of a TerminationManager class, a couple of examples are demonstrated below:

# using elapsed time as the termination criteria
from pyga.utils.termination_manager import TimeTerminationManager
optimiser.termination_manager = TimeTerminationManager(t_budget=10_000)
# using error as the termination criteria
from pyga.utils.termination_manager import ErrorTerminationManager
optimiser.termination_manager = ErrorTerminationManager(
    optimiser, target=0.0, threshold=1e-3
)
Author: Daniel Kelshaw

Metadata

Release files for PyGAopt 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyGAopt 1.0.1
File Size Uploaded Provenance Actions
PyGAopt-1.0.1.tar.gz 12.9 kB Without provenance Details for PyGAopt-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for PyGAopt 1.0.1
File Interpreter ABI Platform Actions
PyGAopt-1.0.1-py3-none-any.whl Python 3 none any Details for PyGAopt-1.0.1-py3-none-any.whl

Total release size: 37.5 kB

Release files / PyGAopt-1.0.1.tar.gz

Download URL PyGAopt-1.0.1.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8f575bfbeb67cfe82e2b97d70fa7abe19d9d66e0b155ed66bb84ed6699ebba77
BLAKE2b-256 checksum
How to use checksums
e0d2970a368b4285bdacceba09c967e68b98a7ca47a1d9703d87efb61ef47878
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

Release files / PyGAopt-1.0.1-py3-none-any.whl

Download URL PyGAopt-1.0.1-py3-none-any.whl
Size 24.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac9f19187d54738771ea859453007bfee4d37469b944c0b168db0a3d57892a45
BLAKE2b-256 checksum
How to use checksums
ce5872b97651a37e1e7dbfc3f4f4fecc79c92dd65acadd43ce5d3ee47560093b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

Security for PyGAopt 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page