Class: SClust::KMean::Cluster
- Inherits:
-
Object
- Object
- SClust::KMean::Cluster
- Defined in:
- lib/sclust/kmean/cluster.rb
Instance Attribute Summary collapse
-
#center ⇒ Object
readonly
Returns the value of attribute center.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #+(point) ⇒ Object
- #-(point) ⇒ Object
- #get_max_terms(n = 3) ⇒ Object
-
#initialize(centerPoint) ⇒ Cluster
constructor
A new instance of Cluster.
Constructor Details
#initialize(centerPoint) ⇒ Cluster
Returns a new instance of Cluster.
125 126 127 128 129 |
# File 'lib/sclust/kmean/cluster.rb', line 125 def initialize(centerPoint) @fixed = false @center = centerPoint.clone @size = 1 end |
Instance Attribute Details
#center ⇒ Object (readonly)
Returns the value of attribute center.
123 124 125 |
# File 'lib/sclust/kmean/cluster.rb', line 123 def center @center end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
123 124 125 |
# File 'lib/sclust/kmean/cluster.rb', line 123 def size @size end |
Instance Method Details
#+(point) ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/sclust/kmean/cluster.rb', line 131 def +(point) point.cluster = self @size+=1 @center.add(point, 1.0/@size.to_f) end |
#-(point) ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/sclust/kmean/cluster.rb', line 139 def -(point) point.cluster = nil @center.sub(point, 1.0/@size.to_f) @size-=1 end |
#get_max_terms(n = 3) ⇒ Object
147 148 149 |
# File 'lib/sclust/kmean/cluster.rb', line 147 def get_max_terms(n=3) @center.get_max_terms(n) end |