code: def _sample(self, maxIter=1000, c1=1.193, c2=1.193, lookback = 0.25, standard_dev = None):
          
          self._get_fitness(self.swarm)
          i = 0
          self.i = i
          while True:
  
              for particle in self.swarm:
                  if ((self._gbest.fitness)<particle.fitness):
  
                      self._gbest = particle.copy()
  
                  if (particle.fitness > particle.pbest.fitness):
                      particle.updatePBest()
  
              if(i>=maxIter):
                  if self._verbose:
                      print("max iteration reached! stoping")
                  return
  
              if self._func.is_converged:
                  return
  
              if self._converged_likelihood(maxIter*lookback, self._particleCount, standard_dev):
                  return
  
              for particle in self.swarm:
  
                  w = 0.5 + numpy.random.uniform(0, 1, size=self._paramCount) / 2
                  #w=0.72
                  part_vel = w * particle.velocity
                  cog_vel = c1 * numpy.random.uniform(0, 1, size=self._paramCount) * (particle.pbest.position - particle.position)
                  soc_vel = c2 * numpy.random.uniform(0, 1, size=self._paramCount) * (self._gbest.position - particle.position)
                  particle.velocity = part_vel + cog_vel + soc_vel
                  particle.position = particle.position + particle.velocity
  
              self._get_fitness(self.swarm)
  
              swarm = []
              for particle in self.swarm:
                  swarm.append(particle.copy())
              yield swarm
  
              i+=1
              self.i = i
docs: Launches the PSO. Yields the complete swarm per iteration
  
          :param maxIter: maximum iterations
          :param c1: cognitive weight
          :param c2: social weight
          :param lookback: percentange of particles to use when determining convergence
          :param standard_dev: standard deviation of the last lookback particles for convergence