\section{R\+A\+Search$<$ Sort\+Policy, Metric\+Type, Mat\+Type, Tree\+Type $>$ Class Template Reference}
\label{classmlpack_1_1neighbor_1_1RASearch}\index{R\+A\+Search$<$ Sort\+Policy, Metric\+Type, Mat\+Type, Tree\+Type $>$@{R\+A\+Search$<$ Sort\+Policy, Metric\+Type, Mat\+Type, Tree\+Type $>$}}


The \doxyref{R\+A\+Search}{p.}{classmlpack_1_1neighbor_1_1RASearch} class\+: This class provides a generic manner to perform rank-\/approximate search via random-\/sampling.  


\subsection*{Public Types}
\begin{DoxyCompactItemize}
\item 
typedef Tree\+Type$<$ Metric\+Type, \textbf{ R\+A\+Query\+Stat}$<$ Sort\+Policy $>$, Mat\+Type $>$ \textbf{ Tree}
\begin{DoxyCompactList}\small\item\em Convenience typedef. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\textbf{ R\+A\+Search} (Mat\+Type reference\+Set, const bool naive=false, const bool single\+Mode=false, const double tau=5, const double alpha=0.\+95, const bool sample\+At\+Leaves=false, const bool first\+Leaf\+Exact=false, const size\+\_\+t single\+Sample\+Limit=20, const Metric\+Type metric=Metric\+Type())
\begin{DoxyCompactList}\small\item\em Initialize the \doxyref{R\+A\+Search}{p.}{classmlpack_1_1neighbor_1_1RASearch} object, passing both a reference dataset (this is the dataset that will be searched). \end{DoxyCompactList}\item 
\textbf{ R\+A\+Search} (\textbf{ Tree} $\ast$reference\+Tree, const bool single\+Mode=false, const double tau=5, const double alpha=0.\+95, const bool sample\+At\+Leaves=false, const bool first\+Leaf\+Exact=false, const size\+\_\+t single\+Sample\+Limit=20, const Metric\+Type metric=Metric\+Type())
\begin{DoxyCompactList}\small\item\em Initialize the \doxyref{R\+A\+Search}{p.}{classmlpack_1_1neighbor_1_1RASearch} object with the given pre-\/constructed reference tree. \end{DoxyCompactList}\item 
\textbf{ R\+A\+Search} (const bool naive=false, const bool single\+Mode=false, const double tau=5, const double alpha=0.\+95, const bool sample\+At\+Leaves=false, const bool first\+Leaf\+Exact=false, const size\+\_\+t single\+Sample\+Limit=20, const Metric\+Type metric=Metric\+Type())
\begin{DoxyCompactList}\small\item\em Create an \doxyref{R\+A\+Search}{p.}{classmlpack_1_1neighbor_1_1RASearch} object with no reference data. \end{DoxyCompactList}\item 
\textbf{ $\sim$\+R\+A\+Search} ()
\begin{DoxyCompactList}\small\item\em Delete the \doxyref{R\+A\+Search}{p.}{classmlpack_1_1neighbor_1_1RASearch} object. \end{DoxyCompactList}\item 
double \textbf{ Alpha} () const
\begin{DoxyCompactList}\small\item\em Get the desired success probability. \end{DoxyCompactList}\item 
double \& \textbf{ Alpha} ()
\begin{DoxyCompactList}\small\item\em Modify the desired success probability. \end{DoxyCompactList}\item 
bool \textbf{ First\+Leaf\+Exact} () const
\begin{DoxyCompactList}\small\item\em Get whether or not we traverse to the first leaf without approximation. \end{DoxyCompactList}\item 
bool \& \textbf{ First\+Leaf\+Exact} ()
\begin{DoxyCompactList}\small\item\em Modify whether or not we traverse to the first leaf without approximation. \end{DoxyCompactList}\item 
bool \textbf{ Naive} () const
\begin{DoxyCompactList}\small\item\em Get whether or not naive (brute-\/force) search is used. \end{DoxyCompactList}\item 
bool \& \textbf{ Naive} ()
\begin{DoxyCompactList}\small\item\em Modify whether or not naive (brute-\/force) search is used. \end{DoxyCompactList}\item 
const Mat\+Type \& \textbf{ Reference\+Set} () const
\begin{DoxyCompactList}\small\item\em Access the reference set. \end{DoxyCompactList}\item 
void \textbf{ Reset\+Query\+Tree} (\textbf{ Tree} $\ast$query\+Tree) const
\begin{DoxyCompactList}\small\item\em This function recursively resets the \doxyref{R\+A\+Query\+Stat}{p.}{classmlpack_1_1neighbor_1_1RAQueryStat} of the given query tree to set \textquotesingle{}bound\textquotesingle{} to Sort\+Policy\+::\+Worst\+Distance and \textquotesingle{}num\+Samples\+Made\textquotesingle{} to 0. \end{DoxyCompactList}\item 
bool \textbf{ Sample\+At\+Leaves} () const
\begin{DoxyCompactList}\small\item\em Get whether or not sampling is done at the leaves. \end{DoxyCompactList}\item 
bool \& \textbf{ Sample\+At\+Leaves} ()
\begin{DoxyCompactList}\small\item\em Modify whether or not sampling is done at the leaves. \end{DoxyCompactList}\item 
void \textbf{ Search} (const Mat\+Type \&query\+Set, const size\+\_\+t k, arma\+::\+Mat$<$ size\+\_\+t $>$ \&neighbors, arma\+::mat \&distances)
\begin{DoxyCompactList}\small\item\em Compute the rank approximate nearest neighbors of each query point in the query set and store the output in the given matrices. \end{DoxyCompactList}\item 
void \textbf{ Search} (\textbf{ Tree} $\ast$query\+Tree, const size\+\_\+t k, arma\+::\+Mat$<$ size\+\_\+t $>$ \&neighbors, arma\+::mat \&distances)
\begin{DoxyCompactList}\small\item\em Compute the rank approximate nearest neighbors of each point in the pre-\/built query tree and store the output in the given matrices. \end{DoxyCompactList}\item 
void \textbf{ Search} (const size\+\_\+t k, arma\+::\+Mat$<$ size\+\_\+t $>$ \&neighbors, arma\+::mat \&distances)
\begin{DoxyCompactList}\small\item\em Compute the rank approximate nearest neighbors of each point in the reference set (that is, the query set is taken to be the reference set), and store the output in the given matrices. \end{DoxyCompactList}\item 
{\footnotesize template$<$typename Archive $>$ }\\void \textbf{ serialize} (Archive \&ar, const unsigned int)
\begin{DoxyCompactList}\small\item\em Serialize the object. \end{DoxyCompactList}\item 
bool \textbf{ Single\+Mode} () const
\begin{DoxyCompactList}\small\item\em Get whether or not single-\/tree search is used. \end{DoxyCompactList}\item 
bool \& \textbf{ Single\+Mode} ()
\begin{DoxyCompactList}\small\item\em Modify whether or not single-\/tree search is used. \end{DoxyCompactList}\item 
size\+\_\+t \textbf{ Single\+Sample\+Limit} () const
\begin{DoxyCompactList}\small\item\em Get the limit on the size of a node that can be approximated. \end{DoxyCompactList}\item 
size\+\_\+t \& \textbf{ Single\+Sample\+Limit} ()
\begin{DoxyCompactList}\small\item\em Modify the limit on the size of a node that can be approximation. \end{DoxyCompactList}\item 
double \textbf{ Tau} () const
\begin{DoxyCompactList}\small\item\em Get the rank-\/approximation in percentile of the data. \end{DoxyCompactList}\item 
double \& \textbf{ Tau} ()
\begin{DoxyCompactList}\small\item\em Modify the rank-\/approximation in percentile of the data. \end{DoxyCompactList}\item 
void \textbf{ Train} (Mat\+Type reference\+Set)
\begin{DoxyCompactList}\small\item\em \char`\"{}\+Train\char`\"{} the model on the given reference set. \end{DoxyCompactList}\item 
void \textbf{ Train} (\textbf{ Tree} $\ast$reference\+Tree)
\begin{DoxyCompactList}\small\item\em Set the reference tree to a new reference tree. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
\subsubsection*{template$<$typename Sort\+Policy = Nearest\+Neighbor\+Sort, typename Metric\+Type = metric\+::\+Euclidean\+Distance, typename Mat\+Type = arma\+::mat, template$<$ typename Tree\+Metric\+Type, typename Tree\+Stat\+Type, typename Tree\+Mat\+Type $>$ class Tree\+Type = tree\+::\+K\+D\+Tree$>$\newline
class mlpack\+::neighbor\+::\+R\+A\+Search$<$ Sort\+Policy, Metric\+Type, Mat\+Type, Tree\+Type $>$}

