Search in sources :

Example 71 with Graph

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

the class WeightedDegreeNGTest method testCompleteGraphDegree.

@Test
public void testCompleteGraphDegree() {
    GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(5);
    Graph graph = graphModel.getGraph();
    Node n = graph.getNode("2");
    WeightedDegree d = new WeightedDegree();
    d.execute(graph);
    assertEquals(n.getAttribute(WeightedDegree.WDEGREE), 4.0);
}
Also used : Graph(org.gephi.graph.api.Graph) DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

Example 72 with Graph

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

the class HitsNGTest method testStarGraphHits.

@Test
public void testStarGraphHits() {
    GraphModel graphModel = GraphGenerator.generateStarUndirectedGraph(5);
    Graph graph = graphModel.getUndirectedGraph();
    Hits hit = new Hits();
    double[] authority = new double[6];
    double[] hubs = new double[6];
    HashMap<Node, Integer> indices = hit.createIndicesMap(graph);
    hit.calculateHits(graph, hubs, authority, indices, false, EPSILON);
    Node n1 = graph.getNode("0");
    Node n3 = graph.getNode("2");
    Node n4 = graph.getNode("3");
    int index1 = indices.get(n1);
    int index3 = indices.get(n3);
    int index4 = indices.get(n4);
    double hub1 = hubs[index1];
    double hub3 = hubs[index3];
    double auth1 = authority[index1];
    double auth4 = authority[index4];
    assertEquals(hub1, 0.4082);
    assertEquals(auth1, 0.9128);
    assertEquals(auth4, 0.1825);
    assertEquals(hub1, hub3);
}
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) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

Example 73 with Graph

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

the class HitsNGTest method testTwoConnectedNodesHits.

@Test
public void testTwoConnectedNodesHits() {
    GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(2);
    Graph graph = graphModel.getUndirectedGraph();
    Hits hit = new Hits();
    double[] authority = new double[2];
    double[] hubs = new double[2];
    HashMap<Node, Integer> indices = hit.createIndicesMap(graph);
    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 hub1 = hubs[index1];
    double auth2 = authority[index2];
    assertEquals(hub1, 0.7071);
    assertEquals(auth2, 0.7071);
}
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) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

Example 74 with Graph

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

the class HitsNGTest method testCompleteGraphHits.

@Test
public void testCompleteGraphHits() {
    GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(5);
    Graph graph = graphModel.getUndirectedGraph();
    Hits hit = new Hits();
    double[] authority = new double[5];
    double[] hubs = new double[5];
    HashMap<Node, Integer> indices = hit.createIndicesMap(graph);
    hit.calculateHits(graph, hubs, authority, indices, false, EPSILON);
    Node n1 = graph.getNode("0");
    Node n5 = graph.getNode("4");
    int index1 = indices.get(n1);
    int index5 = indices.get(n5);
    double hub1 = hubs[index1];
    double auth5 = authority[index5];
    assertEquals(hub1, 0.4472);
    assertEquals(auth5, 0.4472);
}
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) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

Example 75 with Graph

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

the class HitsNGTest method testNullGraphHits.

@Test
public void testNullGraphHits() {
    GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(5);
    Graph graph = graphModel.getUndirectedGraph();
    Hits hit = new Hits();
    double[] authority = new double[5];
    double[] hubs = new double[5];
    HashMap<Node, Integer> indices = hit.createIndicesMap(graph);
    hit.calculateHits(graph, hubs, authority, indices, false, EPSILON);
    Node n2 = graph.getNode("1");
    Node n3 = graph.getNode("2");
    int index2 = indices.get(n2);
    int index3 = indices.get(n3);
    double hub2 = hubs[index2];
    double auth3 = authority[index3];
    assertEquals(hub2, 0.0);
    assertEquals(auth3, 0.0);
}
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) Node(org.gephi.graph.api.Node) 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