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>>

public class Neighbor<K,V> extends Object implements 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

    Fields
    Modifier and Type
    Field
    Description
    final double
    The distance between the query and the neighbor.
    final int
    The index of neighbor object in the dataset.
    final K
    The key of neighbor.
    final V
    The data object of neighbor.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Neighbor(K key, V object, int index, double distance)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    static <T> Neighbor<T,T>
    of(T key, int index, double distance)
    Creates a neighbor object, of which key and object are the same.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • key

      public final K key
      The key of neighbor.
    • value

      public final V value
      The data object of neighbor. It may be same as the key object.
    • index

      public final int index
      The index of neighbor object in the dataset.
    • distance

      public final double distance
      The distance between the query and the neighbor.
  • Constructor Details

    • Neighbor

      public Neighbor(K key, V object, int index, double distance)
      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

      public int compareTo(Neighbor<K,V> o)
      Specified by:
      compareTo in interface Comparable<K>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • of

      public static <T> Neighbor<T,T> of(T key, int index, double distance)
      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.