Sha256: 01d7094d8831f64d34951a40c4e5e8ea1b9016f4f5c3881557389f267fb0bd80
Contents?: true
Size: 1.48 KB
Versions: 1
Compression:
Stored size: 1.48 KB
Contents
# For more information see https://en.wikipedia.org/wiki/DBSCAN module DbClustering module Algorithms class Dbscan attr_accessor :datasource, :clusters def initialize(datasource:, distance_metric:) @datasource = datasource @distance_metric = distance_metric @clusters = [] end def cluster(max_distance:, min_neighbors:, debug: false) @clusters = [] cluster = nil @datasource.iterate_all_points do |point, current_index, points_count| neighbors = @datasource.neighbors(point: point, distance_metric: @distance_metric, max_distance: max_distance) if neighbors.count < min_neighbors point.is_noise = true else if point.cluster.nil? cluster = DbClustering::Models::Cluster.new @clusters << cluster else cluster = point.cluster end neighbors.each do |neighbor| if neighbor.cluster.nil? cluster.add(neighbor) if debug print "+" end # add the neighbors of the neighbor to the neighbors to fully expand the cluster neighbors |= @datasource.neighbors(point: neighbor, distance_metric: @distance_metric, max_distance: max_distance) end end end yield(point, current_index, points_count) if block_given? end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
db_clustering-0.1.12 | lib/algorithms/density_based/dbscan.rb |