Skip to main content

A Python implementation of the Bees Algorithm based Local Optima Region Radius Extimator (BA-LORRE). This library allows an out-of-the-box use of the numerical optimisation algorithm on an user-defined target function. The algorithm can be configured to find the maxima of the target function with an iterative process.

Project description

BA-LORRE

A Python implementation of the Bees Algorithm based Local Optima Region Radius Extimator. Most of the intelligenent numerical optimization algorithms available are only made to find the global optimum of a given function. In contrast, the BA-LORRE is a swarm computation algorithm designed to find several local optima, avoiding already explored regions during the search.

The algorithm exploits the search properties of the Bees Algorithm to identify the position and radius of local optima region in a non-parametric way. Once identified, the local score of those regions is lowered, allowing the algorithm to focus furture search to unexplored regions.

This library allows an off-the-shelf use of the algorithm to find the best local optima of an user-defined target function.

solutions

Reference

For details on the inner working of the BA-LORRE algorithm, how it's related on the Bess Algorithm and how the optima regions are found, please refer to this work.

If you are using this implementation of the BA-LORRE for your research, feel free to cite this work in your paper using the following BibTex entry:

@article{baronti2020analysis,
  title={An Analysis of the Search Mechanisms of the Bees Algorithm},
  author={Baronti, Luca and Castellani, Marco and Pham, Duc Truong},
  journal={Swarm and Evolutionary Computation},
  volume={59},
  pages={100746},
  year={2020},
  publisher={Elsevier},
  doi={10.1016/j.swevo.2020.100746},
  url={https://doi.org/10.1016/j.swevo.2020.100746}
}

Installation

This module is available on pip and can be installed as follows:

$ pip3 install ba_lorre

Usage and Guidelines

As an extension of the original Bees Algorithm, the BA-LORRE shares most of the interface and mirrors its general usage.

The main class, LORRE, has the following signature (mandatory parameters in bold):

  • score_function: Callable[[list], float] the function that need to be optimised. It can either be a (lambda) function or a class that overrides the __call__ function. Either way, score_function(solution: list) -> float needs to take a single parameter, a list of N float representing a position in the search space, and returns the score relative to that position;
  • range_min: list list of N float, indicating the lower bound of the search space;
  • range_max: list list of N float, indicating the upper bound of the search space;
  • nb: int number of sites;
  • nrb: int number of solutions sampled around each site, per iteration;
  • stlim: int stagnation limit, the number of iteration required to abandon a site if no local progress is made;
  • initial_ngh: list the neighbourhood used for the local search in a site;
  • shrink_factor: float how much a neighbourhood must be shrunk per every iteration that its centre is not updated;
  • derating_radius_selection_criterion: str the criterion used to identify the optima region radius. Allowed values are median and topological;
  • derating_type: str the shape of penalty that will apply on every found region. Allowed values are flat and linear;

In this context N is the number of dimensions of the score function to be optimized. At each iteration nb x nrb solutions are evaluated in the search space. Examples of scores functions that can be used as a benchmark can be found in this library.

Please note that for simplicity this algorithm solves a maximization problem. If you need to minimize a function, please provide the opposite of the function (i.e. g(x)=-f(x)) to the algorithm. The found solutions won't be affected.

Please refer to the Bees Algorithm documentation for further details.

Initialization

The algorithm is first instantiated (as an example, here we are using a simple hyperbolic function to be optimized)

from ba_lorre import LORRE

alg = LORRE(lambda x: -pow(x[0]*x[1],2),
            range_min=[-100, -100],
            range_max=[100, 100],
            nb=5, nrb=20, stlim=20,
            derating_radius_selection_criterion='median',
            derating_type='linear')

Optimization

Then the optimisation itself can be performed in different ways. The most simple method is calling performFullOptimisation specifying either the maximum number of iterations or the maximum score wanted as stopping criterion.

>>> alg.performFullOptimisation(max_iteration=50)
(50, -3.4228945713694973e-11)

This returns the number of iterations required and the score of the best solution found.

Alternatively, more control on the optimization process can achieved performing one iteration at a time this way:

alg.performSingleStep()

For score functions with 2 dimensions is possible to visualize the iterations of the algorithm calling

alg.visualize_iteration_steps()

This is often used for demonstration, debugging and to get a better insight on the algorithm dynamics. All the figures in this readme have been taken this way.

Found Optima Handling

The aim of the algorithm is to return the best local optima of a function. Once the optimization process is terminated the found optima can be collected with

alg.getFoundOptima()

which will return the position of the found optima.

For score functions with 2 dimensions is possible to visualize the found optima directly on the function's surface with:

alg.showFoundOptima()

solutions Either way, a list of pruning criteria can be passed to filter the found optima.

Pruning Criteria

The algorithm has no prior information on how many local optima the score function is supposed to have. As a result, spurious and redundant optima can be returned.

For this reason, this library comes with a set of pruning functions that can be passed to getFoundOptima or showFoundOptima to eliminate solutions that are unlikely to be a good approximation of real optima. Available pruning classes are:

  • PruningProximity putative optima that have been generated at the same time in the same region of an optimum of higher score are removed;
  • PruningAbsScoreCutoff putative optima with a score lower than the cutoff parameter, are removed;
  • PruningPercScoreCutoff putative optima with a score lower than cutoff% of the other optima are removed;

Any number of pruning criteria can be combined:

from ba_lorre import PruningProximity, PruningPercScoreCutoff

alg.getFoundOptima(pruning_functions=[PruningProximity(), PruningPercScoreCutoff(cutoff=.5)])

The PruningAbsScoreCutoff and PruningPercScoreCutoff pruning criteria require insight on the optima distribution to be used properly. To help the practitioner a convenience function to visualize the optima score distribution is provided:

alg.showOptimaScoreHistogram()

solutions

Versions History

v1.0.0

  • first release

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

ba_lorre-1.0.0.tar.gz (24.6 kB view details)

Uploaded Source

Built Distribution

ba_lorre-1.0.0-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file ba_lorre-1.0.0.tar.gz.

File metadata

  • Download URL: ba_lorre-1.0.0.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6

File hashes

Hashes for ba_lorre-1.0.0.tar.gz
Algorithm Hash digest
SHA256 04b0a1db904f86c148ae789292e2871e58148fe7e4297c98a48e79e0dd2b3c76
MD5 3e15644dfeb13a4bdbf7e71c5d274833
BLAKE2b-256 00feeb6bc00d1316751da198e9dd4c211d9be5bc1a69730964e05eb99ad986c5

See more details on using hashes here.

File details

Details for the file ba_lorre-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ba_lorre-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6

File hashes

Hashes for ba_lorre-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5fce4d51432492c364b0bc7113afe34b5686e157eeccbd2649d79a8d861ed57e
MD5 efad8b669ee9966b7639948f6a188c23
BLAKE2b-256 dbc167f92f1307d72f9a93f1b473dbb317d1a8f6368cc4091cb64c59038eaf76

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