Package smile.neighbor
Class Neighbor<K,V>
java.lang.Object
smile.neighbor.Neighbor<K,V>
- Type Parameters:
K
- the type of keys.V
- the type of associated objects.
- All Implemented Interfaces:
Comparable<Neighbor<K,
V>>
The immutable object encapsulates the results of nearest neighbor search.
A returned neighbor for nearest neighbor search contains the key of object
(e.g. the weight vector of a neuron) and the object itself (e.g. a neuron,
which also contains other information beyond weight vector), an index of
object in the dataset, which is often useful, and the distance between
the query key to the object key.
-
Field Summary
-
Constructor Summary
-
Method Summary
-
Field Details
-
key
The key of neighbor. -
value
The data object of neighbor. It may be same as the key object. -
index
public final int indexThe index of neighbor object in the dataset. -
distance
public final double distanceThe distance between the query and the neighbor.
-
-
Constructor Details
-
Neighbor
Constructor.- Parameters:
key
- the key of neighbor.object
- the value of neighbor.index
- the index of neighbor object in the dataset.distance
- the distance between the query and the neighbor.
-
-
Method Details
-
compareTo
- Specified by:
compareTo
in interfaceComparable<K>
-
toString
-
of
Creates a neighbor object, of which key and object are the same.- Type Parameters:
T
- the data type of key and object.- Parameters:
key
- the query key.index
- the index of object.distance
- the distance between query key and neighbor.- Returns:
- the neighbor object.
-