Class NearestNeighbourSearch.NeighborList

  • Enclosing class:
    NearestNeighbourSearch

    protected class NearestNeighbourSearch.NeighborList
    extends Object
    A class for a linked list to store the nearest k neighbours to an instance. We use a list so that we can take care of cases where multiple neighbours are the same distance away. i.e. the minimum length of the list is k.
    Version:
    $Revision: 8034 $
    Author:
    Ashraf M. Kibriya (amk14[at-the-rate]cs[dot]waikato[dot]ac[dot]nz)
    • Constructor Detail

      • NeighborList

        public NeighborList​(int length)
        Creates the neighborlist with a desired length.
        Parameters:
        length - the length of list to attempt to maintain
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Gets whether the list is empty.
        Returns:
        true if list is empty
      • currentLength

        public int currentLength()
        Gets the current length of the list.
        Returns:
        the current length of the list
      • insertSorted

        public void insertSorted​(double distance,
                                 Instance instance)
        Inserts an instance neighbor into the list, maintaining the list sorted by distance.
        Parameters:
        distance - the distance to the instance
        instance - the neighboring instance
      • pruneToK

        public void pruneToK​(int k)
        Prunes the list to contain the k nearest neighbors. If there are multiple neighbors at the k'th distance, all will be kept.
        Parameters:
        k - the number of neighbors to keep in the list.
      • printList

        public void printList()
        Prints out the contents of the neighborlist.