The \doxyref{R\+A\+Search}{p.}{classmlpack_1_1neighbor_1_1RASearch} class\+: This class provides a generic manner to perform rank-\/approximate search via random-\/sampling. 

If the \textquotesingle{}naive\textquotesingle{} option is chosen, this rank-\/approximate search will be done by randomly sampling from the whole set. If the \textquotesingle{}naive\textquotesingle{} option is not chosen, the sampling is done in a stratified manner in the tree as mentioned in the algorithms in Figure 2 of the following paper\+:

\{ram2009rank, title=\{\{Rank-\/\+Approximate Nearest Neighbor Search\+: Retaining Meaning and Speed in High Dimensions\}\}, author=\{\{Ram, P. and Lee, D. and Ouyang, H. and Gray, A. G.\}\}, booktitle=\{\{Advances of Neural Information Processing Systems\}\}, year=\{2009\} \}

\doxyref{R\+A\+Search}{p.}{classmlpack_1_1neighbor_1_1RASearch} is currently known to not work with ball trees (\#356).


\begin{DoxyTemplParams}{Template Parameters}
{\em Sort\+Policy} & The sort policy for distances; see Nearest\+Neighbor\+Sort. \\
\hline
{\em Metric\+Type} & The metric to use for computation. \\
\hline
{\em Tree\+Type} & The tree type to use. \\
\hline
\end{DoxyTemplParams}


Definition at line 71 of file ra\+\_\+search.\+hpp.



\subsection{Member Typedef Documentation}
\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_a23f60d6d543928c40d96f87711eeba19}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Tree@{Tree}}
\index{Tree@{Tree}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Tree}
{\footnotesize\ttfamily typedef Tree\+Type$<$Metric\+Type, \textbf{ R\+A\+Query\+Stat}$<$Sort\+Policy$>$, Mat\+Type$>$ \textbf{ Tree}}



