Changeset 34 for branches/localSpectral


Ignore:
Timestamp:
Oct 30, 2010, 8:39:22 PM (14 years ago)
Author:
toshi
Message:
 
Location:
branches/localSpectral
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • branches/localSpectral/build/built-jar.properties

    r27 r34  
    1 #Sat, 09 Oct 2010 22:35:12 +0200
     1#Fri, 22 Oct 2010 14:15:58 +0200
    22
    33/home/luke/NetBeansProjects/Jung=
  • branches/localSpectral/nbproject/project.properties

    r32 r34  
    7676    ${javac.classpath}:\
    7777    ${build.classes.dir}
    78 # Space-separated list of JVM arguments used when running the project
    79 # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
    80 # or test-sys-prop.name=value to set system properties for unit tests):
    81 run.jvmargs=-Xms1G
    8278run.test.classpath=\
    8379    ${javac.test.classpath}:\
  • branches/localSpectral/src/clustering/Edge.java

    r33 r34  
    2727    }
    2828
    29    
     29    @Override
     30    public String toString(){
     31        return vertex1 + " --> "+ vertex2;
     32    }
    3033   
    3134
  • branches/localSpectral/src/clustering/LocalSpectral.java

    r32 r34  
    9292        double min_conductance_subset=100;
    9393        int min_conductance_index = -1;
     94        int volume_cluster=0;
    9495
    9596        int subsets_count = vertexsScore.size();
     
    114115                    minvolume = volume_graph - volume_subset;
    115116                double conductance = edge_boundary / minvolume;
     117
    116118                if ((volume_subset > min_volume) && (volume_subset < max_volume)){
     119                //if (volume_subset < min_volume){
    117120                    if (conductance < min_conductance_subset){
    118121                        min_conductance_subset = conductance;
    119122                        min_conductance_index = i;
     123                        volume_cluster = volume_subset;
    120124                    }
    121125                }
    122                 //System.out.println("CONDUCTANCE: "+conductance + " minvolume: "+minvolume + " edge_boundary: "+edge_boundary);
    123126            }
    124127
     
    126129        System.out.println("MIN CONDUCTANCE: "+min_conductance_subset);
    127130
    128         System.out.println("CLUSTER: ");
     131        System.out.println("CLUSTER: ("+min_conductance_index+" elements, volume "+ volume_cluster +", volume graph "+ 2 * this.graph.getEdgeCount()+")");
    129132        List<V> cluster = new ArrayList<V>();
    130133        for(int i=0; i< min_conductance_index; i++)
    131134            cluster.add(vertexsScore.get(i).getVertex());
    132135
     136        String node_list = "";
    133137        for(V node : cluster)
    134             System.out.println(node.toString());
     138            node_list += node.toString() + ",";
     139        System.out.println(node_list);
    135140       
    136141        return cluster;
  • branches/localSpectral/src/data/GraphBuilder.java

    r32 r34  
    44import clustering.Edge;
    55import clustering.VertexString;
     6import edu.uci.ics.jung.graph.DirectedSparseGraph;
    67import edu.uci.ics.jung.graph.Graph;
    78import edu.uci.ics.jung.graph.SparseGraph;
     
    2223    Graph<String,Edge<String>> graph;
    2324
    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>>();
    2628
     29        else
     30            graph = new SparseGraph<String, Edge<String>>();
    2731    }
    2832
  • branches/localSpectral/src/jung/Main.java

    r32 r34  
    22package jung;
    33
    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;
     4import clustering.GraphClusterer;
     5
     6
    197
    208public class Main {
    219
    2210    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();
    2711
    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);
    6522
    6623    }
    6724
    68 
    6925}
  • branches/localSpectral/src/view/VertexPaintRankTransformer.java

    r33 r34  
    1313
    1414    List<VertexScore<V>> pagerank;
    15     List<V> cluster;
     15    V seed_node;
    1616
    17     public VertexPaintRankTransformer(List<VertexScore<V>> ranking, List<V> cluster){
     17    public VertexPaintRankTransformer(List<VertexScore<V>> ranking, V seed_node){
    1818        this.pagerank = ranking;
    19         this.cluster = cluster;
     19        this.seed_node = seed_node;
    2020    }
    2121
    2222    public Paint transform(V node) {
    2323
    24         if(cluster != null){
    25             if (cluster.contains(node)){
     24        if(seed_node != null){
     25            if (seed_node.equals(node)){
    2626                return (Paint) Color.GREEN;
    2727            }
  • branches/localSpectral/src/view/Viewer.java

    r32 r34  
    44import clustering.VertexScore;
    55import clustering.VertexString;
     6import edu.uci.ics.jung.algorithms.layout.DAGLayout;
    67import edu.uci.ics.jung.algorithms.layout.FRLayout;
     8import edu.uci.ics.jung.algorithms.layout.KKLayout;
    79import edu.uci.ics.jung.algorithms.layout.Layout;
    810import edu.uci.ics.jung.graph.Graph;
    911import edu.uci.ics.jung.visualization.BasicVisualizationServer;
     12import java.awt.BorderLayout;
    1013import java.awt.Color;
    1114import java.awt.Dimension;
     15import java.awt.FlowLayout;
    1216import java.awt.LayoutManager;
    1317import java.awt.Paint;
     18import java.awt.event.ActionEvent;
     19import java.awt.event.ActionListener;
    1420import java.util.ArrayList;
    1521import java.util.List;
     22import javax.swing.JButton;
    1623import javax.swing.JFrame;
     24import javax.swing.JPanel;
     25import javax.swing.JTextArea;
     26import javax.xml.bind.JAXB;
    1727import org.apache.commons.collections15.Transformer;
    1828
     
    2535    BasicVisualizationServer<V,E> vv;
    2636    JFrame frame;
     37    JButton button;
     38    JPanel button_panel;
     39    JTextArea text ;
    2740
    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
    2950        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));
    3458        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);
    3662        vv.getRenderContext().setVertexLabelTransformer(new VertexLabelTransformer<V, String>());
     63       
    3764    }
    3865
     66    public void setText(String text){
     67        this.text.setText(text);
     68    }
    3969    public void setGraph(Graph<V, E> graph) {
    4070        this.graph = graph;
     
    4373    }
    4474   
    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);
    4777         vv.getRenderContext().setVertexFillPaintTransformer((Transformer<V, Paint>) vertexPaint);
    4878         
     
    6797
    6898     }
     99
    69100}
Note: See TracChangeset for help on using the changeset viewer.