Permalink
Browse files

some cleaning

  • Loading branch information...
1 parent 80000ae commit b360930b60f0756105947492ebc20d20a946bb4c @retran committed May 20, 2012
Showing with 2 additions and 3 deletions.
  1. +2 −3 clusterization/kmeans.rb
View
5 clusterization/kmeans.rb
@@ -1,6 +1,5 @@
#!/usr/bin/env ruby -wKU
-require "csv"
require "../common/data.rb"
def distance(a, b)
@@ -15,7 +14,7 @@ def get_nearest_center(point, centers)
centers.min_by { |c| distance(point, c) }
end
-def arrange(points, centers)
+def clusterize(points, centers)
(points.group_by { |p| get_nearest_center(p, centers) }).values
end
@@ -26,7 +25,7 @@ def nearly?(a, b, epsilon)
def kmeans(points, nclusters, epsilon)
centers = points.sample(nclusters)
- clusters = arrange(points, centers)
+ clusters = clusterize(points, centers)
new_centers = nil
while not nearly?(centers, new_centers, epsilon)
centers = new_centers

0 comments on commit b360930

Please sign in to comment.