File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed
mllib/src/main/scala/org/apache/spark/mllib/clustering Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -183,10 +183,19 @@ class StreamingKMeans(
183
183
this
184
184
}
185
185
186
- /** Initialize random centers, requiring only the number of dimensions. */
187
- def setRandomCenters (d : Int ): this .type = {
188
- val initialCenters = (0 until k).map(_ => Vectors .dense(Array .fill(d)(nextGaussian()))).toArray
189
- val clusterCounts = Array .fill(this .k)(0 ).map(_.toLong)
186
+ /** Initialize random centers, requiring only the number of dimensions.
187
+ *
188
+ * @param dim Number of dimensions
189
+ * @param seed Random seed
190
+ * */
191
+ def setRandomCenters (dim : Int , seed : Long = Utils .random.nextLong): this .type = {
192
+
193
+ val random = Utils .random
194
+ random.setSeed(seed)
195
+
196
+ val initialCenters = (0 until k)
197
+ .map(_ => Vectors .dense(Array .fill(dim)(random.nextGaussian()))).toArray
198
+ val clusterCounts = new Array [Long ](this .k)
190
199
this .model = new StreamingKMeansModel (initialCenters, clusterCounts)
191
200
this
192
201
}
You can’t perform that action at this time.
0 commit comments