Skip to content

Instantly share code, notes, and snippets.

@tarlanahad
Created January 16, 2020 10:45
Show Gist options
  • Save tarlanahad/f57976843080678eba8a7d0fd535b9cd to your computer and use it in GitHub Desktop.
Save tarlanahad/f57976843080678eba8a7d0fd535b9cd to your computer and use it in GitHub Desktop.
class Particle:
def __init__(self, dim, minx, maxx):
self.position = np.random.uniform(low=minx, high=maxx, size=dim)
self.velocity = np.random.uniform(low=minx, high=maxx, size=dim)
self.best_part_pos = self.position.copy()
self.error = error(self.position)
self.best_part_err = self.error.copy()
def setPos(self, pos):
self.position = pos
self.error = error(pos)
if self.error < self.best_part_err:
self.best_part_err = self.error
self.best_part_pos = pos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment