E
- the type of data objects in the tree.public class BKTree<E> extends java.lang.Object implements RNNSearch<E,E>, java.io.Serializable
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 |
---|
BKTree(smile.math.distance.Metric<E> distance)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.util.Collection<E> data)
Add a dataset into BK-tree.
|
void |
add(E datum)
Add a datum into the BK-tree.
|
void |
add(E[] data)
Add a dataset into BK-tree.
|
void |
range(E q,
double radius,
java.util.List<Neighbor<E,E>> neighbors)
Search the neighbors in the given radius of query object, i.e.
|
void |
range(E q,
int radius,
java.util.List<Neighbor<E,E>> neighbors)
Search the neighbors in the given radius of query object, i.e.
|
java.lang.String |
toString() |
public BKTree(smile.math.distance.Metric<E> distance)
distance
- the metric used to build BK-tree. Note that the metric
must be a discrete distance, e.g. edit distance, Hamming distance, Lee
distance, Jaccard distance, and taxonomic distance, etc.public void add(E[] data)
data
- the dataset to insert into the BK-tree.public void add(java.util.Collection<E> data)
data
- the dataset to insert into the BK-tree.public java.lang.String toString()
toString
in class java.lang.Object
public void add(E datum)
public void range(E q, double radius, java.util.List<Neighbor<E,E>> neighbors)
RNNSearch
public void range(E q, int radius, java.util.List<Neighbor<E,E>> neighbors)
q
- the query object.radius
- the radius of search range from target.neighbors
- the list to store found neighbors in the given range on output.