class_docstr: A BA class, inherited from Optimizer.
  
  This is the designed class to define BA-related
  variables and methods.
  
  References:
      X.-S. Yang. A new metaheuristic bat-inspired algorithm.
      Nature inspired cooperative strategies for optimization (2010).
docstr: Wraps Bat Algorithm over all agents and variables.
  
  Args:
      space: Space containing agents and update-related information.
      function: A Function object that will be used as the objective function.
      iteration: Current iteration.
docstr_tok: ["Wraps","Bat","Algorithm","over","all","agents","and","variables",".","Args",":","space",":","Space","containing","agents","and","update-related","information",".","function",":","A","Function","object","that","will","be","used","as","the","objective","function",".","iteration",":","Current","iteration","."]
code: def update(
      self, space: Space, function: Function, iteration: int
  ) -> None:
      """Wraps Bat Algorithm over all agents and variables.
  
      Args:
          space: Space containing agents and update-related information.
          function: A Function object that will be used as the objective function.
          iteration: Current iteration.
  
      """
  
      alpha = 0.9
  
      for i, agent in enumerate(space.agents):
          # Updates frequency (eq. 2)
          # Note that we have to apply (min - max) instead of (max - min) or it will not converge
          beta = rnd.generate_uniform_random_number()
          self.frequency[i] = (
              self.f_min + (self.f_min - self.f_max) * beta
          )
  
          # Updates velocity (eq. 3)
          self.velocity[i] += (
              agent.position - space.best_agent.position
          ) * self.frequency[i]
  
          # Updates agent's position (eq. 4)
          agent.position += self.velocity[i]
  
          p = rnd.generate_uniform_random_number()
          e = rnd.generate_gaussian_random_number()
          if p > self.pulse_rate[i]:
              # Performs a local random walk (eq. 5)
              # We apply 0.001 to limit the step size
              agent.position = (
                  space.best_agent.position
                  + 0.001 * e * np.mean(self.loudness)
              )
          agent.clip_by_bound()
  
          agent.fit = function(agent.position)
          if p < self.loudness[i] and agent.fit < space.best_agent.fit:
              space.best_agent = copy.deepcopy(agent)
  
              # Increasing pulse rate (eq. 6 - left)
              self.pulse_rate[i] = self.r * (
                  1 - np.exp(-alpha * iteration)
              )
  
              # Decreasing loudness (eq. 6 - right)
              self.loudness[i] = self.A * alpha
  
imports: import copy
  from typing import Any, Dict, Optional
  import numpy
  import opytimizer.math.random
  import opytimizer.utils.exception
  from opytimizer.core import Optimizer
  from opytimizer.core.function import Function
  from opytimizer.core.space import Space
  from opytimizer.utils import logging
label_desc: Use image node_id 19 for calling the BA obj's underlying member method code with example usage: obj.update(space, function, iteration) without return types