Posts

Showing posts from 2015

Topological Sort of JUNG graph in Java

Image
Below code sorts the DAG graph in topological order. g is a directed graph object of JUNG graph. I have used the algorithm given here  public void topoSort() { List L =new ArrayList(); List S =new ArrayList(); String node,edge,dest; for (String nod : g.getVertices()) { if (g.inDegree(nod) == 0) { S.add(nod); } } while(S.size()!=0) { node = S.get(S.size()-1); S.remove(node); // System.out.println(node); L.add(node); Collection outE=new ArrayList (); outE.addAll(g.getOutEdges(node)); Iterator ite = outE.iterator(); while(ite.hasNext()) { String outedge = ite.next(); dest = g.getDest(outedge); g.removeEdge(outedge); if(g.inDegree(dest)==0) S.add(dest); ite.remove(); } } if(g.getEdgeCount()!=0) { System.out.println("Error: Cycles present : "+g.getEdges().toString()); } else System.out.println(L.toString()); } The input graph is shown...

Implementing X-means clustering in Java using WEKA API.

This post shows how to run x-means clustering algorithm in Java using Weka. Prepare your data properly and use the following code to run x-means clustering algorithm. The output is the instance and their corresponding cluster. import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import weka.clusterers.XMeans; import weka.core.Instances; public class Cluster {     public static BufferedReader readDataFile(String filename)     {         BufferedReader inputReader = null;         try         {             inputReader = new BufferedReader(new FileReader(filename));         }         catch (FileNotFoundException ex)         {             System.er...

Text Mining Classification Implementation in Java Using WEKA

This tutorial contains the implementation of Text Mining using WEKA tool. The basic steps are given below: 1.                   Preprocessing : 1.                   Remove Special Characters. 2.                   Remove stop words. 3.                   Tokenize data. 4.                   Stemming using LovinsStemmer of WEKA 2.                   Identify Distinct Words. 3.             ...