Record Class Neighbor<K,V>
java.lang.Object
java.lang.Record
smile.neighbor.Neighbor<K,V>
- Type Parameters:
K- the type of keys.V- the type of associated objects.- Record Components:
key- the key of neighbor.value- the value of neighbor.index- the index of neighbor object in the dataset.distance- the distance between the query and the neighbor.
- All Implemented Interfaces:
Comparable<Neighbor<K,V>>
public record Neighbor<K,V> (K key, V value, int index, double distance)
extends Record
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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintdoubledistance()Returns the value of thedistancerecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.intindex()Returns the value of theindexrecord component.key()Returns the value of thekeyrecord component.static <T> Neighbor<T, T> of(T key, int index, double distance) Creates a neighbor object, of which key and object are the same.toString()Returns a string representation of this record class.value()Returns the value of thevaluerecord component.
-
Constructor Details
-
Method Details
-
compareTo
-
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.
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
key
-
value
-
index
-
distance
-