BAT Optimization Algorithm

(96 customer reviews)


Total downloads: 459

This code implements the BAT optimization algorithm which is useful in various linear, non-linear optimization problems. This repository shares the free MATLAB code with full implementation of this paper.

Download Code  Discuss Code


The paper published by Yang, X. S. (2010). “A New Metaheuristic Bat-Inspired Algorithm, in: Nature Inspired Cooperative Strategies for Optimization (NISCO 2010)”. Studies in Computational Intelligence. 284: 65–74 is implemented at A demo version of this is available here but we found it hard to use in any application. So developed in house full BAT code and happy to share here.

The Bats have some echolocation characteristics by using them we can develop an Algorithm for the optimization. Some rules for the Bat algorithm explained below.

  1. The distance can be sense by the bats using the echolocation and they have also difference between food/prey and the background barriers.
  2. The velocity of the Bats represented by (vi) and position of the Bat is (xi)having frequency Fmin varying wavelength  and loudness A0 search for food.
  3. The loudness A0 also take as Amin constant value.

The Matlab coding for the Bat function done by consider various parameters. Various steps are involved for the Bat coding.

Step1.  Firstly make the statement for Bat function


In above statement the input parameter is mainly a benchmark function which is represented by a ‘fobj’ and others are lb=lower bound limit and ub=upper bound limit , fmax is the maximum frequency and fmin is the minimum frequency , A= loudness of each Bat, r=pulse emission rate of each Bat, alpha and gamma are the constants for the loudness and pulse emission rate. The r0 is the initial pulse rate.

Step2. After the statement call the initialization function. The script for the initialization function written separately.

x=initialization(N, Max_iter, dim, ub, lb)     

In initialization upper bound and lower bound limits are available and bats position is randomly search. Each bat has different upper and lower bound limits. There is N number of searching variable. Calculate the initial position of the search variable. We initialize the parameters of algorithm, generate and also evaluate the initial population, and then determine the best solution  in the population. Here, virtual bats are moved in the search space according to updating rules of the bat algorithm.

Step3. Call the benchmark function here which is represented by the ‘fobj’and find the initial best fitness value for benchmark objective function.

The fobj function contains all the information about the benchmark function. It has 23 different benchmark function cases which have different dimension, upper bound and lower bound limits. We can randomly take any benchmark (F1 …..F23) objective function.

The initial best value is obtained

[fmin, index]=min(fitness) 

Also find the best solution for the best fitness value of the objective function.

Step4. Then start the main loop for the maximum iterations. Randomly choose the frequency as equation


Then update the velocity of the bats and position of the bats. After the update of both the terms than applied the upper and lower bound limits and update the position of bats again.


Step5. Check the condition of pulse rate emission of each bat (r). The factor 0.001 is limits the step size of the random walk.


Find the new value of the objective after check the condition. It is the new fitness value in which the loudness is too much. The loudness and emission rate updated if the new solution is improved which means the bats moving towards the optimal solution. The condition for improve the loudness and pulse emission rate is

(fitnessnew<=fitness(ii)) && (rand<A(ii)) 

Step6. Calculate the best fitness value after optimization. Draw the convergence curve according to the best fitness value and iteration. The best position is also obtained through the optimization.


Step7. Write another script for the observation of benchmark function. Initialize the parameters like N=number of searching Bats, any benchmark function (F1…………F10).

  1. Call the benchmark function- in this step all the bench mark function is called.
  2. Call the BAT function – BAT function is calling in this step. The benchmark function initialize through the bat algorithm.
  3. Call the function plot for graphs and convergence curve for the benchmark function. The best position and best fitness value obtained by using the bat algorithm is shown by the curve.

In the general context of exploration and exploitation as well as genetic operators, we can analyze the roles of the main components of the standard BA. In essence, frequency tuning essentially acts as mutation because it varies the solutions mainly locally. However, if mutation is large enough, it can also leads to global search. Certain selection is carried out by applying a selection pressure that is relatively constant due to the use of the current best solution found so far. Compared with genetic algorithms, there is no explicit crossover; however, mutation varies due to the variations of loudness and pulse emission. On the other hand, the variations of loudness and pulse emission rates can also provide an auto zooming ability in the sense that exploitation becomes intensive as the search is approaching the global optimal. This essentially switches an exploitative phase to an exploitative phase automatically

The graph and curve which are obtained by using the BAT algorithm for the optimization of benchmark function.

BAT Optimization
Parameter space and objective space curve for benchmark function

The left hand side figure shows the parameter space for the benchmark function and right hand side figure shows the objective space of same benchmark function. The objective space curve is between the best fitness obtained value and iterations. The curve shows the minimum value of the objective function during the optimization. As shown in the curve the best fitness value near to 3.

We recommend our users to use the hybrid PSO-GWO optimization algorithm whose code is published here.




admin is an innovative and first of its kind platform created by Vidhilekha Soft Solutions Pvt Ltd, a Startup recognized by the Department For Promotion Of Industry And Internal Trade, Ministry of Commerce and Industry, Government of India recognised innovative research startup.

