jsat.linear.vectorcollection
Class VectorArray<V extends Vec>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<V>
-
- jsat.linear.vectorcollection.VectorArray<V>
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<V>, java.util.Collection<V>, java.util.List<V>, java.util.RandomAccess, IncrementalCollection<V>, VectorCollection<V>
public class VectorArray<V extends Vec> extends java.util.ArrayList<V> implements IncrementalCollection<V>
This is the naive implementation of a Vector collection. Construction time is O(n) only to clone the n elements, and all queries are O(n)
Removing elements from the vector array will result in the destruction of anyacceleration cache- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description VectorArray()VectorArray(DistanceMetric distanceMetric)VectorArray(DistanceMetric distanceMetric, java.util.Collection<? extends V> c)VectorArray(DistanceMetric distanceMetric, int initialCapacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanadd(V e)booleanaddAll(java.util.Collection<? extends V> c)voidbuild(boolean parallel, java.util.List<V> collection, DistanceMetric dm)Builds this metric index from the given collection of points using the given distance metric.voidclear()VectorArray<V>clone()java.util.List<java.lang.Double>getAccelerationCache()DistanceMetricgetDistanceMetric()voidinsert(V x)Incrementally adds the given datapoint into the collectionVremove(int index)voidsearch(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 distanceMetric)Sets the distance metric used for this collection.-
Methods inherited from class java.util.ArrayList
add, addAll, contains, ensureCapacity, forEach, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeAll, removeIf, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
-
-
-
Constructor Detail
-
VectorArray
public VectorArray()
-
VectorArray
public VectorArray(DistanceMetric distanceMetric, int initialCapacity)
-
VectorArray
public VectorArray(DistanceMetric distanceMetric, java.util.Collection<? extends V> c)
-
VectorArray
public VectorArray(DistanceMetric distanceMetric)
-
-
Method Detail
-
getDistanceMetric
public DistanceMetric getDistanceMetric()
- Specified by:
getDistanceMetricin interfaceVectorCollection<V extends Vec>- Returns:
- the distance metric to use
-
setDistanceMetric
public void setDistanceMetric(DistanceMetric distanceMetric)
Description copied from interface:VectorCollectionSets the distance metric used for this collection.- Specified by:
setDistanceMetricin interfaceVectorCollection<V extends Vec>- Parameters:
distanceMetric- the distance metric to use
-
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
-
add
public boolean add(V e)
-
getAccelerationCache
public java.util.List<java.lang.Double> getAccelerationCache()
- Specified by:
getAccelerationCachein interfaceVectorCollection<V extends Vec>
-
addAll
public boolean addAll(java.util.Collection<? extends V> c)
-
remove
public V remove(int index)
-
clear
public void clear()
-
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 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.
-
clone
public VectorArray<V> clone()
- Specified by:
clonein interfaceIncrementalCollection<V extends Vec>- Specified by:
clonein interfaceVectorCollection<V extends Vec>- Overrides:
clonein classjava.util.ArrayList<V extends Vec>
-
build
public void build(boolean parallel, java.util.List<V> collection, 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.collection- the list of vectors to put into the indexdm- the distance metric to build the index using.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG