Skip to content

Commit

Permalink
add a cluster.remove() method for convenience when creating derived a…
Browse files Browse the repository at this point in the history
…lgorithms
  • Loading branch information
craigds committed Oct 27, 2011
1 parent 6e3de9f commit 147e8ec
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pygvm/__init__.py
Expand Up @@ -76,6 +76,19 @@ def add_cluster(self, cluster):
"""
self.add(cluster.mass, cluster.center(), cluster.members)

def remove(self, mass, coords, members):
"""
Removes a point from the cluster.
This is not strictly needed for GVM, as members are never removed,
but it may be useful for creating derivative algorithms.
"""
self.mass -= mass
for i, coord in enumerate(coords):
self.m1[i] -= coord * mass
self.m2[i] -= coord * mass * mass
self.members.difference_update(members)
self.update()

def test(self, mass, coords):
"""
Computes the change in this clusters variance if it were to have a new point added to it.
Expand Down

0 comments on commit 147e8ec

Please sign in to comment.