Search in sources :

Example 16 with Graph

use of org.gephi.graph.api.Graph 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)

Example 17 with Graph

use of org.gephi.graph.api.Graph in project gephi by gephi.

the class DynamicDegree method loop.

@Override
public void loop(GraphView window, Interval interval) {
    Graph graph = graphModel.getGraph(window);
    DirectedGraph directedGraph = null;
    if (isDirected) {
        directedGraph = graphModel.getDirectedGraph(window);
    }
    TimeRepresentation tr = graphModel.getConfiguration().getTimeRepresentation();
    long sum = 0;
    for (Node n : graph.getNodes().toArray()) {
        int degree = graph.getDegree(n);
        if (!averageOnly) {
            switch(tr) {
                case INTERVAL:
                    n.setAttribute(dynamicDegreeColumn, degree, new Interval(interval.getLow(), interval.getLow() + tick));
                    break;
                case TIMESTAMP:
                    n.setAttribute(dynamicDegreeColumn, degree, interval.getLow());
                    n.setAttribute(dynamicDegreeColumn, degree, interval.getHigh());
                    break;
            }
            if (isDirected) {
                int indegree = directedGraph.getInDegree(n);
                int outdegree = directedGraph.getOutDegree(n);
                switch(tr) {
                    case INTERVAL:
                        n.setAttribute(dynamicInDegreeColumn, indegree, new Interval(interval.getLow(), interval.getLow() + tick));
                        n.setAttribute(dynamicOutDegreeColumn, outdegree, new Interval(interval.getLow(), interval.getLow() + tick));
                        break;
                    case TIMESTAMP:
                        n.setAttribute(dynamicInDegreeColumn, indegree, interval.getLow());
                        n.setAttribute(dynamicInDegreeColumn, indegree, interval.getHigh());
                        n.setAttribute(dynamicOutDegreeColumn, outdegree, interval.getLow());
                        n.setAttribute(dynamicOutDegreeColumn, outdegree, interval.getHigh());
                        break;
                }
            }
        }
        sum += degree;
        if (cancel) {
            break;
        }
    }
    double avg = sum / (double) graph.getNodeCount();
    averages.put(interval.getLow(), avg);
    averages.put(interval.getHigh(), avg);
    graphModel.getGraphVisible().setAttribute(DYNAMIC_AVGDEGREE, avg, interval.getLow());
    graphModel.getGraphVisible().setAttribute(DYNAMIC_AVGDEGREE, avg, interval.getHigh());
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) Graph(org.gephi.graph.api.Graph) DirectedGraph(org.gephi.graph.api.DirectedGraph) TimeRepresentation(org.gephi.graph.api.TimeRepresentation) Node(org.gephi.graph.api.Node) Interval(org.gephi.graph.api.Interval)

Example 18 with Graph

use of org.gephi.graph.api.Graph in project gephi by gephi.

the class DynamicNbNodes method loop.

@Override
public void loop(GraphView window, Interval interval) {
    Graph graph = graphModel.getGraph(window);
    int count = graph.getNodeCount();
    graphModel.getGraphVisible().setAttribute(NB_NODES, count, interval.getLow());
    graphModel.getGraphVisible().setAttribute(NB_NODES, count, interval.getHigh());
    counts.put(interval.getLow(), count);
    counts.put(interval.getHigh(), count);
}
Also used : Graph(org.gephi.graph.api.Graph)

Example 19 with Graph

use of org.gephi.graph.api.Graph in project gephi by gephi.

the class ClusteringCoefficientNGTest method testOneNodeClusteringCoefficient.

@Test
public void testOneNodeClusteringCoefficient() {
    GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(1);
    Graph graph = graphModel.getGraph();
    ClusteringCoefficient cc = new ClusteringCoefficient();
    cc.setDirected(false);
    ArrayWrapper[] network = new ArrayWrapper[1];
    int[] triangles = new int[1];
    double[] nodeClustering = new double[1];
    HashMap<String, Double> results = cc.computeClusteringCoefficient(graph, network, triangles, nodeClustering, false);
    double avClusteringCoefficient = results.get("clusteringCoefficient");
    assertEquals(avClusteringCoefficient, Double.NaN);
}
Also used : Graph(org.gephi.graph.api.Graph) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Test(org.testng.annotations.Test)

Example 20 with Graph

use of org.gephi.graph.api.Graph in project gephi by gephi.

the class ClusteringCoefficientNGTest method testTwoConectedNodesClusteringCoefficient.

@Test
public void testTwoConectedNodesClusteringCoefficient() {
    GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(2);
    Graph graph = graphModel.getGraph();
    ClusteringCoefficient cc = new ClusteringCoefficient();
    ArrayWrapper[] network = new ArrayWrapper[2];
    int[] triangles = new int[2];
    double[] nodeClustering = new double[2];
    HashMap<String, Double> results = cc.computeClusteringCoefficient(graph, network, triangles, nodeClustering, false);
    double avClusteringCoefficient = results.get("clusteringCoefficient");
    assertEquals(avClusteringCoefficient, Double.NaN);
}
Also used : Graph(org.gephi.graph.api.Graph) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Test(org.testng.annotations.Test)

Aggregations

Graph (org.gephi.graph.api.Graph)104 GraphModel (org.gephi.graph.api.GraphModel)57 Node (org.gephi.graph.api.Node)50 DirectedGraph (org.gephi.graph.api.DirectedGraph)43 Test (org.testng.annotations.Test)36 GraphController (org.gephi.graph.api.GraphController)27 UndirectedGraph (org.gephi.graph.api.UndirectedGraph)24 Edge (org.gephi.graph.api.Edge)21 Column (org.gephi.graph.api.Column)9 ArrayList (java.util.ArrayList)8 Function (org.gephi.appearance.api.Function)6 GraphView (org.gephi.graph.api.GraphView)6 AttributeFunction (org.gephi.appearance.api.AttributeFunction)5 AppearanceController (org.gephi.appearance.api.AppearanceController)4 AppearanceModel (org.gephi.appearance.api.AppearanceModel)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 TransformerUI (org.gephi.appearance.spi.TransformerUI)3 GraphElementsController (org.gephi.datalab.api.GraphElementsController)3 DataTablesController (org.gephi.datalab.api.datatables.DataTablesController)3