private int computeNearestCentroid ( double [ ] vector ) { int centroidIndex = - 1 ; double minDistance = Double . MAX_VALUE ; for ( int i = 0 ; i < numCentroids ; i ++ ) { double distance = 0 ; for ( int j = 0 ; j < vectorLength ; j ++ ) { distance += ( coarseQuantizer [ i ] [ j ] - vector [ j ] ) * ( coarseQuantizer [ i ] [ j ] - vector [ j ] ) ; if ( distance >= minDistance ) { break ; } } if ( distance < minDistance ) { minDistance = distance ; centroidIndex = i ; } } return centroidIndex ; }
Finds and returns the index of the coarse quantizer s centroid which is closer to the given vector .