Search in sources :

Example 11 with EdgeIterable

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;
        }
    }
}
Also used : EdgeIterable(org.gephi.graph.api.EdgeIterable) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge)

Example 12 with EdgeIterable

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;
}
Also used : EdgeIterable(org.gephi.graph.api.EdgeIterable) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge)

Aggregations

Edge (org.gephi.graph.api.Edge)12 EdgeIterable (org.gephi.graph.api.EdgeIterable)12 Node (org.gephi.graph.api.Node)10 NodeIterable (org.gephi.graph.api.NodeIterable)4 LinkedList (java.util.LinkedList)2 Column (org.gephi.graph.api.Column)2 HashMap (java.util.HashMap)1 Element (org.w3c.dom.Element)1