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_r249512833
##########
File path:
mllib/src/main/scala/org/apache/spark/mllib/clustering/PowerIterationClustering.scala
##########
@@ -378,6 +378,27 @@ 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
+ */
+
+ // Rayleigh quotient = x^tAx / x^tx
+ val xTAx = curG.joinVertices(v) {
+ case (_, x, y) => x * y
+ }.vertices.values.sum()
+ val xTx = curG.vertices.mapValues(x => x * x).values.sum()
+ val Rayleigh = xTAx / xTx
Review comment:
Done.
----------------------------------------------------------------
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]