public int closestPoint ( Instance instance , Instances allPoints , int [ ] pointList ) throws Exception { double minDist = Integer . MAX_VALUE ; int bestPoint = 0 ; for ( int i = 0 ; i < pointList . length ; i ++ ) { double dist = distance ( instance , allPoints . instance ( pointList [ i ] ) , Double . POSITIVE_INFINITY ) ; if ( dist < minDist ) { minDist = dist ; bestPoint = i ; } } return pointList [ bestPoint ] ; }
Returns the index of the closest point to the current instance . Index is index in Instances object that is the second parameter .