class_docstr: Do PSO (Particle swarm optimization) algorithm.
  
  This algorithm was adapted from the earlier works of J. Kennedy and
  R.C. Eberhart in Particle Swarm Optimization [IJCNN1995]_.
  
  The position update can be defined as:
  
  .. math::
  
     x_{i}(t+1) = x_{i}(t) + v_{i}(t+1)
  
  Where the position at the current step :math:`t` is updated using
  the computed velocity at :math:`t+1`. Furthermore, the velocity update
  is defined as:
  
  .. math::
  
     v_{ij}(t + 1) = w * v_{ij}(t) + c_{p}r_{1j}(t)[y_{ij}(t) − x_{ij}(t)]
                     + c_{g}r_{2j}(t)[\hat{y}_{j}(t) − x_{ij}(t)]
  
  Here, :math:`cp` and :math:`cg` are the cognitive and social parameters
  respectively. They control the particle's behavior given two choices: (1) to
  follow its *personal best* or (2) follow the swarm's *global best* position.
  Overall, this dictates if the swarm is explorative or exploitative in nature.
  In addition, a parameter :math:`w` controls the inertia of the swarm's
  movement.
  
  .. [IJCNN1995] J. Kennedy and R.C. Eberhart, "Particle Swarm Optimization,"
  Proceedings of the IEEE International Joint Conference on Neural
  Networks, 1995, pp. 1942-1948.
  
  Parameters
  --------------------
  func : function
      The func you want to do optimal
  dim : int
      Number of dimension, which is number of parameters of func.
  pop : int
      Size of population, which is the number of Particles. We use 'pop' to keep accordance with GA
  max_iter : int
      Max of iter iterations
  lb : array_like
      The lower bound of every variables of func
  ub : array_like
      The upper bound of every variables of func
  constraint_eq : tuple
      equal constraint. Note: not available yet.
  constraint_ueq : tuple
      unequal constraint
  n_processes : int
      Number of processes, 0 means use all cpu
  Attributes
  ----------------------
  pbest_x : array_like, shape is (pop,dim)
      best location of every particle in history
  pbest_y : array_like, shape is (pop,1)
      best image of every particle in history
  gbest_x : array_like, shape is (1,dim)
      general best location for all particles in history
  gbest_y : float
      general best image  for all particles in history
  gbest_y_hist : list
      gbest_y of every iteration
  
  
  Examples
  -----------------------------
  see https://scikit-opt.github.io/scikit-opt/#/en/README?id=_3-psoparticle-swarm-optimization
