Open mgiraldo opened 10 years ago
Let me check this, it's an old codebase, I don't remember!
I see. do you know if there's a more recent implementation?
On Jul 24, 2014, at 18:04, Matias Insaurralde notifications@github.com wrote:
Let me check this, it's an old codebase, I don't remember!
— Reply to this email directly or view it on GitHub.
I remembered the "labels" option, is this useful for you?
require 'dbscan'
input = [ 0, 10, 20 ],
[ 0, 11, 21 ],
[ 0, 12, 20 ],
[ 20, 33, 59 ],
[ 21, 32, 56 ],
[ 59, 77, 101 ],
[ 58, 79, 100 ],
[ 58, 76, 102 ],
[ 300, 70, 20 ],
[ 500, 300, 202],
[ 500, 302, 204 ]
dbscan = DBSCAN( input,
:epsilon => 4,
:min_points => 1,
:distance => :euclidean_distance,
:labels => ['a', 'b', 'c', 'd', 'e', 'f','g', 'h', 'i', 'j', 'k'] )
dbscan.clusters.each do |cluster_id, points|
puts "Cluster #{cluster_id}"
points.each do |point|
p point
end
puts
end
Outputs:
Cluster -1
#<DBSCAN::Point:0x007f896a0c9b58 @items=[300, 70, 20], @cluster=nil, @visited=true, @label="i">
Cluster 0
#<DBSCAN::Point:0x007f896a0c9ea0 @items=[0, 10, 20], @cluster=0, @visited=true, @label="a">
#<DBSCAN::Point:0x007f896a0c9e50 @items=[0, 11, 21], @cluster=0, @visited=true, @label="b">
#<DBSCAN::Point:0x007f896a0c9e00 @items=[0, 12, 20], @cluster=0, @visited=true, @label="c">
Cluster 1
#<DBSCAN::Point:0x007f896a0c9db0 @items=[20, 33, 59], @cluster=1, @visited=true, @label="d">
#<DBSCAN::Point:0x007f896a0c9cc0 @items=[21, 32, 56], @cluster=1, @visited=true, @label="e">
Cluster 2
#<DBSCAN::Point:0x007f896a0c9c70 @items=[59, 77, 101], @cluster=2, @visited=true, @label="f">
#<DBSCAN::Point:0x007f896a0c9c20 @items=[58, 79, 100], @cluster=2, @visited=true, @label="g">
#<DBSCAN::Point:0x007f896a0c9bd0 @items=[58, 76, 102], @cluster=2, @visited=true, @label="h">
Cluster 3
#<DBSCAN::Point:0x007f896a0c9b08 @items=[500, 300, 202], @cluster=3, @visited=true, @label="j">
#<DBSCAN::Point:0x007f896a0c9a90 @items=[500, 302, 204], @cluster=3, @visited=true, @label="k">
will look into that
thanks!
Is it possible to cluster a hash like
{:name => "Foo", :coords => [0,1]}
?I'd like to keep track of who got assigned to what cluster and have multiple "names" that have the same "coords".