jsat.linear.vectorcollection
Class VPTree<V extends Vec>
- java.lang.Object
-
- jsat.linear.vectorcollection.VPTree<V>
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, DualTree<V>, IncrementalCollection<V>, VectorCollection<V>
- Direct Known Subclasses:
- VPTreeMV
public class VPTree<V extends Vec> extends java.lang.Object implements IncrementalCollection<V>, DualTree<V>
Provides an implementation of Vantage Point Trees, as described in "Data Structures and Algorithms for Nearest Neighbor Search in General Metric Spaces" by Peter N. Yianilos
VPTrees are more expensive to create, requiring O(n log n) distance computations. However, they work well for high dimensional data sets, and provide O( log n ) query time forVectorCollection.search(jsat.linear.Vec, int)
Note: In the original paper, the VP-tree is detailed, and then enhanced to the VPs-tree, and the VPsb-tree, which each add additional optimizations. This implementation is equivalent to the VPsb-tree presented in the original paper.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classVPTree.VPSelection-
Nested classes/interfaces inherited from interface jsat.linear.vectorcollection.DualTree
DualTree.DualTreeTraversalAction, DualTree.SelfAsChildNode<N extends IndexNode<N>>
-
-
Field Summary
-
Fields inherited from interface jsat.linear.vectorcollection.DualTree
COMP_SCORE
-
-
Constructor Summary
Constructors Constructor and Description VPTree()VPTree(DistanceMetric dm)VPTree(DistanceMetric dm, VPTree.VPSelection sampling)VPTree(java.util.List<V> list, DistanceMetric dm)VPTree(java.util.List<V> list, DistanceMetric dm, boolean parallel)VPTree(java.util.List<V> list, DistanceMetric dm, VPTree.VPSelection vpSelection)VPTree(java.util.List<V> list, DistanceMetric dm, VPTree.VPSelection vpSelection, java.util.Random rand, int sampleSize, int searchIterations)VPTree(java.util.List<V> list, DistanceMetric dm, VPTree.VPSelection vpSelection, java.util.Random rand, int sampleSize, int searchIterations, boolean parallel)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidbuild(boolean parallel, java.util.List<V> list, DistanceMetric dm)Builds this metric index from the given collection of points using the given distance metric.VPTree<V>clone()Vget(int indx)Accesses a vector from this collection via index.java.util.List<java.lang.Double>getAccelerationCache()DistanceMetricgetDistanceMetric()intgetMaxLeafSize()Returns the maximum leaf node size.IndexNodegetRoot()voidinsert(V x)Incrementally adds the given datapoint into the collectionvoidsearch(Vec query, double range, java.util.List<java.lang.Integer> neighbors, java.util.List<java.lang.Double> distances)Performs a range search of the current collection.voidsearch(Vec query, int numNeighbors, java.util.List<java.lang.Integer> neighbors, java.util.List<java.lang.Double> distances)Performs k-Nearest Neighbor search of the current collection.voidsetDistanceMetric(DistanceMetric dm)Sets the distance metric used for this collection.voidsetMaxLeafSize(int maxLeafSize)Sets the maximum leaf node size.intsize()Returns the number of vectors stored in the collection-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.linear.vectorcollection.DualTree
computeKnnBound, dist, dual_depth_first, search, search, traverse
-
-
-
-
Constructor Detail
-
VPTree
public VPTree(java.util.List<V> list, DistanceMetric dm, VPTree.VPSelection vpSelection, java.util.Random rand, int sampleSize, int searchIterations, boolean parallel)
-
VPTree
public VPTree(java.util.List<V> list, DistanceMetric dm, VPTree.VPSelection vpSelection, java.util.Random rand, int sampleSize, int searchIterations)
-
VPTree
public VPTree(java.util.List<V> list, DistanceMetric dm, VPTree.VPSelection vpSelection)
-
VPTree
public VPTree(java.util.List<V> list, DistanceMetric dm, boolean parallel)
-
VPTree
public VPTree(java.util.List<V> list, DistanceMetric dm)
-
VPTree
public VPTree()
-
VPTree
public VPTree(DistanceMetric dm)
-
VPTree
public VPTree(DistanceMetric dm, VPTree.VPSelection sampling)
-
-
Method Detail
-
build
public void build(boolean parallel, java.util.List<V> list, DistanceMetric dm)Description copied from interface:VectorCollectionBuilds this metric index from the given collection of points using the given distance metric.- Specified by:
buildin interfaceVectorCollection<V extends Vec>- Parameters:
parallel-trueif the index should be built in parallel, orfalseif it should be done in a single thread.list- the list of vectors to put into the indexdm- the distance metric to build the index using.
-
setDistanceMetric
public void setDistanceMetric(DistanceMetric dm)
Description copied from interface:VectorCollectionSets the distance metric used for this collection.- Specified by:
setDistanceMetricin interfaceVectorCollection<V extends Vec>- Parameters:
dm- the distance metric to use
-
getDistanceMetric
public DistanceMetric getDistanceMetric()
- Specified by:
getDistanceMetricin interfaceVectorCollection<V extends Vec>- Returns:
- the distance metric to use
-
size
public int size()
Description copied from interface:VectorCollectionReturns the number of vectors stored in the collection- Specified by:
sizein interfaceVectorCollection<V extends Vec>- Returns:
- the size of the collection
-
get
public V get(int indx)
Description copied from interface:VectorCollectionAccesses a vector from this collection via index.- Specified by:
getin interfaceVectorCollection<V extends Vec>- Parameters:
indx- the index in [0,VectorCollection.size()) of the vector to access- Returns:
- the vector from the collection
-
insert
public void insert(V x)
Description copied from interface:IncrementalCollectionIncrementally adds the given datapoint into the collection- Specified by:
insertin interfaceIncrementalCollection<V extends Vec>- Parameters:
x- the vector to add to the collection
-
search
public void search(Vec query, double range, java.util.List<java.lang.Integer> neighbors, java.util.List<java.lang.Double> distances)
Description copied from interface:VectorCollectionPerforms a range search of the current collection. The index and distance of each found neighbor will be placed into the given Lists.- Specified by:
searchin interfaceVectorCollection<V extends Vec>- Parameters:
query- the point to search for the neighbors within a given radius.range- the radius to search for all the neighbors with a distance ≤ range.neighbors- the list to store the index of the neighbors in. Will be sorted by distance to the query, and paired with the values in distances.distances- the list to store the distance of the neighbors to the query in. Will be sorted, and paired with the values in neighbors.
-
search
public void search(Vec query, int numNeighbors, java.util.List<java.lang.Integer> neighbors, java.util.List<java.lang.Double> distances)
Description copied from interface:VectorCollectionPerforms k-Nearest Neighbor search of the current collection. The index and distance of each found neighbor will be placed into the given Lists.- Specified by:
searchin interfaceDualTree<V extends Vec>- Specified by:
searchin interfaceVectorCollection<V extends Vec>- Parameters:
query- the point to search for the k-nearest neighbors ofnumNeighbors- the number of neighbors k to search for.neighbors- the list to store the index of the neighbors in. Will be sorted by distance to the query, and paired with the values in distances.distances- the list to store the distance of the neighbors to the query in. Will be sorted, and paired with the values in neighbors.
-
getMaxLeafSize
public int getMaxLeafSize()
Returns the maximum leaf node size. Leaf nodes are used to reduce inefficiency of splitting small lists. If a sublist will fit into a leaf node, a leaf node will be created instead of splitting. This is the maximum number of points that may be used to construct a leaf node.- Returns:
- the maximum leaf node size in the tree
-
setMaxLeafSize
public void setMaxLeafSize(int maxLeafSize)
Sets the maximum leaf node size. Leaf nodes are used to reduce inefficiency of splitting small lists. If a sublist will fit into a leaf node, a leaf node will be created instead of splitting. This is the maximum number of points that may be used to construct a leaf node.
The minimum leaf size is 5 for implementation reasons. If a value less than 5 is given, 5 will be used isntead.- Parameters:
maxLeafSize- the new maximum leaf node size.
-
getAccelerationCache
public java.util.List<java.lang.Double> getAccelerationCache()
- Specified by:
getAccelerationCachein interfaceVectorCollection<V extends Vec>
-
-
DataMelt 3.0 © DataMelt by jWork.ORG