Beispiel #1
0
 def set_best(self):
     self._best_fitness = Fitness.calculate(self.best_position)
     for particle in self.swarm:
         this_fitness = Fitness.calculate(particle.position)
         if this_fitness < self._best_fitness:
             self._best_fitness = this_fitness
             self.best_position = copy.deepcopy(particle.position)
Beispiel #2
0
 def __init__(self, position):
     self._position = position
     self._dimensions = len(position)
     self._best_position = position
     self._best_fitness = Fitness.calculate(position)
     self._velocity = [
         self.get_random_velocity() for _ in range(self._dimensions)
     ]
Beispiel #3
0
 def _update_best_position(self):
     new_fitness = Fitness.calculate(self._position)
     if new_fitness < self._best_fitness:
         self._best_fitness = new_fitness
         self._best_position = self._position