protected int expandCluster ( final int clusterid , final WritableIntegerDataStore clusterids , final KNNQuery < O > knnq , final DBIDs neighbors , final double maxkdist , final FiniteProgress progress ) { int clustersize = 1 ; // initial seed! final ArrayModifiableDBIDs activeSet = DBIDUtil . newArray ( ) ; activeSet . addDBIDs ( neighbors ) ; // run expandCluster as long as this set is non-empty (non-recursive // implementation) DBIDVar id = DBIDUtil . newVar ( ) ; while ( ! activeSet . isEmpty ( ) ) { activeSet . pop ( id ) ; // Assign object to cluster final int oldclus = clusterids . intValue ( id ) ; if ( oldclus == NOISE ) { clustersize += 1 ; // Non core point cluster member: clusterids . putInt ( id , - clusterid ) ; } else if ( oldclus == UNPROCESSED ) { clustersize += 1 ; // expandCluster again: // Evaluate Neighborhood predicate final KNNList newneighbors = knnq . getKNNForDBID ( id , k ) ; // Evaluate Core-Point predicate if ( newneighbors . getKNNDistance ( ) <= maxkdist ) { activeSet . addDBIDs ( newneighbors ) ; } clusterids . putInt ( id , clusterid ) ; LOG . incrementProcessed ( progress ) ; } } return clustersize ; }
Set - based expand cluster implementation .