use of org.gephi.graph.api.EdgeIterable in project gephi by gephi.
the class Hits method updateHub.
void updateHub(Graph graph, double[] newValues, double[] authValues, boolean isDirected, Map<Node, Integer> indices) {
double norm = 0;
for (Node p : indices.keySet()) {
double hub = 0;
EdgeIterable edge_iter;
if (isDirected) {
edge_iter = ((DirectedGraph) graph).getOutEdges(p);
} else {
edge_iter = graph.getEdges(p);
}
for (Edge edge : edge_iter) {
if (!edge.isSelfLoop()) {
Node r = graph.getOpposite(p, edge);
hub += authValues[indices.get(r)];
}
}
newValues[indices.get(p)] = hub;
norm += hub * hub;
if (isCanceled) {
return;
}
}
norm = Math.sqrt(norm);
if (norm > 0) {
for (int i = 0; i < newValues.length; i++) {
newValues[i] = newValues[i] / norm;
}
}
}
use of org.gephi.graph.api.EdgeIterable in project gephi by gephi.
the class PageRank method updateValueForNode.
private double updateValueForNode(Graph graph, Node s, double[] pagerankValues, double[] weights, HashMap<Node, Integer> indicies, boolean directed, boolean useWeights, double r, double prob) {
double res = r;
EdgeIterable eIter;
if (directed) {
eIter = ((DirectedGraph) graph).getInEdges(s);
} else {
eIter = graph.getEdges(s);
}
for (Edge edge : eIter) {
Node neighbor = graph.getOpposite(s, edge);
int neigh_index = indicies.get(neighbor);
int normalize;
if (directed) {
normalize = ((DirectedGraph) graph).getOutDegree(neighbor);
} else {
normalize = graph.getDegree(neighbor);
}
if (useWeights) {
double weight = edge.getWeight() / weights[neigh_index];
res += prob * pagerankValues[neigh_index] * weight;
} else {
res += prob * (pagerankValues[neigh_index] / normalize);
}
}
return res;
}
Aggregations