huawei-noah / streamDM

Stream Data Mining Library for Spark Streaming
http://streamdm.noahlab.com.hk/
Apache License 2.0
492 stars 147 forks source link

Create global clustering assignment method #8

Closed smaniu closed 6 years ago

smaniu commented 9 years ago

The following code appears in several methods in the implementation of Clustream and StreamKM:

val assignedCl = getClusters.foldLeft((0,Double.MaxValue,0))(
  (cl,centr) => {
    val dist = centr.in.distanceTo(x.in)
    if(dist<cl._2) ((cl._3,dist,cl._3+1))
     else ((cl._1,cl._2,cl._3+1))
   })._1

I suggest creating a ClusteringUtils object in which we put general methods like this, to avoid repetition and possible bugs due to changes.