Class: SClust::KMean::Cluster

Inherits:
Object
  • Object
show all
Defined in:
lib/sclust/kmean/cluster.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#centerObject (readonly)

Returns the value of attribute center.



123
124
125
# File 'lib/sclust/kmean/cluster.rb', line 123

def center
  @center
end

#sizeObject (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