|
|
# k-Nearest-Neighbors Search
|
|
|
|
|
|
An implementation of k-nearest-neighbor search using single-tree and dual-tree algorithms. Given a set of reference points and query points, this can find the k nearest neighbors in the reference set of each query point using trees.
|
|
|
|
|
|
# Available Predicates
|
|
|
|
|
|
* [initAndBuildModel/10](/PrologMethods/Geometry/knn#initandbuildmodel10)
|
|
|
* [searchWithQuery/10](/PrologMethods/Geometry/knn#searchwithquery10)
|
|
|
* [searchNoQuery/7](/PrologMethods/Geometry/knn#searchnoquery7)
|
|
|
|
|
|
---
|
|
|
|
|
|
[links/resources](/PrologMethods/Geometry/knn#connected-linksresources)
|
|
|
|
|
|
## **_initAndBuildModel/10_**
|
|
|
|
|
|
Initialize the Model and build it.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
initAndBuildModel( +string, +string,
|
|
|
+integer,
|
|
|
+integer, +float32, +float32, +float32,
|
|
|
+pointer(float_array), +integer, +integer).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| treeType | +string | Type of tree to use: "kd", "vp", "rp", "max-rp", "ub", "cover", "r", "r-star", "x", "ball", "hilbert-r", "r-plus", "r-plus-plus", "spill", "oct". | kd |
|
|
|
| searchMode | +string | Type of neighbor search: "naive", "single_tree", "dual_tree", "greedy". | dual_tree |
|
|
|
| randomBasis | +integer(bool) | Before tree-building, project the data onto a random orthogonal basis. | (0)false |
|
|
|
| leafSize | +integer | Leaf size for tree building. Not used by cover trees | 20 |
|
|
|
| tau | +float | Overlapping size (only valid for spill trees). | 0.7 |
|
|
|
| rho | +float | Balance threshold (only valid for spill trees). | 0.0 |
|
|
|
| epsilon | +float | If specified, will do approximate furthest neighbor search with given relative error. Must be in the range \[0,1). | 0.0 |
|
|
|
| referenceSet | +matrix | Matrix containing the reference dataset. | - |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_searchWithQuery/10_**
|
|
|
|
|
|
Perform neighbor search on the queryset.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
searchWithQuery( +pointer(float_array), +integer, +integer,
|
|
|
+integer,
|
|
|
-pointer(float_array), -integer, -integer,
|
|
|
-pointer(float_array), -integer, -integer)
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| querySet | +matrix | Matrix containing query points (optional). | - |
|
|
|
| k | +integer | Number of furthest neighbors to find. | 0 |
|
|
|
| neighbors | -matrix | Matrix to output distances into. | - |
|
|
|
| distances | -matrix | Matrix to output neighbors into. | - |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_searchNoQuery/7_**
|
|
|
|
|
|
Perform monochromatic neighbor search.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
searchNoQuery( +integer,
|
|
|
-pointer(float_array), -integer, -integer,
|
|
|
-pointer(float_array), -integer, -integer)
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| k | +integer | Number of furthest neighbors to find. | 0 |
|
|
|
| neighbors | -matrix | Matrix to output distances into. | - |
|
|
|
| distances | -matrix | Matrix to output neighbors into. | - |
|
|
|
|
|
|
---
|
|
|
|
|
|
# Connected Links/Resources
|
|
|
|
|
|
If you want a more detailed explanation, then go to the python documentation. There is most of the time a good explanation on how the methods work and what the parameters do.
|
|
|
|
|
|
* [MLpack::knn_C++\_documentation](https://www.mlpack.org/doc/stable/doxygen/classmlpack_1_1neighbor_1_1NeighborSearch.html)
|
|
|
* [MLpack::knn_Python_documentation](https://www.mlpack.org/doc/stable/python_documentation.html#knn)
|
|
|
|
|
|
added some of the links from the python documentation
|
|
|
|
|
|
* lsh
|
|
|
* krann
|
|
|
* kfn
|
|
|
* [NeighborSearch tutorial (k-nearest-neighbors)](https://mlpack.org/doc/mlpack-git/doxygen/nstutorial.html)
|
|
|
* [Tree-independent dual-tree algorithms (pdf)](http://proceedings.mlr.press/v28/curtin13.pdf) |
|
|
\ No newline at end of file |