Skip to main content

pybees: Python optimization toolkit using the bees algorithm



What is it?

pybees is a Python package for function optimization. It uses the nature inspired bees algorithm, proposed by Pham et al. and is built on top of SciPy. pybees is distributed under the 3-Clause BSD license.

The bees algorithm is a swarm based search algorithm, which mimics the food foraging behaviour of honey bees. The basic algorithm is suitable for both continuous and combinatorial optimization problems, which is demonstrated in the basic examples section.

Main features

  • High-level API to optimize continuous functions (training a multilayer perceptron).

  • High-level API to optimize discrete functions (traveling salesperson problem).

  • Built in single-objective cost functions.

  • plotly plotting tools for 2D and 3D (both continuous and discrete).

  • Extensible API for developing new ideas.

Where to get it

If all dependencies are already installed, then the easiest way to install pybees is using pip.

pip install pybees

How to use it

Please visit the examples folder to view the demonstration examples. These include.

Future examples will include

  • Multilayer perceptron

Dependencies

pybees requires:

  • numpy >= 1.17.4
  • scipy >= 1.3.2
  • plotly >= 4.4.1
  • tqdm >= 4.40.2
  • sklearn >= 0.22
  • pandas >= 0.25.3

License

BSD 3

Basic Examples

Continuous function optimization

import pybees as pb

sbc = pb.SimpleBeesContinuous(
    n_scout_bees = 50, 
    elite_site_params = (15, 40), 
    best_site_params = (15, 30),
    bounds = (-10,10), 
    n_dim = 2,
    nbhd_radius = 2
)

This operation returns a scipy.optimize.OptimizeResult. fun represents the value of the objective function (lowest point). nit represents the number of iterations taken. x represents the coordinates of the value found for the objective function.

>>> sbc.optimize(pb.levy)
fun: 1.007063464503951e-06
nit: 100
x: array([0.99905553, 0.99967304])

The results may also be visualised by using the following

sbc.plot(global_min = (1, 1))

Combinatorial optimization (e.g. travelling salesperson problem)

import pybees as pb

sbd = pb.SimpleBeesDiscrete(
    n_scout_bees = 50, 
    elite_site_params = (15, 40), 
    best_site_params = (15, 30), 
    coordinates = np.random.randint(10, size=[10, 2])
)

This operation returns a scipy.optimize.OptimizeResult result. res.coordinates represents sbd.coordinates reordered, resulting from the optimization of some objective function. In this example, tour_distance was minimized. As such, coordinates represents the sequence, corresponding to the shortest path between all coordinates (i.e. travelling salesperson problem). fun represents the value of the objective function (shortest distance). nit represents the number of iterations taken. x represents the permutation of the original sequence passed to SimpleBeesDiscrete which gives the shortest distance.

>>> sbd.optimize(pb.tour_distance)
coordinates: array([
       [7., 8.],
       [4., 8.],
       [2., 6.],
       [0., 5.],
       [1., 0.],
       [3., 2.],
       [2., 4.],
       [3., 4.],
       [5., 4.],
       [7., 4.]])
fun: 27.228009718084742
nit: 100
x: array([1., 9., 7., 5., 0., 3., 4., 6., 2., 8.])

The results may also be visualised by using the following

sbd.plot()

Metadata

Release files for pybees 0.0.4

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

Source distribution (sdist)

Source distribution for pybees 0.0.4
File Size Uploaded
pybees-0.0.4.tar.gz 29.9 kB Details

Built distribution (wheel)

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

Total release size: 67.7 kB

Release files / pybees-0.0.4.tar.gz

Download URL pybees-0.0.4.tar.gz
Size 29.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c7c22142f9fdcde81acb1809770e71ab2de221e235ddc54aeef501412bfe0c1e
BLAKE2b-256 checksum
How to use checksums
e5813bc5b5916a0e22c4b798236c0342535be6096c6fb150bc22a6e4ce7e910b
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 / pybees-0.0.4-py3-none-any.whl

Download URL pybees-0.0.4-py3-none-any.whl
Size 37.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2331969044cda9eca344bcadd4af88e000b11dc7b72ed44faebaf4de23414170
BLAKE2b-256 checksum
How to use checksums
3482a6de5458cf005a2747ab366d361b74076b012f1bf1bd89f79a9812a48081
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

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

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