---
name: "mlpack_neighbor"
section: "3"
platform: "linux"
package: "mlpack-doc"
version: "1.0.10-1"
release: "Debian 8 (Jessie)"
platforms: ["linux"]
url: "https://new.carta.tech/mlpack_neighbor"
---

# mlpack\_neighbor(3)

Neighbor-search routines.

## NAME

mlpack::neighbor -

Neighbor-search routines.

## SYNOPSIS

### Classes

class **FurthestNeighborSort**\
 *This class implements the necessary methods for the SortPolicy template parameter of the* **NeighborSearch** *class.*  class **LSHSearch**\
 *The* **LSHSearch** *class -- This class builds a hash on the reference set and uses this hash to compute the distance-approximate nearest-neighbors of the given queries.*  class **NearestNeighborSort**\
 *This class implements the necessary methods for the SortPolicy template parameter of the* **NeighborSearch** *class.*  class **NeighborSearch**\
 *The* **NeighborSearch** *class is a template class for performing distance-based neighbor searches.*  class **NeighborSearchRules**\
 class **NeighborSearchStat**\
 *Extra data for each node in the tree.*  class **NeighborSearchTraversalInfo**\
 *Traversal information for* **NeighborSearch***.*  class **RASearchRules**\

### Typedefs

typedef **NeighborSearch**\
 \< **FurthestNeighborSort**, \
 **metric::EuclideanDistance** \> **AllkFN**"\
 *The AllkFN class is the all-k-furthest-neighbors method.*  typedef **NeighborSearch**\
 \< **NearestNeighborSort**, \
 **metric::EuclideanDistance** \> **AllkNN**"\
 *The AllkNN class is the all-k-nearest-neighbors method.*  typedef **RASearch**\
 \< **FurthestNeighborSort** \> **AllkRAFN**"\
 *The AllkRAFN class is the all-k-rank-approximate-farthest-neighbors method.*  typedef **RASearch** **AllkRANN**\
 *The AllkRANN class is the all-k-rank-approximate-nearest-neighbors method.*

### Functions

void **Unmap** (const arma::Mat\< size\_t \> &neighbors, const arma::mat &distances, const std::vector\< size\_t \> &referenceMap, const std::vector\< size\_t \> &queryMap, arma::Mat\< size\_t \> &neighborsOut, arma::mat &distancesOut, const bool squareRoot=false)\
 *Assuming that the datasets have been mapped using the referenceMap and the queryMap (such as during kd-tree construction), unmap the columns of the distances and neighbors matrices into neighborsOut and distancesOut, and also unmap the entries in each row of neighbors.*  void **Unmap** (const arma::Mat\< size\_t \> &neighbors, const arma::mat &distances, const std::vector\< size\_t \> &referenceMap, arma::Mat\< size\_t \> &neighborsOut, arma::mat &distancesOut, const bool squareRoot=false)\
 *Assuming that the datasets have been mapped using referenceMap (such as during kd-tree construction), unmap the columns of the distances and neighbors matrices into neighborsOut and distancesOut, and also unmap the entries in each row of neighbors.*

## Detailed Description

Neighbor-search routines.

These include all-nearest-neighbors and all-furthest-neighbors searches.

## Typedef Documentation

### typedef NeighborSearch\<FurthestNeighborSort, metric::EuclideanDistance\> mlpack::neighbor::AllkFN

The AllkFN class is the all-k-furthest-neighbors method. It returns L2 distances (Euclidean distances) for each of the k furthest neighbors.

Definition at line 48 of file typedef.hpp.

### typedef NeighborSearch\<NearestNeighborSort, metric::EuclideanDistance\> mlpack::neighbor::AllkNN

The AllkNN class is the all-k-nearest-neighbors method. It returns L2 distances (Euclidean distances) for each of the k nearest neighbors.

Definition at line 42 of file typedef.hpp.

### typedef RASearch\<FurthestNeighborSort\> mlpack::neighbor::AllkRAFN

The AllkRAFN class is the all-k-rank-approximate-farthest-neighbors method. It returns squared L2 distances (squared Euclidean distances) for each of the k rank-approximate farthest-neighbors. Squared distances are used because they are slightly faster than non-squared distances (they have one fewer call to sqrt()).

The approximation is controlled with two parameters (see allkrann\_main.cpp) which can be specified at search time. So the tree building is done only once while the search can be performed multiple times with different approximation levels.

Definition at line 63 of file ra\_typedef.hpp.

### typedef RASearch mlpack::neighbor::AllkRANN

The AllkRANN class is the all-k-rank-approximate-nearest-neighbors method. It returns squared L2 distances (squared Euclidean distances) for each of the k rank-approximate nearest-neighbors. Squared distances are used because they are slightly faster than non-squared distances (they have one fewer call to sqrt()).

The approximation is controlled with two parameters (see allkrann\_main.cpp) which can be specified at search time. So the tree building is done only once while the search can be performed multiple times with different approximation levels.

Definition at line 49 of file ra\_typedef.hpp.

## Function Documentation

### void mlpack::neighbor::Unmap (const arma::Mat\< size\_t \> &neighbors, const arma::mat &distances, const std::vector\< size\_t \> &referenceMap, const std::vector\< size\_t \> &queryMap, arma::Mat\< size\_t \> &neighborsOut, arma::mat &distancesOut, const boolsquareRoot = `false`)

Assuming that the datasets have been mapped using the referenceMap and the queryMap (such as during kd-tree construction), unmap the columns of the distances and neighbors matrices into neighborsOut and distancesOut, and also unmap the entries in each row of neighbors. This is useful for the dual-tree case.

**Parameters:**

*neighbors* Matrix of neighbors resulting from neighbor search. \
 *distances* Matrix of distances resulting from neighbor search. \
 *referenceMap* Mapping of reference set to old points. \
 *queryMap* Mapping of query set to old points. \
 *neighborsOut* Matrix to store unmapped neighbors into. \
 *distancesOut* Matrix to store unmapped distances into. \
 *squareRoot* If true, take the square root of the distances.

### void mlpack::neighbor::Unmap (const arma::Mat\< size\_t \> &neighbors, const arma::mat &distances, const std::vector\< size\_t \> &referenceMap, arma::Mat\< size\_t \> &neighborsOut, arma::mat &distancesOut, const boolsquareRoot = `false`)

Assuming that the datasets have been mapped using referenceMap (such as during kd-tree construction), unmap the columns of the distances and neighbors matrices into neighborsOut and distancesOut, and also unmap the entries in each row of neighbors. This is useful for the single-tree case.

**Parameters:**

*neighbors* Matrix of neighbors resulting from neighbor search. \
 *distances* Matrix of distances resulting from neighbor search. \
 *referenceMap* Mapping of reference set to old points. \
 *neighborsOut* Matrix to store unmapped neighbors into. \
 *distancesOut* Matrix to store unmapped distances into. \
 *squareRoot* If true, take the square root of the distances.

## Author

Generated automatically by Doxygen for MLPACK from the source code.