Convenience typedef. 



Definition at line 75 of file ra\+\_\+search.\+hpp.



\subsection{Constructor \& Destructor Documentation}
\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_a2e2e09ad4d126aa5c72648e5e36198ae}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!R\+A\+Search@{R\+A\+Search}}
\index{R\+A\+Search@{R\+A\+Search}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{R\+A\+Search()\hspace{0.1cm}{\footnotesize\ttfamily [1/3]}}
{\footnotesize\ttfamily \textbf{ R\+A\+Search} (\begin{DoxyParamCaption}\item[{Mat\+Type}]{reference\+Set,  }\item[{const bool}]{naive = {\ttfamily false},  }\item[{const bool}]{single\+Mode = {\ttfamily false},  }\item[{const double}]{tau = {\ttfamily 5},  }\item[{const double}]{alpha = {\ttfamily 0.95},  }\item[{const bool}]{sample\+At\+Leaves = {\ttfamily false},  }\item[{const bool}]{first\+Leaf\+Exact = {\ttfamily false},  }\item[{const size\+\_\+t}]{single\+Sample\+Limit = {\ttfamily 20},  }\item[{const Metric\+Type}]{metric = {\ttfamily MetricType()} }\end{DoxyParamCaption})}



Initialize the \doxyref{R\+A\+Search}{p.}{classmlpack_1_1neighbor_1_1RASearch} object, passing both a reference dataset (this is the dataset that will be searched). 

Optionally, perform the computation in naive mode or single-\/tree mode. An initialized distance metric can be given, for cases where the metric has internal data (i.\+e. the distance\+::\+Mahalanobis\+Distance class).

This method will copy the matrices to internal copies, which are rearranged during tree-\/building. If you don\textquotesingle{}t need to keep the reference dataset, you can use std\+::move() to remove the overhead of making copies. Using std\+::move() transfers the ownership of the dataset.

tau, the rank-\/approximation parameter, specifies that we are looking for k neighbors with probability alpha of being in the top tau percent of nearest neighbors. So, as an example, if our dataset has 1000 points, and we want 5 nearest neighbors with 95\% probability of being in the top 5\% of nearest neighbors (or, the top 50 nearest neighbors), we set k = 5, tau = 5, and alpha = 0.\+95.

The method will fail (and throw a std\+::invalid\+\_\+argument exception) if the value of tau is too low\+: tau must be set such that the number of points in the corresponding percentile of the data is greater than k. Thus, if we choose tau = 0.\+1 with a dataset of 1000 points and k = 5, then we are attempting to choose 5 nearest neighbors out of the closest 1 point -- this is invalid.


\begin{DoxyParams}{Parameters}
{\em reference\+Set} & Set of reference points. \\
\hline
{\em naive} & If true, the rank-\/approximate search will be performed by directly sampling the whole set instead of using the stratified sampling on the tree. \\
\hline
{\em single\+Mode} & If true, single-\/tree search will be used (as opposed to dual-\/tree search). This is useful when \doxyref{Search()}{p.}{classmlpack_1_1neighbor_1_1RASearch_a0de302ca0602fe721ac01f073d5e630f} will be called with few query points. \\
\hline
{\em metric} & An optional instance of the Metric\+Type class. \\
\hline
{\em tau} & The rank-\/approximation in percentile of the data. The default value is 5\%. \\
\hline
{\em alpha} & The desired success probability. The default value is 0.\+95. \\
\hline
{\em sample\+At\+Leaves} & Sample at leaves for faster but less accurate computation. This defaults to \textquotesingle{}false\textquotesingle{}. \\
\hline
{\em first\+Leaf\+Exact} & Traverse to the first leaf without approximation. This can ensure that the query definitely finds its (near) duplicate if there exists one. This defaults to \textquotesingle{}false\textquotesingle{} for now. \\
\hline
{\em single\+Sample\+Limit} & The limit on the largest node that can be approximated by sampling. This defaults to 20. \\
\hline
\end{DoxyParams}
\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_a71c2c551b7ed51e42515edd5ab00b255}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!R\+A\+Search@{R\+A\+Search}}
\index{R\+A\+Search@{R\+A\+Search}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{R\+A\+Search()\hspace{0.1cm}{\footnotesize\ttfamily [2/3]}}
{\footnotesize\ttfamily \textbf{ R\+A\+Search} (\begin{DoxyParamCaption}\item[{\textbf{ Tree} $\ast$}]{reference\+Tree,  }\item[{const bool}]{single\+Mode = {\ttfamily false},  }\item[{const double}]{tau = {\ttfamily 5},  }\item[{const double}]{alpha = {\ttfamily 0.95},  }\item[{const bool}]{sample\+At\+Leaves = {\ttfamily false},  }\item[{const bool}]{first\+Leaf\+Exact = {\ttfamily false},  }\item[{const size\+\_\+t}]{single\+Sample\+Limit = {\ttfamily 20},  }\item[{const Metric\+Type}]{metric = {\ttfamily MetricType()} }\end{DoxyParamCaption})}



Initialize the \doxyref{R\+A\+Search}{p.}{classmlpack_1_1neighbor_1_1RASearch} object with the given pre-\/constructed reference tree. 

It is assumed that the points in the tree\textquotesingle{}s dataset correspond to the reference set. Optionally, choose to use single-\/tree mode. Naive mode is not available as an option for this constructor; instead, to run naive computation, use a different constructor. Additionally, an instantiated distance metric can be given, for cases where the distance metric holds data.

There is no copying of the data matrices in this constructor (because tree-\/building is not necessary), so this is the constructor to use when copies absolutely must be avoided.

tau, the rank-\/approximation parameter, specifies that we are looking for k neighbors with probability alpha of being in the top tau percent of nearest neighbors. So, as an example, if our dataset has 1000 points, and we want 5 nearest neighbors with 95\% probability of being in the top 5\% of nearest neighbors (or, the top 50 nearest neighbors), we set k = 5, tau = 5, and alpha = 0.\+95.

The method will fail (and throw a std\+::invalid\+\_\+argument exception) if the value of tau is too low\+: tau must be set such that the number of points in the corresponding percentile of the data is greater than k. Thus, if we choose tau = 0.\+1 with a dataset of 1000 points and k = 5, then we are attempting to choose 5 nearest neighbors out of the closest 1 point -- this is invalid.

\begin{DoxyNote}{Note}
Tree-\/building may (at least with Binary\+Space\+Tree) modify the ordering of a matrix, so be aware that the results you get from \doxyref{Search()}{p.}{classmlpack_1_1neighbor_1_1RASearch_a0de302ca0602fe721ac01f073d5e630f} will correspond to the modified matrix. 
\end{DoxyNote}

\begin{DoxyParams}{Parameters}
{\em reference\+Tree} & Pre-\/built tree for reference points. \\
\hline
{\em single\+Mode} & Whether single-\/tree computation should be used (as opposed to dual-\/tree computation). \\
\hline
{\em tau} & The rank-\/approximation in percentile of the data. The default value is 5\%. \\
\hline
{\em alpha} & The desired success probability. The default value is 0.\+95. \\
\hline
{\em sample\+At\+Leaves} & Sample at leaves for faster but less accurate computation. This defaults to \textquotesingle{}false\textquotesingle{}. \\
\hline
{\em first\+Leaf\+Exact} & Traverse to the first leaf without approximation. This can ensure that the query definitely finds its (near) duplicate if there exists one. This defaults to \textquotesingle{}false\textquotesingle{} for now. \\
\hline
{\em single\+Sample\+Limit} & The limit on the largest node that can be approximated by sampling. This defaults to 20. \\
\hline
{\em metric} & Instantiated distance metric. \\
\hline
\end{DoxyParams}
\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_a796e8bc5d64b5f5d479be42faa9156d1}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!R\+A\+Search@{R\+A\+Search}}
\index{R\+A\+Search@{R\+A\+Search}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{R\+A\+Search()\hspace{0.1cm}{\footnotesize\ttfamily [3/3]}}
{\footnotesize\ttfamily \textbf{ R\+A\+Search} (\begin{DoxyParamCaption}\item[{const bool}]{naive = {\ttfamily false},  }\item[{const bool}]{single\+Mode = {\ttfamily false},  }\item[{const double}]{tau = {\ttfamily 5},  }\item[{const double}]{alpha = {\ttfamily 0.95},  }\item[{const bool}]{sample\+At\+Leaves = {\ttfamily false},  }\item[{const bool}]{first\+Leaf\+Exact = {\ttfamily false},  }\item[{const size\+\_\+t}]{single\+Sample\+Limit = {\ttfamily 20},  }\item[{const Metric\+Type}]{metric = {\ttfamily MetricType()} }\end{DoxyParamCaption})}



Create an \doxyref{R\+A\+Search}{p.}{classmlpack_1_1neighbor_1_1RASearch} object with no reference data. 

If \doxyref{Search()}{p.}{classmlpack_1_1neighbor_1_1RASearch_a0de302ca0602fe721ac01f073d5e630f} is called before a reference set is set with \doxyref{Train()}{p.}{classmlpack_1_1neighbor_1_1RASearch_a27ba39af83e3cb01f2e6fbec159adf0e}, an exception will be thrown.


\begin{DoxyParams}{Parameters}
{\em naive} & Whether naive (brute-\/force) search should be used. \\
\hline
{\em single\+Mode} & Whether single-\/tree computation should be used (as opposed to dual-\/tree computation). \\
\hline
{\em tau} & The rank-\/approximation in percentile of the data. The default value is 5\%. \\
\hline
{\em alpha} & The desired success probability. The default value is 0.\+95. \\
\hline
{\em sample\+At\+Leaves} & Sample at leaves for faster but less accurate computation. This defaults to \textquotesingle{}false\textquotesingle{}. \\
\hline
{\em first\+Leaf\+Exact} & Traverse to the first leaf without approximation. This can ensure that the query definitely finds its (near) duplicate if there exists one. This defaults to \textquotesingle{}false\textquotesingle{} for now. \\
\hline
{\em single\+Sample\+Limit} & The limit on the largest node that can be approximated by sampling. This defaults to 20. \\
\hline
{\em metric} & Instantiated distance metric. \\
\hline
\end{DoxyParams}
\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_a68b835e379f6b9375bbe6874357eb978}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!````~R\+A\+Search@{$\sim$\+R\+A\+Search}}
\index{````~R\+A\+Search@{$\sim$\+R\+A\+Search}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{$\sim$\+R\+A\+Search()}
{\footnotesize\ttfamily $\sim$\textbf{ R\+A\+Search} (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Delete the \doxyref{R\+A\+Search}{p.}{classmlpack_1_1neighbor_1_1RASearch} object. 

The tree is the only member we are responsible for deleting. The others will take care of themselves. 

\subsection{Member Function Documentation}
\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_a500ecd077d5cc5fdbf6ceb095d8de9e1}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Alpha@{Alpha}}
\index{Alpha@{Alpha}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Alpha()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily double Alpha (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Get the desired success probability. 



Definition at line 338 of file ra\+\_\+search.\+hpp.

\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_acbb0e4747a3a307bee88bad71e5eeaf1}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Alpha@{Alpha}}
\index{Alpha@{Alpha}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Alpha()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily double\& Alpha (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Modify the desired success probability. 



Definition at line 340 of file ra\+\_\+search.\+hpp.

\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_a17ec6e467897eb8aee3b519e0758e77d}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!First\+Leaf\+Exact@{First\+Leaf\+Exact}}
\index{First\+Leaf\+Exact@{First\+Leaf\+Exact}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{First\+Leaf\+Exact()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily bool First\+Leaf\+Exact (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Get whether or not we traverse to the first leaf without approximation. 



Definition at line 348 of file ra\+\_\+search.\+hpp.

\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_aca2eb648feb965d3bcb0b0b73f8b2b0f}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!First\+Leaf\+Exact@{First\+Leaf\+Exact}}
\index{First\+Leaf\+Exact@{First\+Leaf\+Exact}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{First\+Leaf\+Exact()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily bool\& First\+Leaf\+Exact (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Modify whether or not we traverse to the first leaf without approximation. 



Definition at line 350 of file ra\+\_\+search.\+hpp.

\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_a343230e7d7344e3f7d5f5f2eb89cf2c5}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Naive@{Naive}}
\index{Naive@{Naive}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Naive()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily bool Naive (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Get whether or not naive (brute-\/force) search is used. 



Definition at line 323 of file ra\+\_\+search.\+hpp.

\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_af7d397adca3f411b4e2d2f977b280ce6}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Naive@{Naive}}
\index{Naive@{Naive}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Naive()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily bool\& Naive (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Modify whether or not naive (brute-\/force) search is used. 



Definition at line 325 of file ra\+\_\+search.\+hpp.

\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_a0a975940b302b4efec85bbe2d8b36251}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Reference\+Set@{Reference\+Set}}
\index{Reference\+Set@{Reference\+Set}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Reference\+Set()}
{\footnotesize\ttfamily const Mat\+Type\& Reference\+Set (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Access the reference set. 



Definition at line 320 of file ra\+\_\+search.\+hpp.

\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_a769fa33810494d3cc0abdd8578daba67}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Reset\+Query\+Tree@{Reset\+Query\+Tree}}
\index{Reset\+Query\+Tree@{Reset\+Query\+Tree}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Reset\+Query\+Tree()}
{\footnotesize\ttfamily void Reset\+Query\+Tree (\begin{DoxyParamCaption}\item[{\textbf{ Tree} $\ast$}]{query\+Tree }\end{DoxyParamCaption}) const}



This function recursively resets the \doxyref{R\+A\+Query\+Stat}{p.}{classmlpack_1_1neighbor_1_1RAQueryStat} of the given query tree to set \textquotesingle{}bound\textquotesingle{} to Sort\+Policy\+::\+Worst\+Distance and \textquotesingle{}num\+Samples\+Made\textquotesingle{} to 0. 

This allows a user to perform multiple searches with the same query tree, possibly with different levels of approximation without requiring to build a new pair of trees for every new (approximate) search.

If \doxyref{Search()}{p.}{classmlpack_1_1neighbor_1_1RASearch_a0de302ca0602fe721ac01f073d5e630f} is called multiple times with the same query tree without calling \doxyref{Reset\+Query\+Tree()}{p.}{classmlpack_1_1neighbor_1_1RASearch_a769fa33810494d3cc0abdd8578daba67}, the results may not satisfy the theoretical guarantees provided by the rank-\/approximate neighbor search algorithm.


\begin{DoxyParams}{Parameters}
{\em query\+Tree} & Tree whose statistics should be reset. \\
\hline
\end{DoxyParams}
\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_aa9dd91d6b96e1d0b343c3cec27372036}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Sample\+At\+Leaves@{Sample\+At\+Leaves}}
\index{Sample\+At\+Leaves@{Sample\+At\+Leaves}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Sample\+At\+Leaves()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily bool Sample\+At\+Leaves (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Get whether or not sampling is done at the leaves. 



Definition at line 343 of file ra\+\_\+search.\+hpp.

\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_a9f6d54dd0424f827becc2e2e9969b1bb}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Sample\+At\+Leaves@{Sample\+At\+Leaves}}
\index{Sample\+At\+Leaves@{Sample\+At\+Leaves}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Sample\+At\+Leaves()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily bool\& Sample\+At\+Leaves (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Modify whether or not sampling is done at the leaves. 



Definition at line 345 of file ra\+\_\+search.\+hpp.

\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_a0de302ca0602fe721ac01f073d5e630f}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Search@{Search}}
\index{Search@{Search}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Search()\hspace{0.1cm}{\footnotesize\ttfamily [1/3]}}
{\footnotesize\ttfamily void Search (\begin{DoxyParamCaption}\item[{const Mat\+Type \&}]{query\+Set,  }\item[{const size\+\_\+t}]{k,  }\item[{arma\+::\+Mat$<$ size\+\_\+t $>$ \&}]{neighbors,  }\item[{arma\+::mat \&}]{distances }\end{DoxyParamCaption})}



Compute the rank approximate nearest neighbors of each query point in the query set and store the output in the given matrices. 

The matrices will be set to the size of n columns by k rows, where n is the number of points in the query dataset and k is the number of neighbors being searched for.

If query\+Set is small or only contains one point, it can be faster to do single-\/tree search; single-\/tree search can be set with the \doxyref{Single\+Mode()}{p.}{classmlpack_1_1neighbor_1_1RASearch_adadacd63ddeadf138d834b1fdc632773} function or in the constructor.


\begin{DoxyParams}{Parameters}
{\em query\+Set} & Set of query points (can be a single point). \\
\hline
{\em k} & Number of neighbors to search for. \\
\hline
{\em neighbors} & Matrix storing lists of neighbors for each query point. \\
\hline
{\em distances} & Matrix storing distances of neighbors for each query point. \\
\hline
\end{DoxyParams}
\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_a9a8b402b4af23e9ebe2143139b3a6b00}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Search@{Search}}
\index{Search@{Search}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Search()\hspace{0.1cm}{\footnotesize\ttfamily [2/3]}}
{\footnotesize\ttfamily void Search (\begin{DoxyParamCaption}\item[{\textbf{ Tree} $\ast$}]{query\+Tree,  }\item[{const size\+\_\+t}]{k,  }\item[{arma\+::\+Mat$<$ size\+\_\+t $>$ \&}]{neighbors,  }\item[{arma\+::mat \&}]{distances }\end{DoxyParamCaption})}



