Search in sources :

Example 51 with UndirectedGraph

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

the class HitsNGTest method testGraphWithSelfLoopsHits.

@Test
public void testGraphWithSelfLoopsHits() {
    GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
    UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
    Node node1 = graphModel.factory().newNode("0");
    Node node2 = graphModel.factory().newNode("1");
    Node node3 = graphModel.factory().newNode("2");
    undirectedGraph.addNode(node1);
    undirectedGraph.addNode(node2);
    undirectedGraph.addNode(node3);
    Edge edge12 = graphModel.factory().newEdge(node1, node2, false);
    Edge edge23 = graphModel.factory().newEdge(node2, node3, false);
    Edge edge11 = graphModel.factory().newEdge(node1, node1, false);
    Edge edge33 = graphModel.factory().newEdge(node3, node3, false);
    undirectedGraph.addEdge(edge12);
    undirectedGraph.addEdge(edge23);
    undirectedGraph.addEdge(edge11);
    undirectedGraph.addEdge(edge33);
    Graph graph = graphModel.getUndirectedGraph();
    Hits hit = new Hits();
    HashMap<Node, Integer> indices = hit.createIndicesMap(graph);
    double[] authority = new double[3];
    double[] hubs = new double[3];
    hit.calculateHits(graph, hubs, authority, indices, false, EPSILON);
    Node n1 = graph.getNode("0");
    Node n2 = graph.getNode("1");
    int index1 = indices.get(n1);
    int index2 = indices.get(n2);
    double auth1 = authority[index1];
    double auth2 = authority[index2];
    assertTrue(auth2 > auth1);
}
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) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController) Test(org.testng.annotations.Test)

Example 52 with UndirectedGraph

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

the class ModularityNGTest method testGraphWithouLinksModularity.

@Test
public void testGraphWithouLinksModularity() {
    GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(5);
    UndirectedGraph graph = graphModel.getUndirectedGraph();
    Modularity mod = new Modularity();
    Modularity.CommunityStructure theStructure = mod.new CommunityStructure(graph);
    int[] comStructure = new int[graph.getNodeCount()];
    HashMap<String, Double> modularityValues = mod.computeModularity(graph, theStructure, comStructure, 1., true, false);
    double modValue = modularityValues.get("modularity");
    assertEquals(modValue, Double.NaN);
}
Also used : GraphModel(org.gephi.graph.api.GraphModel) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Test(org.testng.annotations.Test)

Example 53 with UndirectedGraph

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

the class ModularityNGTest method testComputeBarbellGraphModularityNormalResolution.

@Test
public void testComputeBarbellGraphModularityNormalResolution() {
    GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(4);
    UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
    Node[] nodes = new Node[4];
    for (int i = 0; i < 4; i++) {
        Node currentNode = graphModel.factory().newNode(((Integer) (i + 4)).toString());
        nodes[i] = currentNode;
        undirectedGraph.addNode(currentNode);
    }
    for (int i = 0; i < 3; i++) {
        for (int j = i + 1; j < 4; j++) {
            Edge currentEdge = graphModel.factory().newEdge(nodes[i], nodes[j], false);
            undirectedGraph.addEdge(currentEdge);
        }
    }
    Edge currentEdge = graphModel.factory().newEdge(undirectedGraph.getNode("0"), undirectedGraph.getNode("5"), false);
    undirectedGraph.addEdge(currentEdge);
    UndirectedGraph graph = graphModel.getUndirectedGraph();
    Modularity mod = new Modularity();
    Modularity.CommunityStructure theStructure = mod.new CommunityStructure(graph);
    int[] comStructure = new int[graph.getNodeCount()];
    HashMap<String, Double> modularityValues = mod.computeModularity(graph, theStructure, comStructure, 1., true, false);
    double modValue = modularityValues.get("modularity");
    int class4 = comStructure[0];
    int class5 = comStructure[5];
    boolean correctResult = (class4 != class5 || modValue == 0.);
    assertTrue(correctResult);
}
Also used : Node(org.gephi.graph.api.Node) GraphModel(org.gephi.graph.api.GraphModel) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Edge(org.gephi.graph.api.Edge) Test(org.testng.annotations.Test)

Example 54 with UndirectedGraph

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

the class ModularityNGTest method testComputeBarbellGraphHighResolution.

@Test
public void testComputeBarbellGraphHighResolution() {
    GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(4);
    UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
    Node[] nodes = new Node[4];
    for (int i = 0; i < 4; i++) {
        Node currentNode = graphModel.factory().newNode(((Integer) (i + 4)).toString());
        nodes[i] = currentNode;
        undirectedGraph.addNode(currentNode);
    }
    for (int i = 0; i < 3; i++) {
        for (int j = i + 1; j < 4; j++) {
            Edge currentEdge = graphModel.factory().newEdge(nodes[i], nodes[j], false);
            undirectedGraph.addEdge(currentEdge);
        }
    }
    Edge currentEdge = graphModel.factory().newEdge(undirectedGraph.getNode("0"), undirectedGraph.getNode("5"), false);
    undirectedGraph.addEdge(currentEdge);
    UndirectedGraph graph = graphModel.getUndirectedGraph();
    Modularity mod = new Modularity();
    Modularity.CommunityStructure theStructure = mod.new CommunityStructure(graph);
    int[] comStructure = new int[graph.getNodeCount()];
    HashMap<String, Double> modularityValues = mod.computeModularity(graph, theStructure, comStructure, 100., true, false);
    double modValue = modularityValues.get("modularity");
    int class4 = comStructure[0];
    int class5 = comStructure[5];
    assertEquals(modValue, 0.0);
    assertEquals(class4, class5);
}
Also used : Node(org.gephi.graph.api.Node) GraphModel(org.gephi.graph.api.GraphModel) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Edge(org.gephi.graph.api.Edge) Test(org.testng.annotations.Test)

Example 55 with UndirectedGraph

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

the class PageRankNGTest method testOneNodePageRank.

@Test
public void testOneNodePageRank() {
    pc.newProject();
    GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(1);
    UndirectedGraph graph = graphModel.getUndirectedGraph();
    PageRank pr = new PageRank();
    double[] pageRank;
    HashMap<Node, Integer> indicies = pr.createIndiciesMap(graph);
    pageRank = pr.calculatePagerank(graph, indicies, false, false, 0.001, 0.85);
    Node n1 = graph.getNode("0");
    int index = indicies.get(n1);
    double pr1 = pageRank[index];
    assertEquals(pr1, 1.0);
}
Also used : GraphModel(org.gephi.graph.api.GraphModel) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

Aggregations

UndirectedGraph (org.gephi.graph.api.UndirectedGraph)100 GraphModel (org.gephi.graph.api.GraphModel)99 Node (org.gephi.graph.api.Node)97 Test (org.testng.annotations.Test)93 Edge (org.gephi.graph.api.Edge)44 GraphController (org.gephi.graph.api.GraphController)39 HashMap (java.util.HashMap)36 DirectedGraph (org.gephi.graph.api.DirectedGraph)13 Graph (org.gephi.graph.api.Graph)7 LinkedList (java.util.LinkedList)6