Class: SameSame::LinkMatrix

Inherits:
Object
  • Object
show all
Defined in:
lib/same_same/link_matrix.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ LinkMatrix

Returns a new instance of LinkMatrix.



5
6
7
8
9
10
11
12
13
# File 'lib/same_same/link_matrix.rb', line 5

def initialize( attrs = {} )
  similarity_matrix = attrs.fetch(:similarity_matrix)
  datapoints        = attrs.fetch(:datapoints)
  th                = attrs.fetch(:th)
  neighbours        = calculate_neighbours( datapoints, similarity_matrix, th )

  @links             = calculate_links( neighbours, datapoints )
  @index_lookup      = calculate_index_lookup( datapoints )
end

Instance Attribute Details

#index_lookupObject (readonly)

Returns the value of attribute index_lookup.



3
4
5
# File 'lib/same_same/link_matrix.rb', line 3

def index_lookup
  @index_lookup
end

Returns the value of attribute links.



3
4
5
# File 'lib/same_same/link_matrix.rb', line 3

def links
  @links
end

Instance Method Details



15
16
17
18
19
20
21
# File 'lib/same_same/link_matrix.rb', line 15

def count_links_between_clusters( cluster1, cluster2 )
  cluster1.inject(0) do |sum, p1|
    cluster2.inject(sum) do |sum2, p2|
      sum2 + number_of_links_between_points(p1, p2)
    end
  end
end


23
24
25
# File 'lib/same_same/link_matrix.rb', line 23

def number_of_links_between_points( datapoint1, datapoint2 )
  links.lookup( index_lookup[datapoint1], index_lookup[datapoint2] )
end