Skip to main content

Black Widow Optimization

gh-actions-ci GitHub license PyPI pyversions PyPi Version codecov

From the abstract:

...a novel meta-heuristic algorithm suitable for continuous nonlinear optimization problems. The proposed method, Black Widow Optimization Algorithm (BWO), is inspired by the unique mating behavior of black widow spiders. This method includes an exclusive stage, namely, cannibalism. Due to this stage, species with inappropriate fitness are omitted from the circle, thus leading to early convergence. BWO algorithm is evaluated on 51 various benchmark functions to verify its efficiency in obtaining the optimal solutions for the problems. The obtained results indicate that the proposed algorithm has numerous advantages in different aspects such as early convergence and achieving optimized fitness value compared to other algorithms.

Installation

pip install bwo

or

pip install git+https://github.com/nathanrooy/bwo

Usage

As a simple example, let's find the minimum of the single objective sphere function available in the Landscapes Python package.

pip install landscapes

Next, let's import everything we need.

>>> from bwo import minimize
>>> from landscapes.single_objective import sphere

Now, we just need to call the minimize function. For this particular example, let's optimize across 5 degrees of freedom.

>>> fbest, xbest = minimize(sphere, dof=5)

Where fbest is the best function value achieved during optimization, and xbest is the function input which yielded fbest.

You can also minimize a function given boundary constraints, represented by a list of tuples. Each tuple must follow the (min, max) format.

>>> bounds = [(-1,1),(-2,2), (-3,3), (-4,4), (-5,5)]
>>> fbest, xbest = minimize(sphere, bounds=bounds)

To display the convergence, simply set the disp flag to true as such:

>>> fbest, xbest = minimize(sphere, dof=5, maxiter=20, disp=True)

Which should yield something like the following:

> ITER:  1 | GBEST: 0.561091
> ITER:  2 | GBEST: 0.358288
> ITER:  3 | GBEST: 0.103173
> ITER:  4 | GBEST: 0.008892
> ITER:  5 | GBEST: 0.008892
> ITER:  6 | GBEST: 0.008887
> ITER:  7 | GBEST: 0.005540
> ITER:  8 | GBEST: 0.005540
> ITER:  9 | GBEST: 0.001907
> ITER: 10 | GBEST: 0.001221
> ITER: 11 | GBEST: 0.001147
> ITER: 12 | GBEST: 0.001056
> ITER: 13 | GBEST: 0.000874
> ITER: 14 | GBEST: 0.000874
> ITER: 15 | GBEST: 0.000760
> ITER: 16 | GBEST: 0.000760
> ITER: 17 | GBEST: 0.000731
> ITER: 18 | GBEST: 0.000731
> ITER: 19 | GBEST: 0.000719
> ITER: 20 | GBEST: 0.000719

Options

minimize(func, x0=None, dof=None, bounds=None, pp=0.6, cr=0.44, pm=0.4, npop=10, disp=False, maxiter=50, tol=0.0, patience=None, seed=None)

  • func (callable) : The objective function to be minimized.
  • x0 (list) : Initial guess (optional).
  • dof (int) : degrees of freedom (optional)
  • bounds(list of tuples) : boundary constraints as specified as a list of (xi_min, xi_max) tuples.
  • pp (float) : procreating percentage (0, 1].
  • cr (float) : cannibalism rate [0, 1].
  • pm (float) : mutation rate [0, 1].
  • npop (int) : population size.
  • disp (bool) : output intermediate results at each iteration.
  • maxiter (int) : maximum number of iterations.
  • tol (float) : minimum improvement in best fitness required to reset early-stopping counter.
  • patience (int, optional) : number of consecutive iterations without improvement > tol before stopping early.
  • seed (int, optional) : random seed for reproducible optimization runs.

References

@article{article,
author = {Hayyolalam, Vahideh and Pourhaji Kazem, Ali Asghar},
year = {2019},
month = {10},
pages = {103249},
title = {Black Widow Optimization Algorithm: A novel meta-heuristic approach for solving engineering optimization problems},
volume = {87},
journal = {Engineering Applications of Artificial Intelligence},
doi = {10.1016/j.engappai.2019.103249}
}

Metadata

Release files for bwo 0.1.3

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

Source distribution (sdist)

Source distribution for bwo 0.1.3
File Size Uploaded Provenance Actions
bwo-0.1.3.tar.gz 8.2 kB Without provenance Details for bwo-0.1.3.tar.gz

Built distribution (wheel)

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

Total release size: 16.4 kB

Release files / bwo-0.1.3.tar.gz

Download URL bwo-0.1.3.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
bc6f06fa52cf4ac13e54ebf4cee1de4c53803282b091483b2adeb584726f26f3
BLAKE2b-256 checksum
How to use checksums
124a4a07ecd451c4e84aaa69856c86a0a110ec24123e12df7c90bfd4c669defc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Release files / bwo-0.1.3-py3-none-any.whl

Download URL bwo-0.1.3-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40a9866bf94aa7eefda5d18a86ee9fa39195d9d5a604f1ff86c5fea5526635d1
BLAKE2b-256 checksum
How to use checksums
56791ff098d68ff981987f8baea6277ff3a170bce0c8424749d6836be483d959
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Security for bwo 0.1.3

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.

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