Skip to main content

DBSCAN implementation

Java implementation of DBSCAN (Density-Based Spatial Clustering Applications with Noise) algorithm.



//dbscan.java

import OBJECT.*;
import java.io.*;

/************************************************************************
* dbscan CLASS:
************************************************************************/
public class dbscan extends obj
{
public obj list[][];
public obj db[];
public int k;
public int a[];
public int c;
public int mpn;
public double eps;
public String filename;

public dbscan()throws IOException
{
db=new obj[5000];
int j=0,x=0,r=0;
double d;

eps=3.0;
mpn=4;

expand_cluster();
display();

}

/************************************************************************
* DISPLAY THE CLASSIFIED LOCAL OBJECTS
************************************************************************/



public void expand_cluster()throws IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader bfr=new BufferedReader(isr);
filename=bfr.readLine();

c=file_read(db,filename);

System.out.println("\nTotal number of Objects: "+c+"\n");

for(int i=0;i< = Minpts System.out.println("Total no of neighbour for ("+o.getx()+","+o.gety()+") is :"+j);*/ if(j<=eps) { nbhd[j++]=db[i]; crnt_obj.nc++; } }//END OF FOR /*****************************************************************************/ /* System.out.print("Neibourhood for object ("+crnt_obj.getx()+","+crnt_obj.gety()+")=["+crnt_obj.getnc()+"] : "); for(int k=0;k=mpt)
{
for(i=0;i<(id-1); i++) column[i] = 0; for(int i=0,k=0;i U");
else
{
a[db[i].getid()] = column[db[i].getid()] + 1;
list[db[i].getid()][column[db[i].getid()]++] = db[i];
}
}

System.out.println("\nClassified Objects are : \n");
for(int p = 0; p <= id - 1; p++) { System.out.print("Cluster ID : "+p+" -> ");
for(int q = 0; q < a[p]; q++)
{
System.out.print("("+ list[p][q].getx() + "," + list[p][q].gety() +")["+list[p][q].getnc()+"] ");
}
System.out.println("\n");
}
}


public static void main(String param[]) throws IOException
{
new dbscan();
}


}

/// OBJECT package contains another 3 class

// candi_list.java


package OBJECT;


public class candi_list extends node
{

public candi_list()
{
first = null;
}

public obj getobj()
{
node node1 = first;
return node1.get_obj();
}

public void delete()
{
node node1 = first;
if(!empty())
first = first.next;
node1 = null;
}
}

//node.java


package OBJECT;

public class node
{

public node()
{
}

public node(obj obj)
{
t = obj;
next = null;
}

public obj get_obj()
{
return t;
}

public boolean empty()
{
return first == null;
}

public void add(obj obj)
{
node node2 = new node(obj);
if(empty())
{
first = node2;
} else
{
node node1;
for(node1 = first; node1.next != null; node1 = node1.next);
node1.next = node2;
}
}

public obj t;
public node first;
public node next;
}

// obj.java


package OBJECT;

public class obj
{

public obj()
{
id = 1;
local_id = 1;
global_id = 1;
}

public obj(obj obj1)
{
id = 1;
local_id = 1;
global_id = 1;
x = obj1.getx();
y = obj1.gety();
}

public obj(int i, int j)
{
id = 1;
local_id = 1;
global_id = 1;
x = i;
y = j;
id = -1;
nc = 0;
local_id = 0;
global_id = -1;
eps_range = 0.0D;
}

public void mark_id(int i)
{
id = i;
}

public void rep_mark(int i)
{
local_id = i;
}

public void global_id(int i)
{
global_id = i;
}

public void mark_eps(double d)
{
eps_range = d;
}

public int getx()
{
return x;
}

public int gety()
{
return y;
}

public int getid()
{
return id;
}

public int getnc()
{
return nc;
}

public int getrep_mark()
{
return local_id;
}

public int getglobal_id()
{
return global_id;
}

public double geteps_range()
{
return eps_range;
}

public int id;
public int x;
public int y;
public int nc;
public int local_id;
public int global_id;
public double eps_range;
}


//// input file format

12,23;
34,56;
67,34;

etc....




Comments

  1. hai sir in this code some loops are missing so please give full code and send it to my mail
    hrushikeswar@gmail.com

    ReplyDelete
  2. hai sir in this code some loops are missing so please give full code and send it to my mail

    nazatulhaque.sultan@gmail.com

    ReplyDelete

Post a Comment