class_docstr_tok: ["Do","PSO","(","Particle","swarm","optimization",")","algorithm",".","This","algorithm","was","adapted","from","the","earlier","works","of","J.","Kennedy","and","R.C",".","Eberhart","in","Particle","Swarm","Optimization","[","IJCNN1995","]","_",".","The","position","update","can","be","defined","as",":","..","math",":",":","x_","{","i","}","(","t+1",")","=","x_","{","i","}","(","t",")","+","v_","{","i","}","(","t+1",")","Where","the","position","at","the","current","step",":","math",":","`","t","`","is","updated","using","the","computed","velocity","at",":","math",":","`","t+1","`",".","Furthermore",",","the","velocity","update","is","defined","as",":","..","math",":",":","v_","{","ij","}","(","t","+","1",")","=","w","*","v_","{","ij","}","(","t",")","+","c_","{","p","}","r_","{","1j","}","(","t",")","[","y_","{","ij","}","(","t",")","\u2212","x_","{","ij","}","(","t",")","]","+","c_","{","g","}","r_","{","2j","}","(","t",")","[","\\hat","{","y","}","_","{","j","}","(","t",")","\u2212","x_","{","ij","}","(","t",")","]","Here",",",":","math",":","`","cp","`","and",":","math",":","`","cg","`","are","the","cognitive","and","social","parameters","respectively",".","They","control","the","particle","'s","behavior","given","two","choices",":","(","1",")","to","follow","its","*","personal","best","*","or","(","2",")","follow","the","swarm","'s","*","global","best","*","position",".","Overall",",","this","dictates","if","the","swarm","is","explorative","or","exploitative","in","nature",".","In","addition",",","a","parameter",":","math",":","`","w","`","controls","the","inertia","of","the","swarm's","movement",".","..","[","IJCNN1995","]","J.","Kennedy","and","R.C",".","Eberhart",",","``","Particle","Swarm","Optimization",",","''","Proceedings","of","the","IEEE","International","Joint","Conference","on","Neural","Networks",",","1995",",","pp",".","1942-1948",".","Parameters","--","--","--","--","--","--","--","--","--","--","func",":","function","The","func","you","want","to","do","optimal","dim",":","int","Number","of","dimension",",","which","is","number","of","parameters","of","func",".","pop",":","int","Size","of","population",",","which","is","the","number","of","Particles",".","We","use","'pop","'","to","keep","accordance","with","GA","max_iter",":","int","Max","of","iter","iterations","lb",":","array_like","The","lower","bound","of","every","variables","of","func","ub",":","array_like","The","upper","bound","of","every","variables","of","func","constraint_eq",":","tuple","equal","constraint",".","Note",":","not","available","yet",".","constraint_ueq",":","tuple","unequal","constraint","n_processes",":","int","Number","of","processes",",","0","means","use","all","cpu","Attributes","--","--","--","--","--","--","--","--","--","--","--","pbest_x",":","array_like",",","shape","is","(","pop",",","dim",")","best","location","of","every","particle","in","history","pbest_y",":","array_like",",","shape","is","(","pop,1",")","best","image","of","every","particle","in","history","gbest_x",":","array_like",",","shape","is","(","1",",","dim",")","general","best","location","for","all","particles","in","history","gbest_y",":","float","general","best","image","for","all","particles","in","history","gbest_y_hist",":","list","gbest_y","of","every","iteration","Examples","--","--","--","--","--","--","--","--","--","--","--","--","--","--","-","see","https",":","\/\/scikit-opt.github.io\/scikit-opt\/","#","\/en\/README","?","id=_3-psoparticle-swarm-optimization"]
docstr: precision: None or float
      If precision is None, it will run the number of max_iter steps
      If precision is a float, the loop will stop if continuous N difference between pbest less than precision
  N: int
docstr_tok: ["precision",":","None","or","float","If","precision","is","None",",","it","will","run","the","number","of","max_iter","steps","If","precision","is","a","float",",","the","loop","will","stop","if","continuous","N","difference","between","pbest","less","than","precision","N",":","int"]
code: def run(self, max_iter=None, precision=None, N=20):
      """
      precision: None or float
          If precision is None, it will run the number of max_iter steps
          If precision is a float, the loop will stop if continuous N difference between pbest less than precision
      N: int
      """
      self.max_iter = max_iter or self.max_iter
      c = 0
      for iter_num in range(self.max_iter):
          self.update_V()
          self.recorder()
          self.update_X()
          self.cal_y()
          self.update_pbest()
          self.update_gbest()
          if precision is not None:
              tor_iter = np.amax(self.pbest_y) - np.amin(self.pbest_y)
              if tor_iter < precision:
                  c = c + 1
                  if c > N:
                      break
              else:
                  c = 0
          if self.verbose:
              print(
                  "Iter: {}, Best fit: {} at {}".format(
                      iter_num, self.gbest_y, self.gbest_x
                  )
              )
  
          self.gbest_y_hist.append(self.gbest_y)
      self.best_x, self.best_y = self.gbest_x, self.gbest_y
      return self.best_x, self.best_y
  
imports: import numpy
  from sko.tools import func_transformer
  from .base import SkoBase
  from .operators import crossover, mutation, ranking, selection
  from .operators import mutation
label_desc: Use image node_id 9 for calling the PSO obj's underlying member method code with example usage: obj.run(max_iter, precision, N) and returns: self,  self