.\" Text automatically generated by txt2man .TH mlpack_knn 1 "12 December 2020" "mlpack-3.4.2" "User Commands" .SH NAME \fBmlpack_knn \fP- k-nearest-neighbors search .SH SYNOPSIS .nf .fam C \fBmlpack_knn\fP [\fB-a\fP \fIstring\fP] [\fB-e\fP \fIdouble\fP] [\fB-m\fP \fIunknown\fP] [\fB-k\fP \fIint\fP] [\fB-l\fP \fIint\fP] [\fB-q\fP \fIstring\fP] [\fB-R\fP \fIbool\fP] [\fB-r\fP \fIstring\fP] [\fB-b\fP \fIdouble\fP] [\fB-s\fP \fIint\fP] [\fB-u\fP \fIdouble\fP] [\fB-t\fP \fIstring\fP] [\fB-D\fP \fIstring\fP] [\fB-T\fP \fIstring\fP] [\fB-V\fP \fIbool\fP] [\fB-d\fP \fIstring\fP] [\fB-n\fP \fIstring\fP] [\fB-M\fP \fIunknown\fP] [\fB-h\fP \fB-v\fP] .fam T .fi .fam T .fi .SH DESCRIPTION This program will calculate the k-nearest-neighbors of a set of points using kd-trees or cover trees (cover tree support is experimental and may be slow). You may specify a separate set of reference points and query points, or just a reference set which will be used as both the reference and query set. .PP For example, the following command will calculate the 5 nearest neighbors of each point in 'input.csv' and store the distances in 'distances.csv' and the neighbors in 'neighbors.csv': .PP $ \fBmlpack_knn\fP \fB--k\fP 5 \fB--reference_file\fP input.csv \fB--neighbors_file\fP neighbors.csv \fB--distances_file\fP distances.csv .PP The output is organized such that row i and column j in the neighbors output matrix corresponds to the index of the point in the reference set which is the j'th nearest neighbor from the point in the query set with index i. Row j and column i in the distances output matrix corresponds to the distance between those two points. .RE .PP .SH OPTIONAL INPUT OPTIONS .TP .B \fB--algorithm\fP (\fB-a\fP) [\fIstring\fP] Type of neighbor search: 'naive', 'single_tree', 'dual_tree', 'greedy'. Default value 'dual_tree'. .TP .B \fB--epsilon\fP (\fB-e\fP) [\fIdouble\fP] If specified, will do approximate nearest neighbor search with given relative error. Default value 0. .TP .B \fB--help\fP (\fB-h\fP) [\fIbool\fP] Default help info. .TP .B \fB--info\fP [\fIstring\fP] Print help on a specific option. Default value ''. .TP .B \fB--input_model_file\fP (\fB-m\fP) [\fIunknown\fP] Pre-trained kNN model. .TP .B \fB--k\fP (\fB-k\fP) [\fIint\fP] Number of nearest neighbors to find. Default value 0. .TP .B \fB--leaf_size\fP (\fB-l\fP) [\fIint\fP] Leaf size for tree building (used for kd-trees, vp trees, random projection trees, UB trees, R trees, R* trees, X trees, Hilbert R trees, R+ trees, R++ trees, spill trees, and octrees). Default value 20. .TP .B \fB--query_file\fP (\fB-q\fP) [\fIstring\fP] Matrix containing query points (optional). .TP .B \fB--random_basis\fP (\fB-R\fP) [\fIbool\fP] Before tree-building, project the data onto a random orthogonal basis. .TP .B \fB--reference_file\fP (\fB-r\fP) [\fIstring\fP] Matrix containing the reference dataset. .TP .B \fB--rho\fP (\fB-b\fP) [\fIdouble\fP] Balance threshold (only valid for spill trees). Default value 0.7. .TP .B \fB--seed\fP (\fB-s\fP) [\fIint\fP] Random seed (if 0, \fBstd::time\fP(NULL) is used). Default value 0. .TP .B \fB--tau\fP (\fB-u\fP) [\fIdouble\fP] Overlapping size (only valid for spill trees). Default value 0. .TP .B \fB--tree_type\fP (\fB-t\fP) [\fIstring\fP] 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'. Default value 'kd'. .TP .B \fB--true_distances_file\fP (\fB-D\fP) [\fIstring\fP] Matrix of true distances to compute the effective error (average relative error) (it is printed when \fB-v\fP is specified). .TP .B \fB--true_neighbors_file\fP (\fB-T\fP) [\fIstring\fP] Matrix of true neighbors to compute the recall (it is printed when \fB-v\fP is specified). .TP .B \fB--verbose\fP (\fB-v\fP) [\fIbool\fP] Display informational messages and the full list of parameters and timers at the end of execution. .TP .B \fB--version\fP (\fB-V\fP) [\fIbool\fP] Display the version of mlpack. .SH OPTIONAL OUTPUT OPTIONS .TP .B \fB--distances_file\fP (\fB-d\fP) [\fIstring\fP] Matrix to output distances into. .TP .B \fB--neighbors_file\fP (\fB-n\fP) [\fIstring\fP] Matrix to output neighbors into. .TP .B \fB--output_model_file\fP (\fB-M\fP) [\fIunknown\fP] If specified, the kNN model will be output here. .SH ADDITIONAL INFORMATION For further information, including relevant papers, citations, and theory, consult the documentation found at http://www.mlpack.org or included with your distribution of mlpack.