docstr: Optimize the swarm for a number of iterations
  
  Performs the optimization to evaluate the objective
  function :code:`f` for a number of iterations :code:`iter.`
  
  Parameters
  ----------
  objective_func : callable
      objective function to be evaluated
  iters : int
      number of iterations
  n_processes : int
      number of processes to use for parallel particle evaluation (default: None = no parallelization)
  verbose : bool
      enable or disable the logs and progress bar (default: True = enable logs)
  kwargs : dict
      arguments for the objective function
  
  Returns
  -------
  tuple
      the local best cost and the local best position among the
      swarm.
docstr_tok: ["Optimize","the","swarm","for","a","number","of","iterations","Performs","the","optimization","to","evaluate","the","objective","function",":","code",":","`","f","`","for","a","number","of","iterations",":","code",":","`","iter.","`","Parameters","--","--","--","--","--","objective_func",":","callable","objective","function","to","be","evaluated","iters",":","int","number","of","iterations","n_processes",":","int","number","of","processes","to","use","for","parallel","particle","evaluation","(","default",":","None","=","no","parallelization",")","verbose",":","bool","enable","or","disable","the","logs","and","progress","bar","(","default",":","True","=","enable","logs",")","kwargs",":","dict","arguments","for","the","objective","function","Returns","--","--","--","-","tuple","the","local","best","cost","and","the","local","best","position","among","the","swarm","."]
code: def optimize(
      self,
      objective_func,
      iters,
      n_processes=None,
      verbose=True,
      **kwargs,
  ):
      """Optimize the swarm for a number of iterations
  
      Performs the optimization to evaluate the objective
      function :code:`f` for a number of iterations :code:`iter.`
  
      Parameters
      ----------
      objective_func : callable
          objective function to be evaluated
      iters : int
          number of iterations
      n_processes : int
          number of processes to use for parallel particle evaluation (default: None = no parallelization)
      verbose : bool
          enable or disable the logs and progress bar (default: True = enable logs)
      kwargs : dict
          arguments for the objective function
  
      Returns
      -------
      tuple
          the local best cost and the local best position among the
          swarm.
      """
      # Apply verbosity
      if verbose:
          log_level = logging.INFO
      else:
          log_level = logging.NOTSET
  
      self.rep.log(
          "Obj. func. args: {}".format(kwargs), lvl=logging.DEBUG
      )
      self.rep.log(
          "Optimize for {} iters with {}".format(iters, self.options),
          lvl=log_level,
      )
      # Populate memory of the handlers
      self.bh.memory = self.swarm.position
      self.vh.memory = self.swarm.position
  
      # Setup Pool of processes for parallel evaluation
      pool = None if n_processes is None else mp.Pool(n_processes)
  
      self.swarm.pbest_cost = np.full(self.swarm_size[0], np.inf)
      ftol_history = deque(maxlen=self.ftol_iter)
      for i in (
          self.rep.pbar(iters, self.name) if verbose else range(iters)
      ):
          # Compute cost for current position and personal best
          self.swarm.current_cost = compute_objective_function(
              self.swarm, objective_func, pool=pool, **kwargs
          )
          self.swarm.pbest_pos, self.swarm.pbest_cost = compute_pbest(
              self.swarm
          )
          best_cost_yet_found = np.min(self.swarm.best_cost)
          # Update gbest from neighborhood
          (
              self.swarm.best_pos,
              self.swarm.best_cost,
          ) = self.top.compute_gbest(self.swarm, p=self.p, k=self.k)
          if verbose:
              self.rep.hook(best_cost=np.min(self.swarm.best_cost))
          # Save to history
          hist = self.ToHistory(
              best_cost=self.swarm.best_cost,
              mean_pbest_cost=np.mean(self.swarm.pbest_cost),
              mean_neighbor_cost=np.mean(self.swarm.best_cost),
              position=self.swarm.position,
              velocity=self.swarm.velocity,
          )
          self._populate_history(hist)
          # Verify stop criteria based on the relative acceptable cost ftol
          relative_measure = self.ftol * (
              1 + np.abs(best_cost_yet_found)
          )
          delta = (
              np.abs(self.swarm.best_cost - best_cost_yet_found)
              < relative_measure
          )
          if i < self.ftol_iter:
              ftol_history.append(delta)
          else:
              ftol_history.append(delta)
              if all(ftol_history):
                  break
          # Perform options update
          self.swarm.options = self.oh(
              self.options, iternow=i, itermax=iters
          )
          # Perform position velocity update
          self.swarm.velocity = self.top.compute_velocity(
              self.swarm, self.velocity_clamp, self.vh, self.bounds
          )
          self.swarm.position = self.top.compute_position(
              self.swarm, self.bounds, self.bh
          )
      # Obtain the final best_cost and the final best_position
      final_best_cost = self.swarm.best_cost.copy()
      final_best_pos = self.swarm.pbest_pos[
          self.swarm.pbest_cost.argmin()
      ].copy()
      # Write report in log and return final cost and position
      self.rep.log(
          "Optimization finished | best cost: {}, best pos: {}".format(
              final_best_cost, final_best_pos
          ),
          lvl=log_level,
      )
      # Close Pool of Processes
      if n_processes is not None:
          pool.close()
      return (final_best_cost, final_best_pos)
  
file_path: pyswarms/pyswarms/single/local_best.py
imports: import logging
  import numpy
  import multiprocessing
  from collections import deque
  from ..backend.operators import compute_pbest, compute_objective_function
  from ..backend.topology import Ring
  from ..backend.handlers import BoundaryHandler, VelocityHandler, OptionsHandler
  from ..base import SwarmOptimizer
  from ..utils.reporter import Reporter
label_desc: Use image node_id 2 for calling the LocalBestPSO obj's underlying member method code with example usage: obj.optimize(objective_func, iters, n_processes, verbose) and returns: final_best_cost,  final_best_pos