public Clustering < PrototypeModel < O > > run ( Relation < O > relation ) { RangeQuery < O > rq = relation . getRangeQuery ( getDistanceFunction ( ) , threshold ) ; ModifiableDBIDs seen = DBIDUtil . newHashSet ( relation . size ( ) ) ; Clustering < PrototypeModel < O > > clustering = new Clustering <> ( "Prototype clustering" , "prototype-clustering" ) ; int queries = 0 ; FiniteProgress prog = LOG . isVerbose ( ) ? new FiniteProgress ( "Leader clustering" , relation . size ( ) , LOG ) : null ; for ( DBIDIter it = relation . iterDBIDs ( ) ; it . valid ( ) && seen . size ( ) < relation . size ( ) ; it . advance ( ) ) { if ( seen . contains ( it ) ) { continue ; } DoubleDBIDList res = rq . getRangeForDBID ( it , threshold ) ; ++ queries ; ModifiableDBIDs ids = DBIDUtil . newArray ( res . size ( ) ) ; for ( DBIDIter cand = res . iter ( ) ; cand . valid ( ) ; cand . advance ( ) ) { if ( seen . add ( cand ) ) { LOG . incrementProcessed ( prog ) ; ids . add ( cand ) ; } } assert ( ids . size ( ) > 0 && ids . contains ( it ) ) ; PrototypeModel < O > mod = new SimplePrototypeModel <> ( relation . get ( it ) ) ; clustering . addToplevelCluster ( new Cluster <> ( ids , mod ) ) ; } LOG . statistics ( new LongStatistic ( this . getClass ( ) . getName ( ) + ".queries" , queries ) ) ; LOG . ensureCompleted ( prog ) ; return clustering ; }
Run the leader clustering algorithm .