@@ -140,8 +140,31 @@ object PageRank extends Logging {
140140 */
141141 def runWithOptions [VD : ClassTag , ED : ClassTag ](
142142 graph : Graph [VD , ED ], numIter : Int , resetProb : Double = 0.15 ,
143- srcId : Option [VertexId ] = None ): Graph [Double , Double ] =
144- {
143+ srcId : Option [VertexId ] = None ): Graph [Double , Double ] = {
144+ runWithOptions(graph, numIter, resetProb, srcId, normalized = true )
145+ }
146+
147+ /**
148+ * Run PageRank for a fixed number of iterations returning a graph
149+ * with vertex attributes containing the PageRank and edge
150+ * attributes the normalized edge weight.
151+ *
152+ * @tparam VD the original vertex attribute (not used)
153+ * @tparam ED the original edge attribute (not used)
154+ *
155+ * @param graph the graph on which to compute PageRank
156+ * @param numIter the number of iterations of PageRank to run
157+ * @param resetProb the random reset probability (alpha)
158+ * @param srcId the source vertex for a Personalized Page Rank (optional)
159+ * @param normalized whether or not to normalize rank sum
160+ *
161+ * @return the graph containing with each vertex containing the PageRank and each edge
162+ * containing the normalized weight.
163+ *
164+ */
165+ def runWithOptions [VD : ClassTag , ED : ClassTag ](
166+ graph : Graph [VD , ED ], numIter : Int , resetProb : Double ,
167+ srcId : Option [VertexId ], normalized : Boolean ): Graph [Double , Double ] = {
145168 require(numIter > 0 , s " Number of iterations must be greater than 0, " +
146169 s " but got ${numIter}" )
147170 require(resetProb >= 0 && resetProb <= 1 , s " Random reset probability must belong " +
@@ -179,8 +202,13 @@ object PageRank extends Logging {
179202 iteration += 1
180203 }
181204
182- // SPARK-18847 If the graph has sinks (vertices with no outgoing edges) correct the sum of ranks
183- normalizeRankSum(rankGraph, personalized)
205+ if (normalized) {
206+ // SPARK-18847 If the graph has sinks (vertices with no outgoing edges),
207+ // correct the sum of ranks
208+ normalizeRankSum(rankGraph, personalized)
209+ } else {
210+ rankGraph
211+ }
184212 }
185213
186214 /**
@@ -204,6 +232,32 @@ object PageRank extends Logging {
204232 def runWithOptionsWithPreviousPageRank [VD : ClassTag , ED : ClassTag ](
205233 graph : Graph [VD , ED ], numIter : Int , resetProb : Double , srcId : Option [VertexId ],
206234 preRankGraph : Graph [Double , Double ]): Graph [Double , Double ] = {
235+ runWithOptionsWithPreviousPageRank(
236+ graph, numIter, resetProb, srcId, normalized = true , preRankGraph
237+ )
238+ }
239+
240+ /**
241+ * Run PageRank for a fixed number of iterations returning a graph
242+ * with vertex attributes containing the PageRank and edge
243+ * attributes the normalized edge weight.
244+ *
245+ * @tparam VD the original vertex attribute (not used)
246+ * @tparam ED the original edge attribute (not used)
247+ *
248+ * @param graph the graph on which to compute PageRank
249+ * @param numIter the number of iterations of PageRank to run
250+ * @param resetProb the random reset probability (alpha)
251+ * @param srcId the source vertex for a Personalized Page Rank (optional)
252+ * @param normalized whether or not to normalize rank sum
253+ * @param preRankGraph PageRank graph from which to keep iterating
254+ *
255+ * @return the graph containing with each vertex containing the PageRank and each edge
256+ * containing the normalized weight.
257+ */
258+ def runWithOptionsWithPreviousPageRank [VD : ClassTag , ED : ClassTag ](
259+ graph : Graph [VD , ED ], numIter : Int , resetProb : Double , srcId : Option [VertexId ],
260+ normalized : Boolean , preRankGraph : Graph [Double , Double ]): Graph [Double , Double ] = {
207261 require(numIter > 0 , s " Number of iterations must be greater than 0, " +
208262 s " but got ${numIter}" )
209263 require(resetProb >= 0 && resetProb <= 1 , s " Random reset probability must belong " +
@@ -238,8 +292,13 @@ object PageRank extends Logging {
238292 iteration += 1
239293 }
240294
241- // SPARK-18847 If the graph has sinks (vertices with no outgoing edges) correct the sum of ranks
242- normalizeRankSum(rankGraph, personalized)
295+ if (normalized) {
296+ // SPARK-18847 If the graph has sinks (vertices with no outgoing edges),
297+ // correct the sum of ranks
298+ normalizeRankSum(rankGraph, personalized)
299+ } else {
300+ rankGraph
301+ }
243302 }
244303
245304 /**
0 commit comments