Package: hbmo
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.comandafzali@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.itHBMOin 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 toAfshar et al., while for MHBMO algorithm you can refer toNiknam et al..Traget Calculation FunctionFirst 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:paramsanddata.paramsis a 1-Dnumpy.arraywith sizeP(number of parameters) containing the parameters that you want to optimize.datais a 2-Dnumpy.arraywith size (N,M) containingNdata samples withMfeatures (columns).HBMO input argumentsHBMO(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,000s_min_queen: minimum possible speed of the queen.default: 1s_max_queen: maximum speed of the queen.default: 1,000,000s_alpha: a decay rate for speed of the queen.Default: 0.981n_workers: number of worker bees.Default: 10seed: a random seed value.Default: NoneHBMO methodsHBMO.fit(data, targets, iterations): this method is for optimizing the parameters and it takes 3 inputs.datais a 2-Dnumpy.arraywith size (N,M) containingNdata samples withMfeatures.targetsis a 1-Dnumpy.arraywith sizeNcontaining the real target values.iterationsdetermines the number of iterations to optimize the parameters.Default: 20HBMO.predict(data): this method is for predicting the target value for the given data.datais a 2-Dnumpy.arraywith size (K,M) containingKdata samples withMfeatures.HBMO.plot_progress(): this method is for plotting the progress of the queen's performance in each iteration.ExampleIn 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:defmy_function(params,data):# separating the data featuresf0=data[:,0]f1=data[:,1]f2=data[:,2]# separating the parametersa=params[0]b=params[1]c=params[2]d=params[3]# calculating the results using the formularesults=a*f0+b*f1+c*f2+dreturnresultsand finally start the optimization using MHBMO algorithm.fromhbmo.optimizersimportHBMO,MHBMO# instatiating from MHBMO classoptim=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 processoptim.fit(X_train,Y_train,iterations=20)# plotting the progressoptim.plot_progress()# predicting the targets for the test datapredictions=optim.predict(X_test)# printing parameters with the best performanceprint(optim.queen)