Skip to content

Instantly share code, notes, and snippets.

@kalelc
Created October 20, 2016 13:36
Show Gist options
  • Save kalelc/8582ca30853eb596ba55fddffa1603cd to your computer and use it in GitHub Desktop.
Save kalelc/8582ca30853eb596ba55fddffa1603cd to your computer and use it in GitHub Desktop.
module Kmeans
class Cluster
attr_accessor :centroid, :points
def initialize(centroid)
@centroid = centroid
@points = []
end
def centroid!
xa = ya = 0
old_centroid = @centroid
@points.each do |point|
xa += point.x
ya += point.y
end
xa /= points.length
ya /= points.length
@centroid = Point.new(xa, ya)
#puts old_centroid.to_a
#puts @centroid.to_a
return GpsWaypoints.distance(old_centroid.to_a,centroid.to_a)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment