}
private <E extends WeightedEdge> SparseDoubleVector computeWeightVector(
WeightedGraph<E> g, int vertex) {
SparseDoubleVector weightVec = new CompactSparseVector();// g.order());
Set<E> adjacent = g.getAdjacencyList(vertex);
// Count how many neighbors have positive edge weights
// (assume for now that all edges are weighted positive)
double normalizer = 1d / adjacent.size();
// For each of the neighbors, normalize the positive edge
// weights by the number of neighbors (with pos. weights)
for (E e : adjacent) {
int v = (e.from() == vertex) ? e.to() : e.from();
weightVec.set(v, normalizer * e.weight());
}
// Last, although the graph is assumed to not have self-loops, the
// weight for an node to itself is the normalizing constant (1/num
// positive weights). This is analogous to the similarity contribution
// from the keystone node in the unweighted version
weightVec.set(vertex, normalizer);
return weightVec;
}