use of org.gephi.graph.api.DirectedGraph in project gephi by gephi.
the class ClusteringCoefficient method createNeighbourTable.
private HashMap<Node, EdgeWrapper> createNeighbourTable(Graph graph, Node node, HashMap<Node, Integer> indicies, ArrayWrapper[] networks, boolean directed) {
HashMap<Node, EdgeWrapper> neighborTable = new HashMap<>();
if (!directed) {
for (Edge edge : graph.getEdges(node)) {
Node neighbor = graph.getOpposite(node, edge);
neighborTable.put(neighbor, new EdgeWrapper(1, networks[indicies.get(neighbor)]));
}
} else {
for (Node neighbor : ((DirectedGraph) graph).getPredecessors(node)) {
neighborTable.put(neighbor, new EdgeWrapper(1, networks[indicies.get(neighbor)]));
}
for (Edge out : ((DirectedGraph) graph).getOutEdges(node)) {
Node neighbor = out.getTarget();
EdgeWrapper ew = neighborTable.get(neighbor);
if (ew == null) {
neighborTable.put(neighbor, new EdgeWrapper(1, network[indicies.get(neighbor)]));
} else {
ew.count++;
}
}
}
return neighborTable;
}
use of org.gephi.graph.api.DirectedGraph in project gephi by gephi.
the class PageRank method calculateR.
private double calculateR(Graph graph, double[] pagerankValues, HashMap<Node, Integer> indicies, boolean directed, double prob) {
int N = graph.getNodeCount();
double r = 0;
for (Node s : graph.getNodes()) {
int s_index = indicies.get(s);
boolean out;
if (directed) {
out = ((DirectedGraph) graph).getOutDegree(s) > 0;
} else {
out = graph.getDegree(s) > 0;
}
if (out) {
r += (1.0 - prob) * (pagerankValues[s_index] / N);
} else {
r += (pagerankValues[s_index] / N);
}
if (isCanceled) {
return r;
}
}
return r;
}
use of org.gephi.graph.api.DirectedGraph in project gephi by gephi.
the class WeightedDegree method calculateAverageWeightedDegree.
public double calculateAverageWeightedDegree(Graph graph, boolean isDirected, boolean updateAttributes) {
double averageWeightedDegree = 0;
DirectedGraph directedGraph = null;
if (isDirected) {
directedGraph = (DirectedGraph) graph;
}
Progress.start(progress, graph.getNodeCount());
for (Node n : graph.getNodes()) {
double totalWeight = 0;
if (isDirected) {
double totalInWeight = 0;
double totalOutWeight = 0;
for (Edge e : directedGraph.getEdges(n)) {
if (e.getSource().equals(n)) {
totalOutWeight += e.getWeight();
}
if (e.getTarget().equals(n)) {
totalInWeight += e.getWeight();
}
}
totalWeight = totalInWeight + totalOutWeight;
n.setAttribute(WINDEGREE, totalInWeight);
n.setAttribute(WOUTDEGREE, totalOutWeight);
n.setAttribute(WDEGREE, totalWeight);
updateDegreeDists(totalInWeight, totalOutWeight, totalWeight);
} else {
for (Edge e : graph.getEdges(n)) {
totalWeight += (e.isSelfLoop() ? 2 : 1) * e.getWeight();
}
n.setAttribute(WDEGREE, totalWeight);
updateDegreeDists(totalWeight);
}
averageWeightedDegree += totalWeight;
if (isCanceled) {
break;
}
Progress.progress(progress);
}
averageWeightedDegree /= (isDirected ? 2.0 : 1.0) * graph.getNodeCount();
return averageWeightedDegree;
}
use of org.gephi.graph.api.DirectedGraph 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());
}
use of org.gephi.graph.api.DirectedGraph in project gephi by gephi.
the class ClusteringCoefficientNGTest method testTriangleNonCompleteDirectedGraphClusteringCoefficient.
@Test
public void testTriangleNonCompleteDirectedGraphClusteringCoefficient() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
Edge edge12 = graphModel.factory().newEdge(node1, node2);
Edge edge21 = graphModel.factory().newEdge(node2, node1);
Edge edge23 = graphModel.factory().newEdge(node2, node3);
Edge edge32 = graphModel.factory().newEdge(node3, node2);
Edge edge13 = graphModel.factory().newEdge(node1, node3);
directedGraph.addEdge(edge12);
directedGraph.addEdge(edge21);
directedGraph.addEdge(edge23);
directedGraph.addEdge(edge32);
directedGraph.addEdge(edge13);
DirectedGraph graph = graphModel.getDirectedGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
ArrayWrapper[] network = new ArrayWrapper[3];
int[] triangles = new int[3];
double[] nodeClustering = new double[3];
HashMap<String, Double> results = cc.computeClusteringCoefficient(graph, network, triangles, nodeClustering, true);
double avClusteringCoefficient = results.get("clusteringCoefficient");
double res = 0.833;
double diff = 0.01;
assertTrue(Math.abs(avClusteringCoefficient - res) < diff);
}
Aggregations