public static Centroid make ( Relation < ? extends NumberVector > relation , DBIDs ids ) { final int dim = RelationUtil . dimensionality ( relation ) ; Centroid c = new Centroid ( dim ) ; double [ ] elems = c . elements ; int count = 0 ; for ( DBIDIter iter = ids . iter ( ) ; iter . valid ( ) ; iter . advance ( ) ) { NumberVector v = relation . get ( iter ) ; for ( int i = 0 ; i < dim ; i ++ ) { elems [ i ] += v . doubleValue ( i ) ; } count += 1 ; } if ( count == 0 ) { return c ; } for ( int i = 0 ; i < dim ; i ++ ) { elems [ i ] /= count ; } c . wsum = count ; return c ; }
Static constructor from an existing relation .