Compute the rank approximate nearest neighbors of each point in the pre-\/built query tree and store the output in the given matrices. 

The matrices will be set to the size of n columns by k rows, where n is the number of points in the query dataset and k is the number of neighbors being searched for.

If single\+Mode or naive is enabled, then this method will throw a std\+::invalid\+\_\+argument exception; calling this function implies a dual-\/tree algorithm.

\begin{DoxyNote}{Note}
If the tree type you are using modifies the data matrix, be aware that the results returned from this function will be with respect to the modified data matrix. 
\end{DoxyNote}

\begin{DoxyParams}{Parameters}
{\em query\+Tree} & Tree built on query points. \\
\hline
{\em k} & Number of neighbors to search for. \\
\hline
{\em neighbors} & Matrix storing lists of neighbors for each query point. \\
\hline
{\em distances} & Matrix storing distances of neighbors for each query point. \\
\hline
\end{DoxyParams}
\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_a619c7d4931e628a0c199159c57b34cbd}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Search@{Search}}
\index{Search@{Search}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Search()\hspace{0.1cm}{\footnotesize\ttfamily [3/3]}}
{\footnotesize\ttfamily void Search (\begin{DoxyParamCaption}\item[{const size\+\_\+t}]{k,  }\item[{arma\+::\+Mat$<$ size\+\_\+t $>$ \&}]{neighbors,  }\item[{arma\+::mat \&}]{distances }\end{DoxyParamCaption})}



