private Instance getNearestNeighbour ( Instance inst , List < Instance > neighbourhood2 , boolean inNbhd ) { double dist = Double . MAX_VALUE ; Instance nearestNeighbour = null ; for ( Instance candidateNN : neighbourhood2 ) { // If inst is in neighbourhood2 and an identical instance is found, then it is no longer required to // look for inst and the inNbhd flag can be set to FALSE. if ( inNbhd && ( distance ( inst , candidateNN ) == 0 ) ) { inNbhd = false ; } else { if ( distance ( inst , candidateNN ) < dist ) { nearestNeighbour = candidateNN . copy ( ) ; dist = distance ( inst , candidateNN ) ; } } } return nearestNeighbour ; }
Searches the neighbourhood in order to find the argument instance s nearest neighbour .