Changeset 34 for branches/localSpectral/src
- Timestamp:
- Oct 30, 2010, 8:39:22 PM (14 years ago)
- Location:
- branches/localSpectral/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/localSpectral/src/clustering/Edge.java
r33 r34 27 27 } 28 28 29 29 @Override 30 public String toString(){ 31 return vertex1 + " --> "+ vertex2; 32 } 30 33 31 34 -
branches/localSpectral/src/clustering/LocalSpectral.java
r32 r34 92 92 double min_conductance_subset=100; 93 93 int min_conductance_index = -1; 94 int volume_cluster=0; 94 95 95 96 int subsets_count = vertexsScore.size(); … … 114 115 minvolume = volume_graph - volume_subset; 115 116 double conductance = edge_boundary / minvolume; 117 116 118 if ((volume_subset > min_volume) && (volume_subset < max_volume)){ 119 //if (volume_subset < min_volume){ 117 120 if (conductance < min_conductance_subset){ 118 121 min_conductance_subset = conductance; 119 122 min_conductance_index = i; 123 volume_cluster = volume_subset; 120 124 } 121 125 } 122 //System.out.println("CONDUCTANCE: "+conductance + " minvolume: "+minvolume + " edge_boundary: "+edge_boundary);123 126 } 124 127 … … 126 129 System.out.println("MIN CONDUCTANCE: "+min_conductance_subset); 127 130 128 System.out.println("CLUSTER: ");131 System.out.println("CLUSTER: ("+min_conductance_index+" elements, volume "+ volume_cluster +", volume graph "+ 2 * this.graph.getEdgeCount()+")"); 129 132 List<V> cluster = new ArrayList<V>(); 130 133 for(int i=0; i< min_conductance_index; i++) 131 134 cluster.add(vertexsScore.get(i).getVertex()); 132 135 136 String node_list = ""; 133 137 for(V node : cluster) 134 System.out.println(node.toString()); 138 node_list += node.toString() + ","; 139 System.out.println(node_list); 135 140 136 141 return cluster; -
branches/localSpectral/src/data/GraphBuilder.java
r32 r34 4 4 import clustering.Edge; 5 5 import clustering.VertexString; 6 import edu.uci.ics.jung.graph.DirectedSparseGraph; 6 7 import edu.uci.ics.jung.graph.Graph; 7 8 import edu.uci.ics.jung.graph.SparseGraph; … … 22 23 Graph<String,Edge<String>> graph; 23 24 24 public GraphBuilder(){ 25 graph = new SparseGraph<String, Edge<String>>(); 25 public GraphBuilder(boolean directed){ 26 if (directed) 27 graph = new DirectedSparseGraph<String, Edge<String>>(); 26 28 29 else 30 graph = new SparseGraph<String, Edge<String>>(); 27 31 } 28 32 -
branches/localSpectral/src/jung/Main.java
r32 r34 2 2 package jung; 3 3 4 import clustering.Edge; 5 import clustering.LocalSpectral; 6 import clustering.VertexScore; 7 import clustering.VertexString; 8 import data.GraphBuilder; 9 import edu.uci.ics.jung.algorithms.scoring.PageRank; 10 import edu.uci.ics.jung.graph.AbstractGraph; 11 import edu.uci.ics.jung.graph.Graph; 12 import edu.uci.ics.jung.graph.SparseGraph; 13 import java.awt.Paint; 14 import java.util.ArrayList; 15 import java.util.Collection; 16 import java.util.List; 17 import view.VertexPaintTransformer; 18 import view.Viewer; 4 import clustering.GraphClusterer; 5 6 19 7 20 8 public class Main { 21 9 22 10 public static void main(String[] args) { 23 GraphBuilder builder = new GraphBuilder();24 builder.buildGraphFromARFF("/home/luke/Desktop/reteUtentiMikeHidden.arff", 1000);25 //builder.buildGraphFromARFF("/home/luke/Desktop/reteSemplice.txt", 10000);26 Graph<String, Edge<String>> graph = builder.getGraph();27 11 28 LocalSpectral<String,Edge<String>> clusterer = new LocalSpectral(graph); 29 List<VertexScore<String>> global_ranking = clusterer.getGlobalRank(); 30 31 System.out.println("GLOBAL RANKING"); 32 for(VertexScore<String> v : global_ranking) 33 System.out.println(v.toString()); 34 35 Viewer viewGraph = new Viewer(graph); 36 viewGraph.viewGraphRank(global_ranking,null); 37 //viewGraph.viewGraph(null); 38 39 40 for(VertexScore<String> v : global_ranking){ 41 Long stoptime = 5000L; 42 try { 43 Thread.sleep(stoptime); 44 } catch (InterruptedException e) {} 45 List<String> cut = clusterer.clusterPageRankPriors(v.getVertex(),6); 46 Graph<String,Edge<String>> cut_graph = new SparseGraph<String, Edge<String>>(); 47 for(String vertex : cut){ 48 Collection<Edge<String>> out_edges = graph.getOutEdges(vertex); 49 for(Edge<String> edge : out_edges){ 50 String out_node = edge.getVertex2(); 51 if (cut.contains(out_node)){ 52 cut_graph.addEdge(edge, edge.getVertex1(),edge.getVertex2()); 53 } 54 } 55 } 56 viewGraph.setGraph(cut_graph); 57 viewGraph.viewGraph(null); 58 try { 59 Thread.sleep(stoptime); 60 } catch (InterruptedException e) {} 61 viewGraph.setGraph(graph); 62 viewGraph.viewGraphRank(global_ranking, null); 63 } 64 12 String path_simply_net = "/home/luke/Desktop/reteSemplice.txt"; 13 String path_mike_hiddent = "/home/luke/Desktop/reteUtentiMikeHidden.arff"; 14 String karate_club = "/home/luke/Desktop/karate.csv"; 15 String les_miserables = "/home/luke/Desktop/lesmis.csv"; 16 String power_grids = "/home/luke/Desktop/power.csv"; 17 String pol_blogs = "/home/luke/Desktop/polblogs.csv"; 18 String dolphins = "/home/luke/Desktop/dolphins.csv"; 19 String erdos_co_authors = "/home/luke/Desktop/erdos.csv"; 20 GraphClusterer cl = new GraphClusterer(dolphins,false,60); 21 cl.clusterize(true); 65 22 66 23 } 67 24 68 69 25 } -
branches/localSpectral/src/view/VertexPaintRankTransformer.java
r33 r34 13 13 14 14 List<VertexScore<V>> pagerank; 15 List<V> cluster;15 V seed_node; 16 16 17 public VertexPaintRankTransformer(List<VertexScore<V>> ranking, List<V> cluster){17 public VertexPaintRankTransformer(List<VertexScore<V>> ranking, V seed_node){ 18 18 this.pagerank = ranking; 19 this. cluster = cluster;19 this.seed_node = seed_node; 20 20 } 21 21 22 22 public Paint transform(V node) { 23 23 24 if( cluster!= null){25 if ( cluster.contains(node)){24 if(seed_node != null){ 25 if (seed_node.equals(node)){ 26 26 return (Paint) Color.GREEN; 27 27 } -
branches/localSpectral/src/view/Viewer.java
r32 r34 4 4 import clustering.VertexScore; 5 5 import clustering.VertexString; 6 import edu.uci.ics.jung.algorithms.layout.DAGLayout; 6 7 import edu.uci.ics.jung.algorithms.layout.FRLayout; 8 import edu.uci.ics.jung.algorithms.layout.KKLayout; 7 9 import edu.uci.ics.jung.algorithms.layout.Layout; 8 10 import edu.uci.ics.jung.graph.Graph; 9 11 import edu.uci.ics.jung.visualization.BasicVisualizationServer; 12 import java.awt.BorderLayout; 10 13 import java.awt.Color; 11 14 import java.awt.Dimension; 15 import java.awt.FlowLayout; 12 16 import java.awt.LayoutManager; 13 17 import java.awt.Paint; 18 import java.awt.event.ActionEvent; 19 import java.awt.event.ActionListener; 14 20 import java.util.ArrayList; 15 21 import java.util.List; 22 import javax.swing.JButton; 16 23 import javax.swing.JFrame; 24 import javax.swing.JPanel; 25 import javax.swing.JTextArea; 26 import javax.xml.bind.JAXB; 17 27 import org.apache.commons.collections15.Transformer; 18 28 … … 25 35 BasicVisualizationServer<V,E> vv; 26 36 JFrame frame; 37 JButton button; 38 JPanel button_panel; 39 JTextArea text ; 27 40 28 public Viewer(Graph<V,E> graph) { 41 public Viewer(Graph<V,E> graph, ActionListener listerner) { 42 this.button = new JButton("Next"); 43 this.button.addActionListener(listerner); 44 this.button_panel = new JPanel(new BorderLayout(100,100)); 45 this.button_panel.add(button); 46 this.text = new JTextArea(); 47 this.text.setEditable(false); 48 this.text.setBackground(Color.yellow); 49 29 50 this.graph = graph; 30 this.frame = new JFrame("Graph View"); 31 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 32 layout = new FRLayout(graph); 33 layout.setSize(new Dimension(1000,700)); 51 this.frame = new JFrame("Clustering with Google PageRank"); 52 this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 53 KKLayout kklayout = new KKLayout(graph); 54 kklayout.setAdjustForGravity(false); 55 kklayout.setMaxIterations(100); 56 this.layout = kklayout; 57 layout.setSize(new Dimension(1280,700)); 34 58 vv = new BasicVisualizationServer(layout); 35 vv.setPreferredSize(new Dimension(1000,700)); 59 vv.setPreferredSize(new Dimension(1280,700)); 60 vv.add(this.button_panel); 61 vv.add(this.text); 36 62 vv.getRenderContext().setVertexLabelTransformer(new VertexLabelTransformer<V, String>()); 63 37 64 } 38 65 66 public void setText(String text){ 67 this.text.setText(text); 68 } 39 69 public void setGraph(Graph<V, E> graph) { 40 70 this.graph = graph; … … 43 73 } 44 74 45 public void viewGraphRank(List<VertexScore<V>> pagerank, List<V> cluster){46 VertexPaintRankTransformer vertexPaint = new VertexPaintRankTransformer(pagerank, cluster);75 public void viewGraphRank(List<VertexScore<V>> pagerank, V seed_node){ 76 VertexPaintRankTransformer vertexPaint = new VertexPaintRankTransformer(pagerank,seed_node); 47 77 vv.getRenderContext().setVertexFillPaintTransformer((Transformer<V, Paint>) vertexPaint); 48 78 … … 67 97 68 98 } 99 69 100 }
Note: See TracChangeset
for help on using the changeset viewer.