Class: Clusterer::Clustering

Inherits:
Object
  • Object
show all
Defined in:
lib/clusterer/clustering.rb

Class Method Summary collapse

Class Method Details

.cluster(algorithm, objects, options = { }) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/clusterer/clustering.rb', line 26

def cluster(algorithm, objects, options = { })
  options[:no_of_clusters] ||= Math.sqrt(objects.size).to_i
  idf = InverseDocumentFrequency.new
  docs = objects.collect {|o|
    (defined? yield) == "yield" ? Document.new(o, options.merge(:idf => idf)) {|o| yield(o)} : Document.new(o, options.merge(:idf => idf))}
  Algorithms.send(algorithm, docs.collect {|d| d.normalize!(idf) }, options[:no_of_clusters])
end