Compute the rank approximate nearest neighbors of each point in the reference set (that is, the query set is taken to be the reference set), and store the output in the given matrices. 

The matrices will be set to the size of n columns by k rows, where n is the number of points in the query dataset and k is the number of neighbors being searched for.


\begin{DoxyParams}{Parameters}
{\em k} & Number of neighbors to search for. \\
\hline
{\em neighbors} & Matrix storing lists of neighbors for each point. \\
\hline
{\em distances} & Matrix storing distances of neighbors for each query point. \\
\hline
\end{DoxyParams}
\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_af0dd9205158ccf7bcfcd8ff81f79c927}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!serialize@{serialize}}
\index{serialize@{serialize}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{serialize()}
{\footnotesize\ttfamily void serialize (\begin{DoxyParamCaption}\item[{Archive \&}]{ar,  }\item[{const unsigned}]{int }\end{DoxyParamCaption})}



Serialize the object. 



Referenced by R\+A\+Search$<$ Sort\+Policy, Metric\+Type, Mat\+Type, Tree\+Type $>$\+::\+Single\+Sample\+Limit().

\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_a7477b3e8499a6158bbe177e7f30d4947}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Single\+Mode@{Single\+Mode}}
\index{Single\+Mode@{Single\+Mode}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Single\+Mode()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily bool Single\+Mode (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Get whether or not single-\/tree search is used. 



Definition at line 328 of file ra\+\_\+search.\+hpp.

\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_adadacd63ddeadf138d834b1fdc632773}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Single\+Mode@{Single\+Mode}}
\index{Single\+Mode@{Single\+Mode}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Single\+Mode()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily bool\& Single\+Mode (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Modify whether or not single-\/tree search is used. 



Definition at line 330 of file ra\+\_\+search.\+hpp.

\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_a3a2580f686a9de3078e499b1280e2a9f}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Single\+Sample\+Limit@{Single\+Sample\+Limit}}
\index{Single\+Sample\+Limit@{Single\+Sample\+Limit}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Single\+Sample\+Limit()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily size\+\_\+t Single\+Sample\+Limit (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Get the limit on the size of a node that can be approximated. 



Definition at line 353 of file ra\+\_\+search.\+hpp.

\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_ae78a7b8e9c96a2dbf646a27efee047b1}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Single\+Sample\+Limit@{Single\+Sample\+Limit}}
\index{Single\+Sample\+Limit@{Single\+Sample\+Limit}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Single\+Sample\+Limit()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily size\+\_\+t\& Single\+Sample\+Limit (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Modify the limit on the size of a node that can be approximation. 



Definition at line 355 of file ra\+\_\+search.\+hpp.



References R\+A\+Search$<$ Sort\+Policy, Metric\+Type, Mat\+Type, Tree\+Type $>$\+::serialize().

\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_a4a4b0fafde4cc4c856a53025dc8c4c21}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Tau@{Tau}}
\index{Tau@{Tau}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Tau()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily double Tau (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Get the rank-\/approximation in percentile of the data. 



Definition at line 333 of file ra\+\_\+search.\+hpp.

\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_ad522d61ed716a322376adea25ebdbc90}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Tau@{Tau}}
\index{Tau@{Tau}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Tau()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily double\& Tau (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Modify the rank-\/approximation in percentile of the data. 



Definition at line 335 of file ra\+\_\+search.\+hpp.

\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_a27ba39af83e3cb01f2e6fbec159adf0e}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Train@{Train}}
\index{Train@{Train}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Train()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily void Train (\begin{DoxyParamCaption}\item[{Mat\+Type}]{reference\+Set }\end{DoxyParamCaption})}



