Class: KMeansPP::Cluster
- Inherits:
-
Object
- Object
- KMeansPP::Cluster
- Defined in:
- lib/k_means_pp/cluster.rb
Overview
Cluster has a centroid and a group of related points.
Instance Attribute Summary collapse
-
#centroid ⇒ Centroid
Center of the data set (“centroid”).
-
#points ⇒ Array<Point>
Points in this cluster.
Instance Method Summary collapse
-
#initialize(centroid, points = []) ⇒ Cluster
constructor
Create a new cluster with a centroid and points.
-
#to_s ⇒ Object
A string representation of the cluster.
Constructor Details
#initialize(centroid, points = []) ⇒ Cluster
Create a new cluster with a centroid and points.
18 19 20 21 |
# File 'lib/k_means_pp/cluster.rb', line 18 def initialize(centroid, points = []) self.centroid = centroid self.points = points end |
Instance Attribute Details
#centroid ⇒ Centroid
Center of the data set (“centroid”).
7 8 9 |
# File 'lib/k_means_pp/cluster.rb', line 7 def centroid @centroid end |
#points ⇒ Array<Point>
Points in this cluster.
12 13 14 |
# File 'lib/k_means_pp/cluster.rb', line 12 def points @points end |
Instance Method Details
#to_s ⇒ Object
A string representation of the cluster.
24 25 26 27 28 29 30 |
# File 'lib/k_means_pp/cluster.rb', line 24 def to_s o = '' o << "Cluster #{centroid}: [\n" points.each { |p| o << " #{p},\n" } o << "]\n" o end |