Skip to main content

implementation of HBMO and MHBMO optimization algorithms

Project description

Ali Mahmoodi1, Reza Piraei2, Seied Hosein Afzali2, and Majid Niazkar3

HBMO


in this work, we implemented swarm-based optimization algorithms called Honey-Bee Mating Optmization (HBMO) and Modified HBMO (MHBMO). The HBMO algorithm draws inspiration from the social life style of honeybees within a colony, specifically simulating the process of queen mating. A typical honeybee colony consists of various members, including a queen, workers, drones, and broods. The original version of the algorithm had a convergence problem where brood generation could get stuck in local optima. To address this issue, modifications have been made to the algorithm, resulting MHBMO. For more information regarding the details of HBMO algorithm you can refer to Afshar et al., while for MHBMO algorithm you can refer to Niknam et al..

Traget Calculation Function

First you need to define a function that calculates the target value for each sample in the input data. this function must have two input arguments: params and data. params is a 1-D numpy.array with size P (number of parameters) containing the parameters that you want to optimize. data is a 2-D numpy.array with size (N, M) containing N data samples with M features (columns).

HBMO input arguments

HBMO(n_param, calc_function, high, low, metric, init_pop, s_min_queen, s_max_queen, s_alpha, n_workers, seed)

n_param: number of parameters that need to be optimized.

calc_function:target calculation function that we wxplained above.

high: a list of upperbound values for each parameter.Default: 1 for all parameters.

low: a list of lowerbound values for each parameter.Default: 0 for all parameters.

metric: an evaluation function to measure the performance of parameters and it can be one of the following values ('rmse', 'mse', 'mae'). Default: 'rmse'

init_pop: the initial population of prameters. Default: 1,000

s_min_queen: minimum possible speed of the queen. default: 1

s_max_queen: maximum speed of the queen. default: 1,000,000

s_alpha: a decay rate for speed of the queen. Default: 0.981

n_workers: number of worker bees. Default: 10

seed: a random seed value. Default: None

HBMO methods

HBMO.fit(data, targets, iterations): this method is for optimizing the parameters and it takes 3 inputs.

  1. data is a 2-D numpy.array with size (N, M) containing N data samples with M features.
  2. targets is a 1-D numpy.array with size N containing the real target values.
  3. iterations determines the number of iterations to optimize the parameters. Default: 20

HBMO.predict(data): this method is for predicting the target value for the given data.

  1. data is a 2-D numpy.array with size (K, M) containing K data samples with M features.

HBMO.plot_progress(): this method is for plotting the progress of the queen's performance in each iteration.

Example

In this example we will show you how to optimize several coefficients using HBMO/MHBMO algorithm to calculate the output based on a linear formula from the input features. First define the Target Calculation Function:

def my_function(params, data):
    # separating the data features
    f0 = data[:, 0]
    f1 = data[:, 1]
    f2 = data[:, 2]

    # separating the parameters
    a = params[0]
    b = params[1]
    c = params[2]
    d = params[3]

    # calculating the results using the formula
    results = a*f0 + b*f1 + c*f2 + d

    return results

and finally start the optimization using MHBMO algorithm.

from hbmo.optimizers import HBMO, MHBMO
# instatiating from MHBMO class
optim = MHBMO(n_param = 4,
         calc_function = my_function,
         high = [10, 12, 13, 15],
         low = [0, 0, 0, 0],
         metric = 'rmse',
         init_pop = 1000,
         s_min_queen = 1,
         s_max_queen = 1e6,
         s_alpha = 0.981,
         n_workers = 10,
         seed = 42)
# starting the optimization process
optim.fit(X_train, Y_train, iterations = 20)
# plotting the progress
optim.plot_progress()
# predicting the targets for the test data
predictions = optim.predict(X_test)
# printing parameters with the best performance
print(optim.queen)
  1. Department of Computer Engineering, Shiraz University, 7136474616, Shiraz, Iran. ORCID: 0009-0005-3761-2494, Email address: ali.mahmoodi7872@gmail.com

  2. Department of Civil Engineering, Shiraz University, 7134851156, Shiraz, Iran. ORCID: 0000-0001-7129-8076 and 0000-0002-9195-615X, Email address: piraeir@gmail.com and afzali@shirazu.ac.ir 2

  3. Faculty of Science and Technology, Free University of Bozen-Bolzano, Piazza Università 5, 39100 Bolzano, Italy. ORCID: 0000-0002-5022-1026, Email address: majid.niazkar@unibz.it

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

hbmo-1.0.3.tar.gz (5.6 kB view details)

Uploaded Source

File details

Details for the file hbmo-1.0.3.tar.gz.

File metadata

  • Download URL: hbmo-1.0.3.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.12

File hashes

Hashes for hbmo-1.0.3.tar.gz
Algorithm Hash digest
SHA256 434022dce38fc75b6b292da8cad4ea109f72f58967c61bf838e457866ea4be88
MD5 5efc178842bf052542e7fd34987b1396
BLAKE2b-256 f7d3dd0ac0030f22bd217bb12467f1823c9381d88dbe75c5d7835dbdf0ea6e8f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page