Skip to content

Commit 714acb5

Browse files
committed
added numRuns
1 parent 60c8ce2 commit 714acb5

File tree

1 file changed

+6
-4
lines changed
  • mllib/src/main/scala/org/apache/spark/mllib/clustering

1 file changed

+6
-4
lines changed

mllib/src/main/scala/org/apache/spark/mllib/clustering/KMeans.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,11 @@ class KMeans private (
210210

211211
val initStartTime = System.nanoTime()
212212

213+
val numRuns = if (initialModel.nonEmpty) runs else 1
214+
213215
val centers = initialModel match {
214216
case Some(kMeansCenters) => {
215-
Array.tabulate(runs)(r => kMeansCenters.clusterCenters
217+
Array.tabulate(numRuns)(r => kMeansCenters.clusterCenters
216218
.map(s => new VectorWithNorm(s, Vectors.norm(s, 2.0))))
217219
}
218220
case None => {
@@ -227,10 +229,10 @@ class KMeans private (
227229
logInfo(s"Initialization with $initializationMode took " + "%.3f".format(initTimeInSeconds) +
228230
" seconds.")
229231

230-
val active = Array.fill(runs)(true)
231-
val costs = Array.fill(runs)(0.0)
232+
val active = Array.fill(numRuns)(true)
233+
val costs = Array.fill(numRuns)(0.0)
232234

233-
var activeRuns = new ArrayBuffer[Int] ++ (0 until runs)
235+
var activeRuns = new ArrayBuffer[Int] ++ (0 until numRuns)
234236
var iteration = 0
235237

236238
val iterationStartTime = System.nanoTime()

0 commit comments

Comments
 (0)