Skip to main content

PySwallow

Build Status

PySwallow is an extensible toolkit for PSO.

The library aims to provide a high-level declarative interface which ensures that PSOs can be implemented and customised with ease. PySwallow 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 Particle Swarm Optimisation.
  • Extensible API for implementing new functionality.

Basic Usage:

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

import pyswallow as ps
from pyswallow.utils.functions import single_objective as fx


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

optimiser = ps.Swarm(bounds=bounds, n_swallows=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:

PySwallow 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 pyswallow.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 Swarm is very effective, there may be aspects that the user wishes to change, such as the boundary handler / inertia weight methods. The library provides an extensible API which allows the user to implement a variety of functions as well as develop their own with templates provided in the form of Abstract Base Classes.

Attributes of the Swarm instance can be modified to alter how the optimisation process will work, this is demonstrated below:

# altering the boundary handling method
from pyswallow.handlers.boundary_handler import NearestBH
optimiser.bh = NearestBH(lb, ub)
# altering the inertia weight handler
from pyswallow.handlers.inertia_handler import LinearIWH
optimiser.iwh = LinearIWH(w_init=0.7, w_end=0.4, n_iterations=100)

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 pyswallow.utils.termination_manager import TimeTerminationManager
optimiser.termination_manager = TimeTerminationManager(t_budget=10_000)
# using error as the termination criteria
from pyswallow.utils.termination_manager import ErrorTerminationManager
optimiser.termination_manager = ErrorTerminationManager(
    optimiser, target=0.0, threshold=1e-3
)
Author: Daniel Kelshaw

Metadata

Release files for PySwallow 1.0.0

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

Source distribution (sdist)

Source distribution for PySwallow 1.0.0
File Size Uploaded
PySwallow-1.0.0.tar.gz 15.9 kB Details

Built distribution (wheel)

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

Total release size: 46.6 kB

Release files / PySwallow-1.0.0.tar.gz

Download URL PySwallow-1.0.0.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
404aa89bb30b72ef61d610ef8025de2b5e1094cf7fd06cff795aa7554bb18931
BLAKE2b-256 checksum
How to use checksums
f0e3fa901b25da3da4bd87688945a746be4063e1e99b2543e92e2242482a341d
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 / PySwallow-1.0.0-py3-none-any.whl

Download URL PySwallow-1.0.0-py3-none-any.whl
Size 30.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5fca4b97f669fef728d15be9e20cc8de041411af38362ce8e19554242b592ddc
BLAKE2b-256 checksum
How to use checksums
f94ce34e4695a429faa8ad19aa9a0907a7980c9f10a2d33b83aef479df841431
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 history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

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