Class: Clusterer::DocumentsCentroidVector
- Inherits:
-
Object
- Object
- Clusterer::DocumentsCentroidVector
- Defined in:
- lib/clusterer/lsi/documents_centroid_vector.rb
Instance Attribute Summary collapse
-
#centroid ⇒ Object
readonly
Returns the value of attribute centroid.
-
#no_of_documents ⇒ Object
readonly
Returns the value of attribute no_of_documents.
Instance Method Summary collapse
-
#initialize(docs = []) ⇒ DocumentsCentroidVector
constructor
A new instance of DocumentsCentroidVector.
- #merge!(centroid) ⇒ Object
- #to_dmatrix ⇒ Object
Constructor Details
#initialize(docs = []) ⇒ DocumentsCentroidVector
Returns a new instance of DocumentsCentroidVector.
28 29 30 31 32 33 34 |
# File 'lib/clusterer/lsi/documents_centroid_vector.rb', line 28 def initialize(docs = []) @no_of_documents = docs.size return if @no_of_documents == 0 @centroid = docs[0] docs.slice(1..docs.length).each {|d| @centroid = @centroid + d} @centroid = @centroid / @no_of_documents end |
Instance Attribute Details
#centroid ⇒ Object (readonly)
Returns the value of attribute centroid.
26 27 28 |
# File 'lib/clusterer/lsi/documents_centroid_vector.rb', line 26 def centroid @centroid end |
#no_of_documents ⇒ Object (readonly)
Returns the value of attribute no_of_documents.
25 26 27 |
# File 'lib/clusterer/lsi/documents_centroid_vector.rb', line 25 def no_of_documents @no_of_documents end |
Instance Method Details
#merge!(centroid) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/clusterer/lsi/documents_centroid_vector.rb', line 40 def merge!(centroid) return unless centroid.centroid unless @centroid @centroid = centroid.centroid @no_of_documents = centroid.no_of_documents else @centroid = (@centroid * @no_of_documents) + (centroid.centroid * centroid.no_of_documents) @centroid = @centroid / (@no_of_documents += centroid.no_of_documents) end end |
#to_dmatrix ⇒ Object
36 37 38 |
# File 'lib/clusterer/lsi/documents_centroid_vector.rb', line 36 def to_dmatrix @centroid end |