Results 1 to 1 of 1

Thread: Density-Based Spatial Clustering of Applications with Noise (DBSCAN)

  1. #1

    Thread Starter
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Density-Based Spatial Clustering of Applications with Noise (DBSCAN)

    Quote Originally Posted by wikipedia
    Density-based spatial clustering of applications with noise (DBSCAN) is a data clustering algorithm. It is a density-based clustering algorithm because it finds a number of clusters starting from the estimated density distribution of corresponding nodes. DBSCAN is one of the most common clustering algorithms.

    http://en.wikipedia.org/wiki/DBSCAN
    How to use:

    1. Add Dbscan.vb to your project.
    2. Add Dbscan.txt to your project, set the Copy to Output Directory property to Copy always on it.
    3. Add a chart (from the System.Windows.Forms.DataVisualization namespace) to the form.
    4. Add the code below to your form. (C# Version Here)

    Code:
    Imports System.Windows.Forms.DataVisualization.Charting
    
    Public Class Form1
    
    #Region "fields"
    
        Private Shared ChartColors As Color() = New Color() {Color.FromArgb(&H41, 140, 240), Color.FromArgb(&HFC, 180, &H41), _
                                                             Color.FromArgb(&HE0, &H40, 10), Color.FromArgb(5, 100, &H92), _
                                                             Color.FromArgb(&HBF, &HBF, &HBF), Color.FromArgb(&H1A, &H3B, &H69), _
                                                             Color.FromArgb(&HFF, &HE3, 130), Color.FromArgb(&H12, &H9C, &HDD), _
                                                             Color.FromArgb(&HCA, &H6B, &H4B), Color.FromArgb(0, &H5C, &HDB), _
                                                             Color.FromArgb(&HF3, 210, &H88), Color.FromArgb(80, &H63, &H81), _
                                                             Color.FromArgb(&HF1, &HB9, &HA8), Color.FromArgb(&HE0, &H83, 10), _
                                                             Color.FromArgb(120, &H93, 190)}
    
    #End Region
    
    #Region "constructors"
    
        Public Sub New()
            Me.InitializeComponent()
            Me.InitializeChart()
        End Sub
    
    #End Region
    
    #Region "methods"
    
        Private Sub InitializeChart()
            Dim series As Series = Me.Chart1.Series(0)
    
            series.ChartType = SeriesChartType.Point
            series.MarkerStyle = MarkerStyle.Circle
            series.MarkerSize = 10
    
            Me.Chart1.Legends(0).Enabled = False
    
            Me.Chart1.ChartAreas(0).AxisX.LabelStyle.Format = "N3"
            Me.Chart1.ChartAreas(0).AxisX.MajorGrid.Enabled = False
    
            Me.Chart1.ChartAreas(0).AxisY.LabelStyle.Format = "N3"
            Me.Chart1.ChartAreas(0).AxisY.MajorGrid.Enabled = False
        End Sub
    
        Protected Overrides Sub OnLoad(e As EventArgs)
            MyBase.OnLoad(e)
    
            ' generate chart based on Dbscan.txt
            Me.GenerateClusters()
        End Sub
    
        Private Sub GenerateClusters()
    
            Dim points As New List(Of DbscanPoint)()
    
            ' change path as appropriate
            Dim lines = System.IO.File.ReadAllLines("Dbscan.txt")
    
            For Each line In lines
                Dim split = line.Split(" "c)
    
                points.Add(New DbscanPoint(Convert.ToDouble(split(1)), Convert.ToDouble(split(2))))
            Next
    
            ' customize the epsilion radius and minimum cluster points here
            ' note: if you are using http://people.cs.nctu.edu.tw/~rsliang/dbscan/testdatagen.html
            '       to generate data, make sure these parameters match the parameters on the site
            '       otherwise you will get different results
            DbscanAlgorithm.Dbscan(points.ToArray(), 4.0, 6)
    
            Dim series = Me.Chart1.Series(0)
    
            For Each item In points
                Dim p = series.Points(series.Points.AddXY(item.X, item.Y))
    
                If item.IsNoise Then
                    p.Color = SystemColors.Control
                Else
                    p.Color = Form1.ChartColors((item.ClusterId.Value - 1) Mod Form1.ChartColors.Length)
                End If
            Next
        End Sub
    
    #End Region
    
    End Class
    
    You should see this if everything was successful:

    Name:  DbScan.png
Views: 1319
Size:  27.9 KB

    Here's how you can generate test data (this is what I verified the algorithm against): http://people.cs.nctu.edu.tw/~rslian...stdatagen.html.
    Attached Files Attached Files

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width