docstr: Initialize the swarm
  
  Attributes
  ----------
  n_particles : int
      number of particles in the swarm.
  dimensions : int
      number of dimensions in the space.
  options : dict with keys :code:`{'c1', 'c2', 'w', 'k', 'p'}`
      a dictionary containing the parameters for the specific
      optimization technique
          * c1 : float
              cognitive parameter
          * c2 : float
              social parameter
          * w : float
              inertia parameter
          * k : int
              number of neighbors to be considered. Must be a
              positive integer less than :code:`n_particles`
          * p: int {1,2}
              the Minkowski p-norm to use. 1 is the
              sum-of-absolute values (or L1 distance) while 2 is
              the Euclidean (or L2) distance.
  init_pos : numpy.ndarray, optional
      option to explicitly set the particles' initial positions. Set to
      :code:`None` if you wish to generate the particles randomly.
  velocity_clamp : tuple, optional
      a tuple of size 2 where the first entry is the minimum velocity
      and the second entry is the maximum velocity. It
      sets the limits for velocity clamping.
  vh_strategy : String
      a strategy for the handling of the velocity of out-of-bounds particles.
      Only the "unmodified" and the "adjust" strategies are allowed.
  ftol : float
      relative error in objective_func(best_pos) acceptable for
      convergence
  ftol_iter : int
      number of iterations over which the relative error in
      objective_func(best_pos) is acceptable for convergence.
      Default is :code:`1`
docstr_tok: ["Initialize","the","swarm","Attributes","--","--","--","--","--","n_particles",":","int","number","of","particles","in","the","swarm",".","dimensions",":","int","number","of","dimensions","in","the","space",".","options",":","dict","with","keys",":","code",":","`","{","'c1","'",",","'c2","'",",","'","w","'",",","'","k","'",",","'","p","'","}","`","a","dictionary","containing","the","parameters","for","the","specific","optimization","technique","*","c1",":","float","cognitive","parameter","*","c2",":","float","social","parameter","*","w",":","float","inertia","parameter","*","k",":","int","number","of","neighbors","to","be","considered",".","Must","be","a","positive","integer","less","than",":","code",":","`","n_particles","`","*","p",":","int","{","1,2","}","the","Minkowski","p-norm","to","use",".","1","is","the","sum-of-absolute","values","(","or","L1","distance",")","while","2","is","the","Euclidean","(","or","L2",")","distance",".","init_pos",":","numpy.ndarray",",","optional","option","to","explicitly","set","the","particles","'","initial","positions",".","Set","to",":","code",":","`","None","`","if","you","wish","to","generate","the","particles","randomly",".","velocity_clamp",":","tuple",",","optional","a","tuple","of","size","2","where","the","first","entry","is","the","minimum","velocity","and","the","second","entry","is","the","maximum","velocity",".","It","sets","the","limits","for","velocity","clamping",".","vh_strategy",":","String","a","strategy","for","the","handling","of","the","velocity","of","out-of-bounds","particles",".","Only","the","``","unmodified","''","and","the","``","adjust","''","strategies","are","allowed",".","ftol",":","float","relative","error","in","objective_func","(","best_pos",")","acceptable","for","convergence","ftol_iter",":","int","number","of","iterations","over","which","the","relative","error","in","objective_func","(","best_pos",")","is","acceptable","for","convergence",".","Default","is",":","code",":","`","1","`"]
code: def __init__(
      self,
      n_particles,
      dimensions,
      options,
      init_pos=None,
      velocity_clamp=None,
      vh_strategy="unmodified",
      ftol=-np.inf,
      ftol_iter=1,
  ):
      """Initialize the swarm
  
      Attributes
      ----------
      n_particles : int
          number of particles in the swarm.
      dimensions : int
          number of dimensions in the space.
      options : dict with keys :code:`{'c1', 'c2', 'w', 'k', 'p'}`
          a dictionary containing the parameters for the specific
          optimization technique
              * c1 : float
                  cognitive parameter
              * c2 : float
                  social parameter
              * w : float
                  inertia parameter
              * k : int
                  number of neighbors to be considered. Must be a
                  positive integer less than :code:`n_particles`
              * p: int {1,2}
                  the Minkowski p-norm to use. 1 is the
                  sum-of-absolute values (or L1 distance) while 2 is
                  the Euclidean (or L2) distance.
      init_pos : numpy.ndarray, optional
          option to explicitly set the particles' initial positions. Set to
          :code:`None` if you wish to generate the particles randomly.
      velocity_clamp : tuple, optional
          a tuple of size 2 where the first entry is the minimum velocity
          and the second entry is the maximum velocity. It
          sets the limits for velocity clamping.
      vh_strategy : String
          a strategy for the handling of the velocity of out-of-bounds particles.
          Only the "unmodified" and the "adjust" strategies are allowed.
      ftol : float
          relative error in objective_func(best_pos) acceptable for
          convergence
      ftol_iter : int
          number of iterations over which the relative error in
          objective_func(best_pos) is acceptable for convergence.
          Default is :code:`1`
      """
      # Initialize logger
      self.rep = Reporter(logger=logging.getLogger(__name__))
      # Assign k-neighbors and p-value as attributes
      self.k, self.p = options["k"], options["p"]
      # Initialize parent class
      super(BinaryPSO, self).__init__(
          n_particles=n_particles,
          dimensions=dimensions,
          binary=True,
          options=options,
          init_pos=init_pos,
          velocity_clamp=velocity_clamp,
          ftol=ftol,
          ftol_iter=ftol_iter,
      )
      # Initialize the resettable attributes
      self.reset()
      # Initialize the topology
      self.top = Ring(static=False)
      self.vh = VelocityHandler(strategy=vh_strategy)
      self.name = __name__
  
file_path: pyswarms/pyswarms/discrete/binary.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
  from ..base import DiscreteSwarmOptimizer
  from ..utils.reporter import Reporter
label_desc: Use image node_id 1 to create a new BinaryPSO object from inherited base classes: DiscreteSwarmOptimizer with example: obj = BinaryPSO(n_particles, dimensions, options, init_pos, velocity_clamp, vh_strategy, ftol, ftol_iter)