VectorType
- Type of Vectorizable, the first valuesDataType
- Type of data in the Pair, the second valuesPairType
- Type of Pair to use in the KDTree.@PublicationReference(author="Andrew W. Moore",title="An intoductory tutorial on kd-trees",type=TechnicalReport,publication="University of Cambridge Computer Laboratory Technical Report No. 209",year=1991,url="http://www.autonlab.org/autonweb/14665.html?branch=1&language=2") @PublicationReference(author="Wikipedia",title="kd-tree",type=WebPage,year=2009,url="http://en.wikipedia.org/wiki/Kd-tree") public class KDTree<VectorType extends Vectorizable,DataType,PairType extends Pair<? extends VectorType,DataType>> extends java.util.AbstractCollection<PairType> implements CloneableSerializable
Modifier and Type | Class and Description |
---|---|
protected static class |
KDTree.InOrderKDTreeIterator<VectorType extends Vectorizable,DataType,PairType extends Pair<? extends VectorType,DataType>>
Iterates through the KDTree using "inorder", also known as "symmetric
traversal", of the tree.
|
protected static class |
KDTree.Neighborhood<VectorType extends Vectorizable,DataType,PairType extends Pair<? extends VectorType,DataType>>
A Collection of nearby pairs.
|
protected static class |
KDTree.PairFirstVectorizableIndexComparator
Comparator for Pairs that have a Vectorizable as its first parameter.
|
Modifier and Type | Field and Description |
---|---|
protected KDTree.PairFirstVectorizableIndexComparator |
comparator
Comparator of this node to determine less than, greater than, or
equality.
|
protected KDTree<VectorType,DataType,PairType> |
leftChild
Left child of this subtree
|
protected int |
num
Number of elements in this subtree.
|
protected KDTree<VectorType,DataType,PairType> |
parent
Parent of this node of the subtree.
|
protected KDTree<VectorType,DataType,PairType> |
rightChild
Right child of this subtree.
|
protected PairType |
value
VectorType,DataType value for this node of the subtree.
|
Modifier | Constructor and Description |
---|---|
|
KDTree()
Default constructor
|
protected |
KDTree(java.util.ArrayList<? extends PairType> points,
KDTree.PairFirstVectorizableIndexComparator comparator,
int dimensionality,
KDTree<VectorType,DataType,PairType> parent)
Creates a balanced KDTree subtree for recursion purposes from the given
ArrayList of points.
|
|
KDTree(java.util.Collection<? extends PairType> points)
Creates a balanced KDTree from the given points.
|
protected |
KDTree(PairType value,
KDTree.PairFirstVectorizableIndexComparator comparator,
KDTree<VectorType,DataType,PairType> parent)
Creates a KDTree subtree for recursion purposes.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(PairType point) |
KDTree<VectorType,DataType,PairType> |
clone()
Creates a new clone (shallow copy) of this object.
|
protected double |
computeMinimumDifference(VectorType key)
Computes the minimum absolute difference between the given key and the
"first" value stored in this subtree for the index given by the embedded
comparator.
|
static <VectorType extends Vectorizable,DataType,PairType extends Pair<? extends VectorType,DataType>> |
createBalanced(java.util.Collection<? extends PairType> points)
Creates a balanced KDTree based on the given collection of Pairs.
|
protected void |
findNearest(VectorType key,
int k,
KDTree.Neighborhood<VectorType,DataType,PairType> neighborhood,
Metric<? super VectorType> metric)
Finds the "num" nearest neighbors to the given "key" stored in the
KDTree.
|
java.util.Collection<PairType> |
findNearest(VectorType key,
int k,
Metric<? super VectorType> metric)
Finds the "num" nearest neighbors to the given "key" stored in the
KDTree.
|
protected void |
findNearestWithinRadius(VectorType key,
double radius,
KDTree.Neighborhood<VectorType,DataType,PairType> neighborhood,
Metric<? super VectorType> metric)
Finds the neighbors within a given distance to the given "key" stored in
the KDTree.
|
java.util.Collection<PairType> |
findNearestWithinRadius(VectorType key,
double radius,
Metric<? super VectorType> metric)
Finds the neighbors within a given distance to the given "key" stored in
the KDTree.
|
java.util.Iterator<PairType> |
iterator()
Iterates through the KDTree using "inorder", also known as "symmetric
traversal", of the tree.
|
KDTree<VectorType,DataType,PairType> |
reblanace()
Rebalances the KDTree.
|
int |
size() |
java.lang.String |
toString() |
protected java.lang.String |
toString(java.lang.String prefix)
Recursively prints out the tree "inorder" by printing out the left
subtree, then the node, then the right subtree.
|
addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
protected int num
protected PairType extends Pair<? extends VectorType,DataType> value
protected KDTree<VectorType extends Vectorizable,DataType,PairType extends Pair<? extends VectorType,DataType>> parent
protected KDTree<VectorType extends Vectorizable,DataType,PairType extends Pair<? extends VectorType,DataType>> leftChild
protected KDTree<VectorType extends Vectorizable,DataType,PairType extends Pair<? extends VectorType,DataType>> rightChild
protected KDTree.PairFirstVectorizableIndexComparator comparator
public KDTree()
public KDTree(java.util.Collection<? extends PairType> points)
points
- Points to load into the KDTree.protected KDTree(PairType value, KDTree.PairFirstVectorizableIndexComparator comparator, KDTree<VectorType,DataType,PairType> parent)
value
- Value of the head of the subtree.comparator
- Comparator to use for the Vectorizables.parent
- Parent node of this subtree.protected KDTree(java.util.ArrayList<? extends PairType> points, KDTree.PairFirstVectorizableIndexComparator comparator, int dimensionality, KDTree<VectorType,DataType,PairType> parent)
points
- Points to load into the subtree.dimensionality
- Dimensionality of the Vectorizables.comparator
- Comparator to use for the Vectorizables.parent
- Parent node of this subtree.public KDTree<VectorType,DataType,PairType> clone()
CloneableSerializable
clone
in interface CloneableSerializable
clone
in class java.lang.Object
public static <VectorType extends Vectorizable,DataType,PairType extends Pair<? extends VectorType,DataType>> KDTree<VectorType,DataType,PairType> createBalanced(java.util.Collection<? extends PairType> points)
VectorType
- Type of Vectorizable, the first values.DataType
- Type of data in the Pair, the second values.PairType
- Type of Pair to use in the KDTree.points
- Points to load into the tree.public KDTree<VectorType,DataType,PairType> reblanace()
public boolean add(PairType point)
add
in interface java.util.Collection<PairType extends Pair<? extends VectorType,DataType>>
add
in class java.util.AbstractCollection<PairType extends Pair<? extends VectorType,DataType>>
public int size()
size
in interface java.util.Collection<PairType extends Pair<? extends VectorType,DataType>>
size
in class java.util.AbstractCollection<PairType extends Pair<? extends VectorType,DataType>>
@PublicationReference(author="Wikipedia", title="Tree traversal", type=WebPage, year=2009, url="http://en.wikipedia.org/wiki/Tree_traversal#Traversal") public java.util.Iterator<PairType> iterator()
iterator
in interface java.lang.Iterable<PairType extends Pair<? extends VectorType,DataType>>
iterator
in interface java.util.Collection<PairType extends Pair<? extends VectorType,DataType>>
iterator
in class java.util.AbstractCollection<PairType extends Pair<? extends VectorType,DataType>>
public java.lang.String toString()
toString
in class java.util.AbstractCollection<PairType extends Pair<? extends VectorType,DataType>>
protected java.lang.String toString(java.lang.String prefix)
prefix
- Prefix to tack onto the recursion values.public java.util.Collection<PairType> findNearest(VectorType key, int k, Metric<? super VectorType> metric)
key
- Vector to find the nearest neighbors of.k
- Number of neighbors to find.metric
- Metric to use to evaluate the nearness of other points.protected void findNearest(VectorType key, int k, KDTree.Neighborhood<VectorType,DataType,PairType> neighborhood, Metric<? super VectorType> metric)
key
- Vector to find the nearest neighbors of.k
- Number of neighbors to find.neighborhood
- PriorityQueue to store the current nearest neighbors.metric
- Metric to use to evaluate the nearness of other points.public java.util.Collection<PairType> findNearestWithinRadius(VectorType key, double radius, Metric<? super VectorType> metric)
key
- Vector to find the nearest neighbors of.radius
- Radius of desired neighborhood.metric
- Metric to use to evaluate the nearness of other points.protected void findNearestWithinRadius(VectorType key, double radius, KDTree.Neighborhood<VectorType,DataType,PairType> neighborhood, Metric<? super VectorType> metric)
key
- Vector to find the nearest neighbors of.radius
- Radius of desired neighborhood.neighborhood
- PriorityQueue to store the neighbors.metric
- Metric to use to evaluate the nearness of other points.protected double computeMinimumDifference(VectorType key)
key
- Vector to compare against.