T
- the type of data objects.public class LinearSearch<T> extends java.lang.Object implements NearestNeighborSearch<T,T>, KNNSearch<T,T>, RNNSearch<T,T>
By default, the query object (reference equality) is excluded from the neighborhood.
You may change this behavior with setIdenticalExcluded
. Note that
you may observe weird behavior with String objects. JVM will pool the string literal
objects. So the below variables
String a = "ABC";
String b = "ABC";
String c = "AB" + "C";
are actually equal in reference test a == b == c
. With toy data that you
type explicitly in the code, this will cause problems. Fortunately, the data would be
read from secondary storage in production.
Constructor and Description |
---|
LinearSearch(T[] dataset,
smile.math.distance.Distance<T> distance)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
isIdenticalExcluded()
Get whether if query object self be excluded from the neighborhood.
|
Neighbor<T,T>[] |
knn(T q,
int k)
Search the k nearest neighbors to the query.
|
Neighbor<T,T> |
nearest(T q)
Search the nearest neighbor to the given sample.
|
void |
range(T q,
double radius,
java.util.List<Neighbor<T,T>> neighbors)
Search the neighbors in the given radius of query object, i.e.
|
LinearSearch |
setIdenticalExcluded(boolean excluded)
Set if exclude query object self from the neighborhood.
|
java.lang.String |
toString() |
public java.lang.String toString()
toString
in class java.lang.Object
public LinearSearch setIdenticalExcluded(boolean excluded)
public boolean isIdenticalExcluded()
public Neighbor<T,T> nearest(T q)
NearestNeighborSearch
nearest
in interface NearestNeighborSearch<T,T>
q
- the query key.public Neighbor<T,T>[] knn(T q, int k)
KNNSearch