96 reviews for BAT Optimization Algorithm

  1. anujstaple (verified owner)

    Good Product

  2. admin (verified owner)

    Good Product

  3. Anonymous


  4. frank (verified owner)


  5. frank (verified owner)


  6. frank (verified owner)

    perfect platform

  7. enireddy.vamsidhar (verified owner)

    good site for researchers

  8. bayu permana.sejati (verified owner)

    Good Job

  9. taha.ansar (verified owner)

    Should also give an example

  10. Fawad (verified owner)


  11. venkat.reddy (verified owner)


  12. venkat.reddy (verified owner)


  13. raju.kumar (verified owner)


  14. kaju.kumar (verified owner)


  15. praveen.hipparge (verified owner)


  16. shiffali.goyal (verified owner)


  17. ramahk92 (verified owner)

    Thanks for Providing Code.

  18. alok.kumar (verified owner)

    Thanks for your support.

  19. k.l (verified owner)


  20. sameer.kumthekar (verified owner)


  21. sameer.kumthekar (verified owner)

    best one

  22. preethi.g (verified owner)


  23. treesa.jose (verified owner)


  24. xuexi (verified owner)


  25. javier.carletto (verified owner)


  26. cynthia.joseph (verified owner)


  27. richa.singh (verified owner)


  28. ratheesh.p m (verified owner)

    Very Useful

  29. ratheesh.p m (verified owner)

    Very USeful

  30. ratheesh.p m (verified owner)


  31. ratheesh.p m (verified owner)


  32. ratheesh.p m (verified owner)


  33. ratheesh.p m (verified owner)


  34. nishant.tripathi (verified owner)

    too good

  35. umit.cetinkaya (verified owner)

    It is so good

  36. priya.lollmun (verified owner)


  37. m.m (verified owner)


  38. 1316893612 (verified owner)


  39. otuo.acheampong (verified owner)

    very useful website

  40. otuo.acheampong (verified owner)

    very useful website

  41. daniela.irimia (verified owner)

    Usefull, I hope!

  42. chou_aib (verified owner)


  43. brandon.calder (verified owner)


  44. thiyagarajan.n (verified owner)


  45. thiyagarajan.n (verified owner)


  46. thiyagarajan.n (verified owner)


  47. thiyagarajan.n (verified owner)


  48. kshitiz.varma (verified owner)

    Good Initiative

  49. chou_aib (verified owner)


  50. harshithraj.k m (verified owner)

    its good

  51. karthik.m (verified owner)


  52. vishnupriya.vijayan (verified owner)

    nice job!!!

  53. maria.gonzales huamani (verified owner)

    gracias, de gran ayuda

  54. saranya.gunasekar (verified owner)

    need some additional details

  55. virakwan.kelian (verified owner)


  56. MadhuSudhan Reddy (verified owner)


  57. saranya.gunasekar (verified owner)

    very helpful

  58. anuj.goel (verified owner)

    Thank you !

  59. john.seed (verified owner)


  60. john.seed (verified owner)


  61. omid.mokhlessi (verified owner)

    thank you

  62. omid.mokhlessi (verified owner)

    thank you

  63. omid.mokhlessi (verified owner)

    thank you very much

  64. hamdi.karim (verified owner)


  65. thiyagarajan.n-1218 (verified owner)


  66. thiyagarajan.n-1218 (verified owner)


  67. sumeet (verified owner)


  68. sumeet (verified owner)


  69. sumeet (verified owner)


  70. nenisi.j (verified owner)


  71. zeamari.ilias (verified owner)

    Best Articles are found here.

  72. mohamed.elkhayat (verified owner)


  73. subhashis.kar (verified owner)


  74. rupam.chattopadhyay (verified owner)


  75. sagar.verma (verified owner)


  76. prashant.kulkarni-0716 (verified owner)


  77. mana009 (verified owner)


  78. soumalya_m (verified owner)


  79. lokeshwaran.r (verified owner)


  80. dhivya.k


  81. manishshukla8840 (verified owner)


  82. manishshukla8840 (verified owner)

    na n

  83. manishshukla8840 (verified owner)

    na n

  84. manishshukla8840 (verified owner)

    ZGoog theme but all topics was not covered in this portal

  85. narles.lino (verified owner)

    Great code sharing

  86. jayati.vaish (verified owner)


  87. jayati.vaish (verified owner)


  88. jayati.vaish (verified owner)


  89. aditi (verified owner)

    thankyou for the help

  90. ibrahim.alnaib (verified owner)


  91. ssfd.dsfdsf (verified owner)

    it is ok

  92. Ahussein (verified owner)

    Thank you for your support

  93. Ahussein (verified owner)

    Thank you for your support

  94. anusuya.p (verified owner)


  95. aaa.aaaa (verified owner)


  96. aaa.aaaa (verified owner)


  97. aaa.aaaa (verified owner)


  98. tammisetty.koteswararao (verified owner)

    very helpful

Only logged in customers who have purchased this product may leave a review.