\char`\"{}\+Train\char`\"{} the model on the given reference set. 

If tree-\/based search is being used (if \doxyref{Naive()}{p.}{classmlpack_1_1neighbor_1_1RASearch_af7d397adca3f411b4e2d2f977b280ce6} is false), the reference tree is rebuilt. Thus, a copy of the reference dataset is made. If you don\textquotesingle{}t need to keep the dataset, you can avoid copying by using std\+::move(). This transfers the ownership of the dataset.


\begin{DoxyParams}{Parameters}
{\em reference\+Set} & New reference set to use. \\
\hline
\end{DoxyParams}
\mbox{\label{classmlpack_1_1neighbor_1_1RASearch_a3d1133fe6bda66e7143fd7aab27cbd04}} 
\index{mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}!Train@{Train}}
\index{Train@{Train}!mlpack\+::neighbor\+::\+R\+A\+Search@{mlpack\+::neighbor\+::\+R\+A\+Search}}
\subsubsection{Train()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily void Train (\begin{DoxyParamCaption}\item[{\textbf{ Tree} $\ast$}]{reference\+Tree }\end{DoxyParamCaption})}



Set the reference tree to a new reference tree. 



The documentation for this class was generated from the following file\+:\begin{DoxyCompactItemize}
\item 
/var/www/mlpack.\+ratml.\+org/mlpack.\+org/\+\_\+src/mlpack-\/3.\+3.\+1/src/mlpack/methods/rann/\textbf{ ra\+\_\+search.\+hpp}\end{DoxyCompactItemize}
