in cassovary-core/src/main/scala/com/twitter/cassovary/algorithms/linkanalysis/PageRank.scala [85:113]
def iterate(prevIteration: PageRankIterationState): PageRankIterationState = {
val beforePR = prevIteration.pageRank
val afterPR = new Array[Double](graph.maxNodeId + 1)
log.debug("Calculating new PageRank values based on previous iteration...")
val prog = Progress("pagerank_calc", 65536, Some(graph.nodeCount))
//must correct for nodes with no outgoing connections
val dangleSum = dampingFactor * zeroOutgoing.foldLeft(0.0){ (partialSum, n) => partialSum + beforePR(n) } / nodeCount
graph foreach { node =>
val neighbors = efficientNeighbors(node)
if (isInStored) {
var newNodePR = 0.0
neighbors.foreach {
nbr => newNodePR += dampingFactor * beforePR(nbr) / outboundCount(nbr)
}
afterPR(node.id) = newNodePR + dampingAmount + dangleSum
}
else {
neighbors foreach { nbr =>
afterPR(nbr) += dampingFactor * beforePR(node.id) / node .outboundCount
}
afterPR(node.id) += dangleSum + dampingAmount
}
prog.inc
}
PageRankIterationState(afterPR, deltaOfArrays(prevIteration.pageRank, afterPR), prevIteration.iteration + 1)
}