Class NearestNeighbourSearch.NeighborList
- java.lang.Object
-
- moa.classifiers.lazy.neighboursearch.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)
-
-
Field Summary
Fields Modifier and Type Field Description protected NearestNeighbourSearch.NeighborNode
m_First
The first node in the list.protected NearestNeighbourSearch.NeighborNode
m_Last
The last node in the list.protected int
m_Length
The number of nodes to attempt to maintain in the list.
-
Constructor Summary
Constructors Constructor Description NeighborList(int length)
Creates the neighborlist with a desired length.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
currentLength()
Gets the current length of the list.NearestNeighbourSearch.NeighborNode
getFirst()
returns the first element in the list.NearestNeighbourSearch.NeighborNode
getLast()
returns the last element in the list.void
insertSorted(double distance, Instance instance)
Inserts an instance neighbor into the list, maintaining the list sorted by distance.boolean
isEmpty()
Gets whether the list is empty.void
printList()
Prints out the contents of the neighborlist.void
pruneToK(int k)
Prunes the list to contain the k nearest neighbors.
-
-
-
Field Detail
-
m_First
protected NearestNeighbourSearch.NeighborNode m_First
The first node in the list.
-
m_Last
protected NearestNeighbourSearch.NeighborNode m_Last
The last node in the list.
-
m_Length
protected int m_Length
The number of nodes to attempt to maintain in the list.
-
-
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 instanceinstance
- 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.
-
getFirst
public NearestNeighbourSearch.NeighborNode getFirst()
returns the first element in the list.- Returns:
- the first element
-
getLast
public NearestNeighbourSearch.NeighborNode getLast()
returns the last element in the list.- Returns:
- the last element
-
-