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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations