protected double [ ] [ ] splitCentroid ( Cluster < ? extends MeanModel > parentCluster , Relation < V > relation ) { double [ ] parentCentroid = parentCluster . getModel ( ) . getMean ( ) ; // Compute size of cluster/region double radius = 0. ; for ( DBIDIter it = parentCluster . getIDs ( ) . iter ( ) ; it . valid ( ) ; it . advance ( ) ) { double d = getDistanceFunction ( ) . distance ( relation . get ( it ) , DoubleVector . wrap ( parentCentroid ) ) ; radius = ( d > radius ) ? d : radius ; } // Choose random vector Random random = rnd . getSingleThreadedRandom ( ) ; final int dim = RelationUtil . dimensionality ( relation ) ; double [ ] randomVector = normalize ( MathUtil . randomDoubleArray ( dim , random ) ) ; timesEquals ( randomVector , ( .4 + random . nextDouble ( ) * .5 ) * radius ) ; // Get the new centroids for ( int d = 0 ; d < dim ; d ++ ) { double a = parentCentroid [ d ] , b = randomVector [ d ] ; parentCentroid [ d ] = a - b ; randomVector [ d ] = a + b ; } return new double [ ] [ ] { parentCentroid , randomVector } ; }
Split an existing centroid into two initial centers .