public class DoubleNearestNeighboursExact extends DoubleNearestNeighbours
Modifier and Type | Class and Description |
---|---|
static class |
DoubleNearestNeighboursExact.Factory
NearestNeighboursFactory for producing
DoubleNearestNeighboursExact s. |
Modifier and Type | Field and Description |
---|---|
protected DoubleFVComparator |
distance |
protected double[][] |
pnts |
Constructor and Description |
---|
DoubleNearestNeighboursExact(double[][] pnts)
Construct the DoubleNearestNeighboursExact over the provided
dataset and using Euclidean distance.
|
DoubleNearestNeighboursExact(double[][] pnts,
DoubleFVComparator distance)
Construct the DoubleNearestNeighboursExact over the provided
dataset with the given distance function.
|
Modifier and Type | Method and Description |
---|---|
double |
computeDistance(double[] a,
double[] b)
Compute the distance between two vectors using the underlying distance
comparison used by this class.
|
DoubleFVComparator |
distanceComparator()
Get the distance comparator
|
double[][] |
getPoints()
Get the underlying data points.
|
int |
numDimensions()
Get the number of dimensions of each vector in the dataset
|
void |
searchKNN(double[][] qus,
int K,
int[][] indices,
double[][] distances)
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<IntDoublePair> |
searchKNN(double[] 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 |
searchKNN(List<double[]> qus,
int K,
int[][] indices,
double[][] distances)
Search for the K nearest neighbours to each of the N queries, and return
the indices of each nearest neighbour and their respective distances.
|
IntDoublePair |
searchNN(double[] query)
Search for the nearest neighbour to the given query and return a pair
containing the distance and index of that neighbour.
|
void |
searchNN(double[][] qus,
int[] indices,
double[] distances)
Search for the nearest neighbour to each of the N queries, and return the
index of each nearest neighbour and the respective distance.
|
void |
searchNN(List<double[]> qus,
int[] indices,
double[] distances)
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
|
distanceFunc, distanceFunc, distanceFunc, distanceFunc
protected final double[][] pnts
protected final DoubleFVComparator distance
public DoubleNearestNeighboursExact(double[][] pnts)
pnts
- the datasetpublic DoubleNearestNeighboursExact(double[][] pnts, DoubleFVComparator distance)
Note: If the distance function provides similarities rather than distances they are automatically inverted.
pnts
- the datasetdistance
- the distance functionpublic void searchNN(double[][] qus, int[] indices, double[] distances)
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
qus
- An array of N query vectorsindices
- The return N-dimensional array for holding the indices of the
nearest neighbour of each respective query.distances
- The return N-dimensional array for holding the distances of
the nearest neighbour to each respective query.public void searchKNN(double[][] qus, int K, int[][] indices, double[][] distances)
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
qus
- An array of N query vectorsK
- the number of neighbours to findindices
- The return N*K-dimensional array for holding the indices of
the K nearest neighbours of each respective query.distances
- The return N*K-dimensional array for holding the distances of
the nearest neighbours of each respective query.public void searchNN(List<double[]> qus, int[] indices, double[] distances)
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
qus
- An array of N query vectorsindices
- The return N-dimensional array for holding the indices of the
nearest neighbour of each respective query.distances
- The return N-dimensional array for holding the distances of
the nearest neighbour to each respective query.public void searchKNN(List<double[]> qus, int K, int[][] indices, double[][] distances)
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
qus
- An array of N query vectorsK
- the number of neighbours to findindices
- The return N*K-dimensional array for holding the indices of
the K nearest neighbours of each respective query.distances
- The return N*K-dimensional array for holding the distances of
the nearest neighbours of each respective query.public List<IntDoublePair> searchKNN(double[] query, int K)
NearestNeighbours
If k neighbours cannot be determined, then the resultant list might have fewer than k elements.
query
- the query vectorK
- the number of neighbours to search forpublic IntDoublePair searchNN(double[] query)
NearestNeighbours
If the nearest-neighbour cannot be determined null
will be
returned.
query
- the query vectorpublic int numDimensions()
DoubleNearestNeighbours
numDimensions
in class DoubleNearestNeighbours
public int size()
NearestNeighbours
public double[][] getPoints()
public double computeDistance(double[] a, double[] b)
a
- the first vectorb
- the second vectorpublic DoubleFVComparator distanceComparator()