Search in sources :

Example 1 with ClusteringCoefficient

use of org.gephi.statistics.plugin.ClusteringCoefficient in project gephi by gephi.

the class DynamicClusteringCoefficient method loop.

@Override
public void loop(GraphView window, Interval interval) {
    Graph graph;
    if (isDirected) {
        graph = graphModel.getDirectedGraph(window);
    } else {
        graph = graphModel.getUndirectedGraph(window);
    }
    TimeRepresentation tr = graphModel.getConfiguration().getTimeRepresentation();
    graph.readLock();
    try {
        clusteringCoefficientStat = new ClusteringCoefficient();
        clusteringCoefficientStat.setDirected(isDirected);
        clusteringCoefficientStat.triangles(graph);
        //Columns
        if (!averageOnly) {
            double[] coefficients = clusteringCoefficientStat.getCoefficientReuslts();
            int i = 0;
            for (Node n : graph.getNodes()) {
                double coef = coefficients[i++];
                switch(tr) {
                    case INTERVAL:
                        n.setAttribute(dynamicCoefficientColumn, coef, new Interval(interval.getLow(), interval.getLow() + tick));
                        break;
                    case TIMESTAMP:
                        n.setAttribute(dynamicCoefficientColumn, coef, interval.getLow());
                        n.setAttribute(dynamicCoefficientColumn, coef, interval.getHigh());
                        break;
                }
                if (cancel) {
                    break;
                }
            }
        }
    } finally {
        graph.readUnlockAll();
    }
    //Average
    double avg = clusteringCoefficientStat.getAverageClusteringCoefficient();
    graphModel.getGraphVisible().setAttribute(DYNAMIC_AVG_CLUSTERING_COEFFICIENT, avg, interval.getLow());
    graphModel.getGraphVisible().setAttribute(DYNAMIC_AVG_CLUSTERING_COEFFICIENT, avg, interval.getHigh());
    averages.put(interval.getLow(), avg);
    averages.put(interval.getHigh(), avg);
}
Also used : Graph(org.gephi.graph.api.Graph) TimeRepresentation(org.gephi.graph.api.TimeRepresentation) Node(org.gephi.graph.api.Node) ClusteringCoefficient(org.gephi.statistics.plugin.ClusteringCoefficient) Interval(org.gephi.graph.api.Interval)

Aggregations

Graph (org.gephi.graph.api.Graph)1 Interval (org.gephi.graph.api.Interval)1 Node (org.gephi.graph.api.Node)1 TimeRepresentation (org.gephi.graph.api.TimeRepresentation)1 ClusteringCoefficient (org.gephi.statistics.plugin.ClusteringCoefficient)1