class_docstr: .. include:: /global.rst
  
  Please refer to |pso| for details on this algorithm.
class_docstr_tok: ["..","include",":",":","\/global.rst","Please","refer","to","|pso|","for","details","on","this","algorithm","."]
code: def optimize(self, f, maximize=True, pmap=map):
      @functools.wraps(f)
      def evaluate(d):
          return f(**d)
  
      if maximize:
          fit = 1.0
      else:
          fit = -1.0
  
      pop = [self.generate() for _ in range(self.num_particles)]
      best = None
  
      for g in range(self.num_generations):
          fitnesses = pmap(evaluate, list(map(self.particle2dict, pop)))
          for part, fitness in zip(pop, fitnesses):
              part.fitness = fit * util.score(fitness)
              if not part.best or part.best_fitness < part.fitness:
                  part.best = part.position
                  part.best_fitness = part.fitness
              if not best or best.fitness < part.fitness:
                  best = part.clone()
          for part in pop:
              self.updateParticle(part, best, self.phi1, self.phi2)
  
      return (
          dict(
              [
                  (k, v)
                  for k, v in zip(self.bounds.keys(), best.position)
              ]
          ),
          None,
      )
  
imports: import math
  import operator
  import random
  import array
  import functools
  from .solver_registry import register_solver
  from .util import Solver, _copydoc, uniform_in_bounds
  from .None import util
  from .Sobol import Sobol
label_desc: Use image node_id 16 for calling the ParticleSwarm obj's underlying member method code with example usage: obj.optimize(f, maximize, pmap) and returns: dict,  None, f