---
name: "mlpack_neighbor_NeighborSearchRules"
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_NeighborSearchRules"
---

# mlpack\_neighbor\_NeighborSearchRules(3)

## NAME

mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \> -

## SYNOPSIS

### Public Types

typedef \
 **NeighborSearchTraversalInfo**\
 \< TreeType \> **TraversalInfoType**"\
 *Convenience typedef.*

### Public Member Functions

**NeighborSearchRules** (const typename TreeType::Mat &**referenceSet**, const typename TreeType::Mat &**querySet**, arma::Mat\< size\_t \> &**neighbors**, arma::mat &**distances**, MetricType &**metric**)\
 double **BaseCase** (const size\_t queryIndex, const size\_t referenceIndex)\
 *Get the distance from the query point to the reference point.*  size\_t **BaseCases** () const \
 *Get the number of base cases that have been performed.*  size\_t & **BaseCases** ()\
 *Modify the number of base cases that have been performed.*  double **Rescore** (const size\_t queryIndex, TreeType &referenceNode, const double oldScore) const \
 *Re-evaluate the score for recursion order.*  double **Rescore** (TreeType &queryNode, TreeType &referenceNode, const double oldScore) const \
 *Re-evaluate the score for recursion order.*  double **Score** (const size\_t queryIndex, TreeType &referenceNode)\
 *Get the score for recursion order.*  double **Score** (TreeType &queryNode, TreeType &referenceNode)\
 *Get the score for recursion order.*  size\_t **Scores** () const \
 *Get the number of scores that have been performed.*  size\_t & **Scores** ()\
 *Modify the number of scores that have been performed.*  const **TraversalInfoType** & **TraversalInfo** () const \
 *Get the traversal info.*  **TraversalInfoType** & **TraversalInfo** ()\
 *Modify the traversal info.*

### Private Member Functions

double **CalculateBound** (TreeType &queryNode) const \
 *Recalculate the bound for a given query node.*  void **InsertNeighbor** (const size\_t queryIndex, const size\_t pos, const size\_t neighbor, const double distance)\
 *Insert a point into the neighbors and distances matrices; this is a helper function.*

### Private Attributes

size\_t **baseCases**\
 *The number of base cases that have been performed.*  arma::mat & **distances**\
 *The matrix the resultant neighbor distances should be stored in.*  double **lastBaseCase**\
 *The last base case result.*  size\_t **lastQueryIndex**\
 *The last query point* **BaseCase()** *was called with.*  size\_t **lastReferenceIndex**\
 *The last reference point* **BaseCase()** *was called with.*  MetricType & **metric**\
 *The instantiated metric.*  arma::Mat\< size\_t \> & **neighbors**\
 *The matrix the resultant neighbor indices should be stored in.*  const TreeType::Mat & **querySet**\
 *The query set.*  const TreeType::Mat & **referenceSet**\
 *The reference set.*  size\_t **scores**\
 *The number of scores that have been performed.*  **TraversalInfoType** **traversalInfo**\
 *Traversal info for the parent combination; this is updated by the traversal before each call to* **Score()***.*

## Detailed Description

### template\<typename SortPolicy, typename MetricType, typename TreeType\>class mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>

Definition at line 32 of file neighbor\_search\_rules.hpp.

## Member Typedef Documentation

### template\<typename SortPolicy , typename MetricType , typename TreeType \> typedef NeighborSearchTraversalInfo\<TreeType\> mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::TraversalInfoType

Convenience typedef.

Definition at line 111 of file neighbor\_search\_rules.hpp.

## Constructor & Destructor Documentation

### template\<typename SortPolicy , typename MetricType , typename TreeType \> mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::NeighborSearchRules (const typename TreeType::Mat &referenceSet, const typename TreeType::Mat &querySet, arma::Mat\< size\_t \> &neighbors, arma::mat &distances, MetricType &metric)

## Member Function Documentation

### template\<typename SortPolicy , typename MetricType , typename TreeType \> double mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::BaseCase (const size\_tqueryIndex, const size\_treferenceIndex)

Get the distance from the query point to the reference point. This will update the 'neighbor' matrix with the new point if appropriate and will track the number of base cases (number of points evaluated).

**Parameters:**

*queryIndex* Index of query point. \
 *referenceIndex* Index of reference point.

### template\<typename SortPolicy , typename MetricType , typename TreeType \> size\_t mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::BaseCases () const` [inline]`

Get the number of base cases that have been performed.

Definition at line 101 of file neighbor\_search\_rules.hpp.

References mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::baseCases.

### template\<typename SortPolicy , typename MetricType , typename TreeType \> size\_t& mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::BaseCases ()` [inline]`

Modify the number of base cases that have been performed.

Definition at line 103 of file neighbor\_search\_rules.hpp.

References mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::baseCases.

### template\<typename SortPolicy , typename MetricType , typename TreeType \> double mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::CalculateBound (TreeType &queryNode) const` [private]`

Recalculate the bound for a given query node.

### template\<typename SortPolicy , typename MetricType , typename TreeType \> void mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::InsertNeighbor (const size\_tqueryIndex, const size\_tpos, const size\_tneighbor, const doubledistance)` [private]`

Insert a point into the neighbors and distances matrices; this is a helper function.

**Parameters:**

*queryIndex* Index of point whose neighbors we are inserting into. \
 *pos* Position in list to insert into. \
 *neighbor* Index of reference point which is being inserted. \
 *distance* Distance from query point to reference point.

### template\<typename SortPolicy , typename MetricType , typename TreeType \> double mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::Rescore (const size\_tqueryIndex, TreeType &referenceNode, const doubleoldScore) const

