shahidki31 commented on a change in pull request #21627: 
[SPARK-24484][MLLIB]Power Iteration Clustering is giving incorrect clustering 
results when there are mutiple leading eigen values.
URL: https://github.com/apache/spark/pull/21627#discussion_r249497213
 
 

 ##########
 File path: 
mllib/src/main/scala/org/apache/spark/mllib/clustering/PowerIterationClustering.scala
 ##########
 @@ -378,6 +378,22 @@ object PowerIterationClustering extends Logging {
       logInfo(s"$msgPrefix: delta = $delta.")
       diffDelta = math.abs(delta - prevDelta)
       logInfo(s"$msgPrefix: diff(delta) = $diffDelta.")
+
+      if (math.abs(diffDelta) < tol) {
+        /**
+         * Power Iteration fails to converge if absolute value of top 2 eigen 
values are equal,
+         * but with opposite sign. The resultant vector flip-flops between two 
vectors.
+         * We should give an exception, if we detect the failure of the 
convergence of the
+         * power iteration
+         */
+        val reileigh = curG.joinVertices(v) {
+          case (_, x, y) => x * y
+        }.vertices.values.sum() / curG.vertices.mapValues(x => x * 
x).values.sum()
+
+        if (math.abs(norm - math.abs(reileigh)) > tol) {
+          throw new SparkException("Power Iteration fail to converge")
 
 Review comment:
   Yes. I would like to know, instead of throwing exception, can we just print  
log error stating that it is failed to converge? But, in that case, we can't 
write UT.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to