Class: SameSame::DbscanNeighborhood
- Inherits:
-
Object
- Object
- SameSame::DbscanNeighborhood
- Defined in:
- lib/same_same/dbscan_neighborhood.rb
Instance Attribute Summary collapse
-
#adjacency_matrix ⇒ Object
Contains distances between points.
-
#eps ⇒ Object
Threshold value.
-
#index_mapping ⇒ Object
used to cache index of points in the matrix.
-
#points ⇒ Object
Returns the value of attribute points.
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ DbscanNeighborhood
constructor
Initializes algorithm with all data that it needs.
- #neighbors_of(p) ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ DbscanNeighborhood
Initializes algorithm with all data that it needs.
* points - points to cluster
* eps - distance threshold value
* minPoints - number of neighbors for point to be considered a core point.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/same_same/dbscan_neighborhood.rb', line 21 def initialize(attrs = {}) self.eps = attrs.fetch(:eps) self.points = attrs.fetch(:points) build_index_mapping vector_calculator = attrs[:vector_calculator] || DbscanNumericVectors.new distance = attrs.fetch( :distance ) use_term_frequencies = attrs[:use_term_frequencies] || false self.adjacency_matrix = calculate_adjacency_matrix(distance, points, vector_calculator) end |
Instance Attribute Details
#adjacency_matrix ⇒ Object
Contains distances between points.
4 5 6 |
# File 'lib/same_same/dbscan_neighborhood.rb', line 4 def adjacency_matrix @adjacency_matrix end |
#eps ⇒ Object
Threshold value. Determines which points will be considered as neighbors. Two points are neighbors if the distance between them does not exceed threshold value.
9 10 11 |
# File 'lib/same_same/dbscan_neighborhood.rb', line 9 def eps @eps end |
#index_mapping ⇒ Object
used to cache index of points in the matrix
12 13 14 |
# File 'lib/same_same/dbscan_neighborhood.rb', line 12 def index_mapping @index_mapping end |
#points ⇒ Object
Returns the value of attribute points.
14 15 16 |
# File 'lib/same_same/dbscan_neighborhood.rb', line 14 def points @points end |
Instance Method Details
#neighbors_of(p) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/same_same/dbscan_neighborhood.rb', line 35 def neighbors_of( p ) Set.new.tap do |neighbors| i = index_mapping[p] (0..index_mapping.size-1).each do |j| neighbors.add(points[j]) if adjacency_matrix.lookup(i,j) <= eps end end end |