Module: Clusterer::ClusterSimilarity

Included in:
Cluster
Defined in:
lib/clusterer/similarity.rb

Instance Method Summary collapse

Instance Method Details

#centroid_similarity(y) ⇒ Object



24
25
26
# File 'lib/clusterer/similarity.rb', line 24

def centroid_similarity(y)
  self.centroid.cosine_similarity(y.centroid)
end

#intra_cluster_similarity(y) ⇒ Object

the algorithms given below find similarity between two clusters



20
21
22
# File 'lib/clusterer/similarity.rb', line 20

def intra_cluster_similarity(y)
  (self+y).intra_cluster_cosine_similarity - self.intra_cluster_cosine_similarity - y.intra_cluster_cosine_similarity
end

#upgma(y) ⇒ Object



28
29
30
31
32
# File 'lib/clusterer/similarity.rb', line 28

def upgma(y)
  self.documents.inject(0) do |n,d|
    n + y.documents.inject(0) {|s,e| s + d.cosine_similarity(e) }
  end / (self.documents.size * y.documents.size)
end