mlpack
Typedefs | Functions
knn_main.cpp File Reference
#include <mlpack/prereqs.hpp>
#include <mlpack/core/util/io.hpp>
#include <mlpack/core/metrics/lmetric.hpp>
#include <mlpack/core/tree/cover_tree.hpp>
#include <mlpack/core/util/mlpack_main.hpp>
#include <string>
#include <fstream>
#include <iostream>
#include "neighbor_search.hpp"
#include "unmap.hpp"
#include "ns_model.hpp"
Include dependency graph for knn_main.cpp:
This graph shows which files directly or indirectly include this file:

Typedefs

typedef NSModel< NearestNeighborSortKNNModel
 

Functions

 BINDING_NAME ("k-Nearest-Neighbors Search")
 
 BINDING_SHORT_DESC ("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; trees that are built can be saved for future use.")
 
 BINDING_LONG_DESC ("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.")
 
 BINDING_EXAMPLE ("For example, the following command will calculate the 5 nearest neighbors " "of each point in "+PRINT_DATASET("input")+" and store the distances " "in "+PRINT_DATASET("distances")+" and the neighbors in "+PRINT_DATASET("neighbors")+": " "\"+PRINT_CALL("knn", "k", 5, "reference", "input", "neighbors", "neighbors", "distances", "distances")+"\" "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.")
 
 BINDING_SEE_ALSO ("@lsh", "#lsh")
 
 BINDING_SEE_ALSO ("@krann", "#krann")
 
 BINDING_SEE_ALSO ("@kfn", "#kfn")
 
 BINDING_SEE_ALSO ("NeighborSearch tutorial (k-nearest-neighbors)", "@doxygen/nstutorial.html")
 
 BINDING_SEE_ALSO ("Tree-independent dual-tree algorithms (pdf)", "http://proceedings.mlr.press/v28/curtin13.pdf")
 
 BINDING_SEE_ALSO ("mlpack::neighbor::NeighborSearch C++ class documentation", "@doxygen/classmlpack_1_1neighbor_1_1NeighborSearch.html")
 
 PARAM_MATRIX_IN ("reference", "Matrix containing the reference dataset.", "r")
 
 PARAM_MATRIX_OUT ("distances", "Matrix to output distances into.", "d")
 
 PARAM_UMATRIX_OUT ("neighbors", "Matrix to output neighbors into.", "n")
 
 PARAM_MATRIX_IN ("true_distances", "Matrix of true distances to compute " "the effective error (average relative error) (it is printed when -v is " "specified).", "D")
 
 PARAM_UMATRIX_IN ("true_neighbors", "Matrix of true neighbors to compute the " "recall (it is printed when -v is specified).", "T")
 
 PARAM_MODEL_IN (KNNModel, "input_model", "Pre-trained kNN model.", "m")
 
 PARAM_MODEL_OUT (KNNModel, "output_model", "If specified, the kNN model will be " "output here.", "M")
 
 PARAM_MATRIX_IN ("query", "Matrix containing query points (optional).", "q")
 
 PARAM_INT_IN ("k", "Number of nearest neighbors to find.", "k", 0)
 
 PARAM_STRING_IN ("tree_type", "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'.", "t", "kd")
 
 PARAM_INT_IN ("leaf_size", "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).", "l", 20)
 
 PARAM_DOUBLE_IN ("tau", "Overlapping size (only valid for spill trees).", "u", 0)
 
 PARAM_DOUBLE_IN ("rho", "Balance threshold (only valid for spill trees).", "b", 0.7)
 
 PARAM_FLAG ("random_basis", "Before tree-building, project the data onto a " "random orthogonal basis.", "R")
 
 PARAM_INT_IN ("seed", "Random seed (if 0, std::time(NULL) is used).", "s", 0)
 
 PARAM_STRING_IN ("algorithm", "Type of neighbor search: 'naive', 'single_tree', " "'dual_tree', 'greedy'.", "a", "dual_tree")
 
 PARAM_DOUBLE_IN ("epsilon", "If specified, will do approximate nearest neighbor " "search with given relative error.", "e", 0)
 

Detailed Description

Author
Ryan Curtin

Implementation of the kNN executable. Allows some number of standard options.

mlpack is free software; you may redistribute it and/or modify it under the terms of the 3-clause BSD license. You should have received a copy of the 3-clause BSD license along with mlpack. If not, see http://www.opensource.org/licenses/BSD-3-Clause for more information.