dananjayamahesh / MunichBFOR

MuNic-BFor: Multi-Niche Bacterial Foraging (Evolutionary) Algorithm for Multimodal Dynamic Optimizations (intially developed for hyper-parameter optimizations of neural networks)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MuNic-BFor

MuNicBFOr is a library of evolutionary algorithms, specifically Bacterial Foraging, that was developed as an extension to SwarmPackagePy. It includes a class of optimization algorithms and each can be used for solving specific optimization problem. You can find the principles they operate on and pseudo codes below.

you can also access the presentation here for more details https://github.com/dananjayamahesh/MunichBFOR/blob/master/MuNichBFor.pdf

Alt Text

Watch the video

Provides:

  • BFO optimization algorithms.
  • Advanced BFO optimization algorithms.
  • Deep Neural Network Optimizations with MunichBFOR.
  • Non-Convex Revenue Optimization with MunichBFOR.
  • Test functions for BFO algorithms.
  • Animation of minimum find process.

    Every algorithm has arguments listed below:
  • n: number of agents
  • function: test function
  • lb: lower limits for plot axes
  • ub: upper limits for plot axes
  • dimension: space dimension
  • iteration: number of iterations

    Every algorithm has methods listed below:
  • get_agents(): returns a history of all agents of the algorithm
  • get_Gbest(): returns the best position of algorithm

    If an algorithm accepts some additional arguments or methods they will be described in its "Arguments" or "Methods" section.

For all questions and suggestions contact dananjayamahesh@gmail.com:

Table of contents

Installation

Requirements

  • python (version >= 3.5 if you are going to run tests; for all other actions you can use python any version)
  • numpy
  • pytest (if you are going to run tests)
  • matplotlib (if you are going to watch animation)
  • pandas (if you are going to watch 3D animation)

Installation

You can install SwarmPackagePy from PyPI repositories using pip. Command bellow will do this:

pip install SwarmPackagePy

Or you can just clone this repository and at the main folder execute command:

cd SwarmPackagePy/
python setup.py install

Bacterial Foraging Optimization

Description

The Bacterial Foraging Optimization, proposed by Passino is inspired by the social foraging behavior of Escherichia coli (next E.coli).
During foraging of the real bacteria, locomotion is achieved by a set of tensile flagella. Flagella help an E.coli bacterium to tumble or swim, which are two basic operations performed by a bacterium at the time of foraging. When they rotate the flagella in the clockwise direction, each flagellum pulls on the cell. That results in the moving of flagella independently and finally the bacterium tumbles with lesser number of tumbling whereas in a harmful place it tumbles frequently to find a nutrient gradient. Moving the flagella in the counterclockwise direction helps the bacterium to swim at a very fast rate. In the above-mentioned algorithm the bacteria undergoes chemotaxis, where they like to move towards a nutrient gradient and avoid noxious environment. Generally the bacteria move for a longer distance in a friendly environment.
When they get food in sufficient, they are increased in length and in presence of suitable temperature they break in the middle to from an exact replica of itself. This phenomenon inspired Passino to introduce an event of reproduction in BFO. Due to the occurrence of sudden environmental changes or attack, the chemotactic progress may be destroyed and a group of bacteria may move to some other places or some other may be introduced in the swarm of concern. This constitutes the event of elimination-dispersal in the real bacterial population, where all the bacteria in a region are killed or a group is dispersed into a new part of the environment.
Bacterial Foraging Optimization has three main steps:

  • Chemotaxis
  • Reproduction
  • Elimination and Dispersal

Mathematical model

Chemotaxis: This process simulates the movement of an E.coli cell through swimming and tumbling via flagella. Biologically an E.coli bacterium can move in two different ways. It can swim for a period of time in the same direction or it may tumble, and alternate between these two modes of operation for the entire lifetime. Reproduction: The least healthy bacteria eventually die while each of the healthier bacteria (those yielding lower value of the objective function) asexually split into two bacteria, which are then placed in the same location. This keeps the swarm size constant. Elimination and Dispersal: Gradual or sudden changes in the local environment where a bacterium population lives may occur due to various reasons e.g. a significant local rise of temperature may kill a group of bacteria that are currently in a region with a high concentration of nutrient gradients. Events can take place in such a fashion that all the bacteria in a region are killed or a group is dispersed into a new location. To simulate this phenomenon in BFO some bacteria are liquidated at random with a very small probability while the new replacements are randomly initialized over the search space.

Algorithm

BEGIN
 Initialize randomly the bacteria foraging optimization population
 Calculate the fitness of each agent
 Set global best agent to best agent
 FOR number of iterations
  FOR number of chemotactic steps
   FOR each search agent
    Move agent to the random direction
    Calculate the fitness of the moved agent
    FOR swimming length
     IF current fitness is better than previous
      Move agent to the same direction
     ELSE
      Move agent to the random direction
     END IF
    END FOR
   END FOR
   Calculate the fitness of each agent
  END FOR
  Compute and sort sum of fitness function of all chemotactic loops (health of agent)
  Let live and split only half of the population according to their health
  IF not the last iteration
   FOR each search agent
    With some probability replace agent with new random generated
   END FOR
  END IF
  Update the best search agent
 Calculate the fitness of each agent
END

Arguments

The bfo method accepts the following arguments:
param Nc number of chemotactic steps
param Ns swimming length
param C the size of step taken in the random direction specified by the tumble
param Ped elimination-dispersal probability

Method invocation

The method can be invoked by passing the arguments in the following order:

SwarmPackagePy.bfo(n, function, lb, ub, dimension, iteration, Nc, Ns, C, Ped)

Tests

All algorithms were tested with different test functions. In fact, you can run tests for all the algorithms on your own. All you need to do is to open terminal (console) and insert the following line:

pytest -v —tb=line test.py

Every algorithm is tested with the following set of test functions:

  • Ackley function
  • Bukin function
  • Cross in tray function
  • Sphere function
  • Bohachevsky function
  • Sum squares function
  • Sum of different powers function
  • Booth function
  • Matyas function
  • McCormick function
  • Dixon price function
  • Six hump camel function
  • Three hump camel function
  • Easom function
  • Michalewicz function
  • Beale function
  • drop wave function
  • Revenue Optimization Algorithms

Animation

There are 2D animation and 3D animation of search process. The general way to start it is (example for pso algorithm):

2D animation

# Compute the algorithm
function = SwarmPackagePy.testFunctions.easom_function
alh = SwarmPackagePy.pso(15, function, -10, 10, 2, 20)
# Show animation
animation(alh.get_agents(), function, 10, -10)

3D animation

# Compute the algorithm
function = SwarmPackagePy.testFunctions.easom_function
alh = SwarmPackagePy.pso(15, function, -10, 10, 2, 20)
# Show animation
animation3D(alh.get_agents(), function, 10, -10)

Save the animation

You can also save the animation of the search process. To do this, add as an animation argument sr=True. The example of saving animation:

# Compute the algorithm
function = SwarmPackagePy.testFunctions.easom_function
alh = SwarmPackagePy.pso(15, function, -10, 10, 2, 20)
# Show animation
animation(alh.get_agents(), function, 10, -10, sr=True)

About

MuNic-BFor: Multi-Niche Bacterial Foraging (Evolutionary) Algorithm for Multimodal Dynamic Optimizations (intially developed for hyper-parameter optimizations of neural networks)


Languages

Language:Python 100.0%