Class: SameSame::LinkMatrix
- Inherits:
-
Object
- Object
- SameSame::LinkMatrix
- Defined in:
- lib/same_same/link_matrix.rb
Instance Attribute Summary collapse
-
#index_lookup ⇒ Object
readonly
Returns the value of attribute index_lookup.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
Instance Method Summary collapse
- #count_links_between_clusters(cluster1, cluster2) ⇒ Object
-
#initialize(attrs = {}) ⇒ LinkMatrix
constructor
A new instance of LinkMatrix.
- #number_of_links_between_points(datapoint1, datapoint2) ⇒ Object
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_lookup ⇒ Object (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 |
#links ⇒ Object (readonly)
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
#count_links_between_clusters(cluster1, cluster2) ⇒ Object
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 |
#number_of_links_between_points(datapoint1, datapoint2) ⇒ Object
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 |