Re-evaluate the score for recursion order. A low score indicates priority for recursion, while DBL\_MAX indicates that the node should not be recursed into at all (it should be pruned). This is used when the score has already been calculated, but another recursion may have modified the bounds for pruning. So the old score is checked against the new pruning bound.

**Parameters:**

*queryIndex* Index of query point. \
 *referenceNode* Candidate node to be recursed into. \
 *oldScore* Old score produced by **Score()** (or **Rescore()**).

### template\<typename SortPolicy , typename MetricType , typename TreeType \> double mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::Rescore (TreeType &queryNode, TreeType &referenceNode, const doubleoldScore) const

Re-evaluate the score for recursion order. A low score indicates priority for recursion, while DBL\_MAX indicates that the node should not be recursed into at all (it should be pruned). This is used when the score has already been calculated, but another recursion may have modified the bounds for pruning. So the old score is checked against the new pruning bound.

**Parameters:**

*queryNode* Candidate query node to recurse into. \
 *referenceNode* Candidate reference node to recurse into. \
 *oldScore* Old score produced by Socre() (or **Rescore()**).

### template\<typename SortPolicy , typename MetricType , typename TreeType \> double mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::Score (const size\_tqueryIndex, TreeType &referenceNode)

Get the score for recursion order. A low score indicates priority for recursion, while DBL\_MAX indicates that the node should not be recursed into at all (it should be pruned).

**Parameters:**

*queryIndex* Index of query point. \
 *referenceNode* Candidate node to be recursed into.

### template\<typename SortPolicy , typename MetricType , typename TreeType \> double mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::Score (TreeType &queryNode, TreeType &referenceNode)

Get the score for recursion order. A low score indicates priority for recursionm while DBL\_MAX indicates that the node should not be recursed into at all (it should be pruned).

**Parameters:**

*queryNode* Candidate query node to recurse into. \
 *referenceNode* Candidate reference node to recurse into.

### template\<typename SortPolicy , typename MetricType , typename TreeType \> size\_t mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::Scores () const` [inline]`

Get the number of scores that have been performed.

Definition at line 106 of file neighbor\_search\_rules.hpp.

References mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::scores.

### template\<typename SortPolicy , typename MetricType , typename TreeType \> size\_t& mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::Scores ()` [inline]`

Modify the number of scores that have been performed.

Definition at line 108 of file neighbor\_search\_rules.hpp.

References mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::scores.

### template\<typename SortPolicy , typename MetricType , typename TreeType \> const TraversalInfoType& mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::TraversalInfo () const` [inline]`

Get the traversal info.

Definition at line 114 of file neighbor\_search\_rules.hpp.

References mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::traversalInfo.

### template\<typename SortPolicy , typename MetricType , typename TreeType \> TraversalInfoType& mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::TraversalInfo ()` [inline]`

Modify the traversal info.

Definition at line 116 of file neighbor\_search\_rules.hpp.

References mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::traversalInfo.

## Member Data Documentation

### template\<typename SortPolicy , typename MetricType , typename TreeType \> size\_t mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::baseCases` [private]`

The number of base cases that have been performed.

Definition at line 142 of file neighbor\_search\_rules.hpp.

Referenced by mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::BaseCases().

### template\<typename SortPolicy , typename MetricType , typename TreeType \> arma::mat& mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::distances` [private]`

The matrix the resultant neighbor distances should be stored in.

Definition at line 129 of file neighbor\_search\_rules.hpp.

### template\<typename SortPolicy , typename MetricType , typename TreeType \> double mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::lastBaseCase` [private]`

The last base case result.

Definition at line 139 of file neighbor\_search\_rules.hpp.

### template\<typename SortPolicy , typename MetricType , typename TreeType \> size\_t mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::lastQueryIndex` [private]`

The last query point **BaseCase()** was called with.

Definition at line 135 of file neighbor\_search\_rules.hpp.

### template\<typename SortPolicy , typename MetricType , typename TreeType \> size\_t mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::lastReferenceIndex` [private]`

The last reference point **BaseCase()** was called with.

Definition at line 137 of file neighbor\_search\_rules.hpp.

### template\<typename SortPolicy , typename MetricType , typename TreeType \> MetricType& mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::metric` [private]`

The instantiated metric.

Definition at line 132 of file neighbor\_search\_rules.hpp.

### template\<typename SortPolicy , typename MetricType , typename TreeType \> arma::Mat\<size\_t\>& mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::neighbors` [private]`

The matrix the resultant neighbor indices should be stored in.

Definition at line 126 of file neighbor\_search\_rules.hpp.

### template\<typename SortPolicy , typename MetricType , typename TreeType \> const TreeType::Mat& mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::querySet` [private]`

The query set.

Definition at line 123 of file neighbor\_search\_rules.hpp.

### template\<typename SortPolicy , typename MetricType , typename TreeType \> const TreeType::Mat& mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::referenceSet` [private]`

The reference set.

Definition at line 120 of file neighbor\_search\_rules.hpp.

### template\<typename SortPolicy , typename MetricType , typename TreeType \> size\_t mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::scores` [private]`

The number of scores that have been performed.

Definition at line 144 of file neighbor\_search\_rules.hpp.

Referenced by mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::Scores().

### template\<typename SortPolicy , typename MetricType , typename TreeType \> TraversalInfoType mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::traversalInfo` [private]`

Traversal info for the parent combination; this is updated by the traversal before each call to **Score()**.

Definition at line 148 of file neighbor\_search\_rules.hpp.

Referenced by mlpack::neighbor::NeighborSearchRules\< SortPolicy, MetricType, TreeType \>::TraversalInfo().

## Author

Generated automatically by Doxygen for MLPACK from the source code.
