hbmo


Namehbmo JSON
Version 1.0.3 PyPI version JSON
download
home_pagehttps://github.com/alimahmoodi78/hbmo
Summaryimplementation of HBMO and MHBMO optimization algorithms
upload_time2023-09-10 17:57:38
maintainer
docs_urlNone
authorAli Mahmoodi
requires_python
licenseMIT
keywords swarm-based optimization honey-bee mating optimization
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Ali Mahmoodi[^a], Reza Piraei[^b], Seied Hosein Afzali[^b], and Majid Niazkar[^c]

[^a]: Department of Computer Engineering, Shiraz University, 7136474616, Shiraz, Iran. ORCID: 0009-0005-3761-2494, Email address: ali.mahmoodi7872@gmail.com

[^b]: 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

[^c]: 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

# 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.](https://doi.org/10.1016/j.jfranklin.2006.06.001), while for MHBMO algorithm you can refer to [Niknam et al.](https://doi.org/10.1016/j.energy.2010.10.062).
## 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:
```Python
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.
```Python
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)
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/alimahmoodi78/hbmo",
    "name": "hbmo",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "Swarm-Based Optimization,Honey-Bee Mating Optimization",
    "author": "Ali Mahmoodi",
    "author_email": "ali.mahmoodi7872@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f7/d3/dd0ac0030f22bd217bb12467f1823c9381d88dbe75c5d7835dbdf0ea6e8f/hbmo-1.0.3.tar.gz",
    "platform": null,
    "description": "Ali Mahmoodi[^a], Reza Piraei[^b], Seied Hosein Afzali[^b], and Majid Niazkar[^c]\r\n\r\n[^a]: Department of Computer Engineering, Shiraz University, 7136474616, Shiraz, Iran. ORCID: 0009-0005-3761-2494, Email address: ali.mahmoodi7872@gmail.com\r\n\r\n[^b]: 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\r\n\r\n[^c]: Faculty of Science and Technology, Free University of Bozen-Bolzano, Piazza Universit\u00c3\u00a0 5, 39100 Bolzano, Italy. ORCID: 0000-0002-5022-1026, Email address: majid.niazkar@unibz.it\r\n\r\n# HBMO\r\n***\r\nin 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.](https://doi.org/10.1016/j.jfranklin.2006.06.001), while for MHBMO algorithm you can refer to [Niknam et al.](https://doi.org/10.1016/j.energy.2010.10.062).\r\n## Traget Calculation Function\r\nFirst 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`.\r\n`params` is a 1-D `numpy.array` with size *P* (number of parameters) containing the parameters that you want to optimize.\r\n`data` is a 2-D `numpy.array` with size (*N*, *M*) containing *N* data samples with *M* features (columns).\r\n## HBMO input arguments\r\n`HBMO(n_param, calc_function, high, low, metric, init_pop, s_min_queen, s_max_queen, s_alpha, n_workers, seed)`\r\n\r\n`n_param`: number of parameters that need to be optimized.\r\n\r\n`calc_function`:target calculation function that we wxplained above.\r\n\r\n`high`: a list of upperbound values for each parameter.`Default`: 1 for all parameters.\r\n\r\n`low`: a list of lowerbound values for each parameter.`Default`: 0 for all parameters.\r\n\r\n`metric`: an evaluation function to measure the performance of parameters and it can be one of the \r\nfollowing values ('rmse', 'mse', 'mae'). `Default`: 'rmse'\r\n\r\n`init_pop`: the initial population of prameters. `Default`: 1,000\r\n\r\n`s_min_queen`: minimum possible speed of the queen. `default`: 1\r\n\r\n`s_max_queen`: maximum speed of the queen. `default`: 1,000,000\r\n\r\n`s_alpha`: a decay rate for speed of the queen. `Default`: 0.981\r\n\r\n`n_workers`: number of worker bees. `Default`: 10\r\n\r\n`seed`: a random seed value. `Default`: None\r\n## HBMO methods\r\n`HBMO.fit(data, targets, iterations)`: this method is for optimizing the parameters and it takes 3 inputs.\r\n1. `data` is a 2-D `numpy.array` with size (*N*, *M*) containing *N* data samples with *M* features.\r\n2. `targets` is a 1-D `numpy.array` with size *N* containing the real target values.\r\n3. `iterations` determines the number of iterations to optimize the parameters. `Default`: 20\r\n\r\n`HBMO.predict(data)`: this method is for predicting the target value for the given data.\r\n1. `data` is a 2-D `numpy.array` with size (*K*, *M*) containing *K* data samples with *M* features.\r\n\r\n`HBMO.plot_progress()`: this method is for plotting the progress of the queen's performance in each iteration.\r\n## Example\r\nIn 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.\r\nFirst define the Target Calculation Function:\r\n```Python\r\ndef my_function(params, data):\r\n    # separating the data features\r\n    f0 = data[:, 0]\r\n    f1 = data[:, 1]\r\n    f2 = data[:, 2]\r\n\r\n    # separating the parameters\r\n    a = params[0]\r\n    b = params[1]\r\n    c = params[2]\r\n    d = params[3]\r\n\r\n    # calculating the results using the formula\r\n    results = a*f0 + b*f1 + c*f2 + d\r\n\r\n    return results\r\n```\r\nand finally start the optimization using MHBMO algorithm.\r\n```Python\r\nfrom hbmo.optimizers import HBMO, MHBMO\r\n# instatiating from MHBMO class\r\noptim = MHBMO(n_param = 4,\r\n         calc_function = my_function,\r\n         high = [10, 12, 13, 15],\r\n         low = [0, 0, 0, 0],\r\n         metric = 'rmse',\r\n         init_pop = 1000,\r\n         s_min_queen = 1,\r\n         s_max_queen = 1e6,\r\n         s_alpha = 0.981,\r\n         n_workers = 10,\r\n         seed = 42)\r\n# starting the optimization process\r\noptim.fit(X_train, Y_train, iterations = 20)\r\n# plotting the progress\r\noptim.plot_progress()\r\n# predicting the targets for the test data\r\npredictions = optim.predict(X_test)\r\n# printing parameters with the best performance\r\nprint(optim.queen)\r\n```\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "implementation of HBMO and MHBMO optimization algorithms",
    "version": "1.0.3",
    "project_urls": {
        "Download": "https://github.com/alimahmoodi78/hbmo/archive/refs/tags/v1.0.tar.gz",
        "Homepage": "https://github.com/alimahmoodi78/hbmo"
    },
    "split_keywords": [
        "swarm-based optimization",
        "honey-bee mating optimization"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f7d3dd0ac0030f22bd217bb12467f1823c9381d88dbe75c5d7835dbdf0ea6e8f",
                "md5": "5efc178842bf052542e7fd34987b1396",
                "sha256": "434022dce38fc75b6b292da8cad4ea109f72f58967c61bf838e457866ea4be88"
            },
            "downloads": -1,
            "filename": "hbmo-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "5efc178842bf052542e7fd34987b1396",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5625,
            "upload_time": "2023-09-10T17:57:38",
            "upload_time_iso_8601": "2023-09-10T17:57:38.810096Z",
            "url": "https://files.pythonhosted.org/packages/f7/d3/dd0ac0030f22bd217bb12467f1823c9381d88dbe75c5d7835dbdf0ea6e8f/hbmo-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-10 17:57:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "alimahmoodi78",
    "github_project": "hbmo",
    "github_not_found": true,
    "lcname": "hbmo"
}
        
Elapsed time: 0.29970s