title: modifying spark GraphX pageRank to do random walk with restart
body: <p>I am trying to implement random walk with restart by modifying the Spark GraphX implementation of PageRank algorithm. </p>
  
  <pre><code>  def randomWalkWithRestart(graph: Graph[VertexProperty, EdgeProperty], patientID: String , numIter: Int = 10, alpha: Double = 0.15, tol: Double = 0.01): Unit = {
  
  var rankGraph: Graph[Double, Double] = graph
    // Associate the degree with each vertex
    .outerJoinVertices(graph.outDegrees) { (vid, vdata, deg) =&gt; deg.getOrElse(0) }
    // Set the weight on the edges based on the degree
    .mapTriplets( e =&gt; 1.0 / e.srcAttr, TripletFields.Src )
    // Set the vertex attributes to the initial pagerank values
    .mapVertices( (id, attr) =&gt; alpha )
  
  var iteration = 0
  var prevRankGraph: Graph[Double, Double] = null
  while (iteration &lt; numIter) {
    rankGraph.cache()
  
    // Compute the outgoing rank contributions of each vertex, perform local preaggregation, and
    // do the final aggregation at the receiving vertices. Requires a shuffle for aggregation.
    val rankUpdates = rankGraph.aggregateMessages[Double](
      ctx =&gt; ctx.sendToDst(ctx.srcAttr * ctx.attr), _ + _, TripletFields.Src)
  
    // Apply the final rank updates to get the new ranks, using join to preserve ranks of vertices
    // that didn't receive a message. Requires a shuffle for broadcasting updated ranks to the
    // edge partitions.
    prevRankGraph = rankGraph
    rankGraph = rankGraph.joinVertices(rankUpdates) {
      (id, oldRank, msgSum) =&gt; alpha + (1.0 - alpha) * msgSum
    }.cache()
  
    rankGraph.edges.foreachPartition(x =&gt; {}) // also materializes rankGraph.vertices
    //logInfo(s"PageRank finished iteration $iteration.")
    prevRankGraph.vertices.unpersist(false)
    prevRankGraph.edges.unpersist(false)
  
    iteration += 1
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I believe the <code>(id, oldRank, msgSum) =&gt; alpha + (1.0 - alpha) * msgSum</code> part should be changed, but I am not sure how. I need to add the ready state probability to this line. </p>
  
  <p>Furthermore, the ready state probability should be initialized somewhere before the <code>while</code> loop. And the ready state probability has to be uploaded inside the <code>while</code> loop. </p>
  
  <p>Any suggestions would be appreciated. </p>