Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

kmeans working now (correct clustering)

  • Loading branch information...
commit dd0071678de4bb842b4d068bd9da8787a6931901 1 parent 7e7f44a
@thomasjungblut authored
Showing with 3 additions and 3 deletions.
  1. +3 −3 KMeansBSP.py
View
6 KMeansBSP.py
@@ -58,7 +58,7 @@ def getNearestCenter(self, vector):
lowest = float("inf")
for i in range(self.numCenters):
dist = self.distance(vector, self.centers[i])
- if lowest < dist:
+ if lowest > dist:
lowest = dist
lowestIndex = i
return lowestIndex
@@ -71,7 +71,7 @@ def assignCentersInternal(self, newCenterArray, summationCount, vector):
newCenterArray[lowestCenterIndex] = center
summationCount[lowestCenterIndex] = 0
else:
- self.sum(newCenterArray[lowestCenterIndex], vector)
+ newCenterArray[lowestCenterIndex] = self.sum(newCenterArray[lowestCenterIndex], vector)
summationCount[lowestCenterIndex] += 1
@@ -118,7 +118,7 @@ def recalculateAssignmentsAndWrite(self, peer):
line = peer.readNext()
if not line: break
lowestDistantCenter = self.getNearestCenter(self.toVector(line[1]))
- peer.write(str(lowestDistantCenter), self.centers[lowestDistantCenter])
+ peer.write(str(lowestDistantCenter), line[1])
pass
Please sign in to comment.
Something went wrong with that request. Please try again.