Github user derrickburns commented on a diff in the pull request:
https://github.com/apache/spark/pull/2419#discussion_r17639992
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/clustering/LocalKMeans.scala ---
@@ -1,127 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.spark.mllib.clustering
-
-import scala.util.Random
-
-import breeze.linalg.{Vector => BV, DenseVector => BDV, norm => breezeNorm}
-
-import org.apache.spark.Logging
-
-/**
- * An utility object to run K-means locally. This is private to the ML
package because it's used
- * in the initialization of KMeans but not meant to be publicly exposed.
- */
-private[mllib] object LocalKMeans extends Logging {
-
- /**
- * Run K-means++ on the weighted point set `points`. This first does the
K-means++
- * initialization procedure and then rounds of Lloyd's algorithm.
- */
- def kMeansPlusPlus(
- seed: Int,
- points: Array[BreezeVectorWithNorm],
- weights: Array[Double],
- k: Int,
- maxIterations: Int
- ): Array[BreezeVectorWithNorm] = {
- val rand = new Random(seed)
- val dimensions = points(0).vector.length
- val centers = new Array[BreezeVectorWithNorm](k)
-
- // Initialize centers by sampling using the k-means++ procedure.
- centers(0) = pickWeighted(rand, points, weights).toDense
- for (i <- 1 until k) {
- // Pick the next center with a probability proportional to cost
under current centers
- val curCenters = centers.view.take(i)
- val sum = points.view.zip(weights).map { case (p, w) =>
- w * KMeans.pointCost(curCenters, p)
- }.sum
- val r = rand.nextDouble() * sum
- var cumulativeScore = 0.0
- var j = 0
- while (j < points.length && cumulativeScore < r) {
- cumulativeScore += weights(j) * KMeans.pointCost(curCenters,
points(j))
- j += 1
- }
- if (j == 0) {
- logWarning("kMeansPlusPlus initialization ran out of distinct
points for centers." +
- s" Using duplicate point for center k = $i.")
- centers(i) = points(0).toDense
--- End diff --
This is the problematic line. Adding duplicate points is bad.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]