You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/06/16 08:52:55 UTC

[GitHub] [flink-ml] zhipeng93 commented on a diff in pull request #110: [FLINK-27096] Optimize KMeans performance

zhipeng93 commented on code in PR #110:
URL: https://github.com/apache/flink-ml/pull/110#discussion_r898854960


##########
flink-ml-lib/src/main/java/org/apache/flink/ml/clustering/kmeans/KMeans.java:
##########
@@ -153,39 +149,24 @@ public IterationBodyResult process(
             DataStream<Integer> terminationCriteria =
                     centroids.flatMap(new TerminateOnMaxIter(maxIterationNum));
 
-            DataStream<Tuple2<Integer, DenseVector>> centroidIdAndPoints =
+            DataStream<Tuple2<Integer[], DenseVector[]>> centroidIdAndPoints =
                     points.connect(centroids.broadcast())
                             .transform(
-                                    "SelectNearestCentroid",
+                                    "CentroidsUpdateAccumulator",
                                     new TupleTypeInfo<>(
-                                            BasicTypeInfo.INT_TYPE_INFO,
-                                            DenseVectorTypeInfo.INSTANCE),
-                                    new SelectNearestCentroidOperator(distanceMeasure));
+                                            BasicArrayTypeInfo.INT_ARRAY_TYPE_INFO,
+                                            ObjectArrayTypeInfo.getInfoFor(
+                                                    DenseVectorTypeInfo.INSTANCE)),
+                                    new CentroidsUpdateAccumulator(distanceMeasure));

Review Comment:
   One optimization from algorithm side could be pre-compute the norm of each data point and thus accelerate the computing of `findClosestCentroidId`.
   
   A similar solution could be found [1] [2].
   
   [1] https://github.com/alibaba/Alink/blob/9ae07329a9fb77e39c334c09c79e5016b62f59ee/core/src/main/java/com/alibaba/alink/operator/common/distance/FastDistance.java
   [2] https://github.com/apache/spark/blob/2fa98a6a0971cafeb98a2148a962cf8d79381842/mllib/src/main/scala/org/apache/spark/mllib/clustering/KMeans.scala#L222



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org