OBJECT
- Type of object being stored.public class LSHNearestNeighbours<OBJECT> extends Object implements IncrementalNearestNeighbours<OBJECT,float[],IntFloatPair>
Note: This object is not thread-safe. Multiple insertions or mixed insertions and searches should not be performed concurrently without external locking.
Modifier and Type | Field and Description |
---|---|
protected List<OBJECT> |
data |
protected DistanceComparator<OBJECT> |
distanceFcn |
protected List<org.openimaj.knn.lsh.LSHNearestNeighbours.Table<OBJECT>> |
tables |
Constructor and Description |
---|
LSHNearestNeighbours(HashFunctionFactory<OBJECT> factory,
int numTables,
DistanceComparator<OBJECT> distanceFcn)
Construct with the given hash function factory which will be used to
initialize the requested number of hash tables.
|
LSHNearestNeighbours(List<HashFunction<OBJECT>> tableHashes,
DistanceComparator<OBJECT> distanceFcn)
Construct with the given hash functions and distance function.
|
Modifier and Type | Method and Description |
---|---|
int |
add(OBJECT o)
Add a single data item
|
void |
addAll(Collection<OBJECT> d)
Insert data into the tables
|
int[] |
addAll(List<OBJECT> d)
Insert all the given data
|
void |
addAll(OBJECT[] d)
Insert data into the tables
|
OBJECT |
get(int i)
Get the data item at the given index.
|
int[] |
getBucketId(OBJECT point)
Compute identifiers of the buckets in which the given point belongs for
all the tables.
|
int[][] |
getBucketId(OBJECT[] data)
Compute identifiers of the buckets in which the given points belong for
all the tables.
|
List<OBJECT> |
getData()
Get a read-only view of the underlying data.
|
int |
numTables()
Get the number of hash tables
|
gnu.trove.set.hash.TIntHashSet |
search(OBJECT data)
Search for a similar data item in the underlying tables and return all
matches
|
gnu.trove.set.hash.TIntHashSet[] |
search(OBJECT[] data)
Search for similar data in the underlying tables and return all matches
|
void |
searchKNN(List<OBJECT> qus,
int K,
int[][] argmins,
float[][] mins)
Search for the K nearest neighbours to each of the N queries, and return
the indices of each nearest neighbour and their respective distances.
|
void |
searchKNN(OBJECT[] qus,
int K,
int[][] argmins,
float[][] mins)
Search for the K nearest neighbours to each of the N queries, and return
the indices of each nearest neighbour and their respective distances.
|
List<IntFloatPair> |
searchKNN(OBJECT query,
int K)
Search for the K nearest neighbours to the given query and return an
ordered list of pairs containing the distance and index of each
neighbour.
|
void |
searchNN(List<OBJECT> qus,
int[] argmins,
float[] mins)
Search for the nearest neighbour to each of the N queries, and return the
index of each nearest neighbour and the respective distance.
|
IntFloatPair |
searchNN(OBJECT query)
Search for the nearest neighbour to the given query and return a pair
containing the distance and index of that neighbour.
|
void |
searchNN(OBJECT[] qus,
int[] argmins,
float[] mins)
Search for the nearest neighbour to each of the N queries, and return the
index of each nearest neighbour and the respective distance.
|
int |
size()
Get the size of the dataset
|
protected DistanceComparator<OBJECT> distanceFcn
public LSHNearestNeighbours(List<HashFunction<OBJECT>> tableHashes, DistanceComparator<OBJECT> distanceFcn)
tableHashes
- The hash functionsdistanceFcn
- The distance functionpublic LSHNearestNeighbours(HashFunctionFactory<OBJECT> factory, int numTables, DistanceComparator<OBJECT> distanceFcn)
factory
- The hash function factory.numTables
- The number of requested tables.distanceFcn
- The distance function.public int numTables()
public void addAll(Collection<OBJECT> d)
d
- the datapublic int add(OBJECT o)
IncrementalNearestNeighbours
add
in interface IncrementalNearestNeighbours<OBJECT,float[],IntFloatPair>
o
- the object to addpublic gnu.trove.set.hash.TIntHashSet[] search(OBJECT[] data)
data
- the pointspublic gnu.trove.set.hash.TIntHashSet search(OBJECT data)
data
- the pointpublic int[][] getBucketId(OBJECT[] data)
data
- the pointspublic int[] getBucketId(OBJECT point)
point
- the pointpublic void searchNN(OBJECT[] qus, int[] argmins, float[] mins)
NearestNeighbours
For efficiency, to use this method, you need to pre-construct the arrays for storing the results outside of the method and pass them in as arguments.
If a nearest-neighbour cannot be determined, it will have an index value of -1
searchNN
in interface NearestNeighbours<OBJECT,float[],IntFloatPair>
qus
- An array of N query vectorsargmins
- The return N-dimensional array for holding the indices of the
nearest neighbour of each respective query.mins
- The return N-dimensional array for holding the distances of
the nearest neighbour to each respective query.public void searchKNN(OBJECT[] qus, int K, int[][] argmins, float[][] mins)
NearestNeighbours
For efficiency, to use this method, you need to pre-construct the arrays for storing the results outside of the method and pass them in as arguments.
If a k-th nearest-neighbour cannot be determined, it will have an index value of -1
searchKNN
in interface NearestNeighbours<OBJECT,float[],IntFloatPair>
qus
- An array of N query vectorsK
- the number of neighbours to findargmins
- The return N*K-dimensional array for holding the indices of
the K nearest neighbours of each respective query.mins
- The return N*K-dimensional array for holding the distances of
the nearest neighbours of each respective query.public void searchNN(List<OBJECT> qus, int[] argmins, float[] mins)
NearestNeighbours
For efficiency, to use this method, you need to pre-construct the arrays for storing the results outside of the method and pass them in as arguments.
If a nearest-neighbour cannot be determined, it will have an index value of -1
searchNN
in interface NearestNeighbours<OBJECT,float[],IntFloatPair>
qus
- An array of N query vectorsargmins
- The return N-dimensional array for holding the indices of the
nearest neighbour of each respective query.mins
- The return N-dimensional array for holding the distances of
the nearest neighbour to each respective query.public void searchKNN(List<OBJECT> qus, int K, int[][] argmins, float[][] mins)
NearestNeighbours
For efficiency, to use this method, you need to pre-construct the arrays for storing the results outside of the method and pass them in as arguments.
If a k-th nearest-neighbour cannot be determined, it will have an index value of -1
searchKNN
in interface NearestNeighbours<OBJECT,float[],IntFloatPair>
qus
- An array of N query vectorsK
- the number of neighbours to findargmins
- The return N*K-dimensional array for holding the indices of
the K nearest neighbours of each respective query.mins
- The return N*K-dimensional array for holding the distances of
the nearest neighbours of each respective query.public int size()
NearestNeighbours
size
in interface NearestNeighbours<OBJECT,float[],IntFloatPair>
public List<OBJECT> getData()
public OBJECT get(int i)
i
- The indexpublic int[] addAll(List<OBJECT> d)
IncrementalNearestNeighbours
addAll
in interface IncrementalNearestNeighbours<OBJECT,float[],IntFloatPair>
d
- the datapublic List<IntFloatPair> searchKNN(OBJECT query, int K)
NearestNeighbours
If k neighbours cannot be determined, then the resultant list might have fewer than k elements.
searchKNN
in interface NearestNeighbours<OBJECT,float[],IntFloatPair>
query
- the query vectorK
- the number of neighbours to search forpublic IntFloatPair searchNN(OBJECT query)
NearestNeighbours
If the nearest-neighbour cannot be determined null
will be
returned.
searchNN
in interface NearestNeighbours<OBJECT,float[],IntFloatPair>
query
- the query vector