Skip to content

Commit cef28f4

Browse files
committed
Further updates to PICExample from Xiangrui's comments
1 parent f7ff43d commit cef28f4

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

examples/src/main/scala/org/apache/spark/examples/mllib/PowerIterationClusteringExample.scala

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,10 @@ object PowerIterationClusteringExample {
141141
}
142142

143143
/**
144-
* Gaussian Similarity:
145-
* http://www.stat.wisc.edu/~mchung/teaching/MIA/reading/diffusion.gaussian.kernel.pdf
144+
* Gaussian Similarity: http://en.wikipedia.org/wiki/Radial_basis_function_kernel
146145
*/
147146
def gaussianSimilarity(p1: (Double, Double), p2: (Double, Double), sigma: Double) = {
148-
(1.0 /
149-
(math.sqrt(2.0 * math.Pi) * sigma)) * math.exp((-1.0 / (2.0 * math.pow(sigma, 2.0))
150-
* (math.pow(p1._1 - p2._1, 2) + math.pow(p1._2 - p2._2, 2))))
147+
math.exp((p1._1 - p2._1)*(p1._1 - p2._1) + (p1._2 - p2._2)*(p1._2 - p2._2))
151148
}
152149

153150
private[mllib] def similarity(p1: (Double, Double), p2: (Double, Double)) = {
@@ -169,10 +166,10 @@ object PowerIterationClusteringExample {
169166
.run(circlesRdd)
170167

171168
val clusters = model.assignments.collect.groupBy(_._2).mapValues(_.map(_._1))
172-
println(s"Cluster assignments: "
173-
+ s"${clusters.toList.sortBy{ case (k,v) => v.length}
174-
.map { case (k, v) => s"$k -> ${v.sorted.mkString("[", ",", "]")}"}
175-
.mkString(",")}")
169+
val assignments =clusters.toList.sortBy{ case (k,v) => v.length}
170+
val assignmentsStr = assignments
171+
.map { case (k, v) => s"$k -> ${v.sorted.mkString("[", ",", "]")}"}.mkString(",")
172+
println(s"Cluster assignments: $assignmentsStr")
176173

177174
sc.stop()
178175
}

0 commit comments

Comments
 (0)