\section{L\+M\+NN$<$ Metric\+Type, Optimizer\+Type $>$ Class Template Reference}
\label{classmlpack_1_1lmnn_1_1LMNN}\index{L\+M\+N\+N$<$ Metric\+Type, Optimizer\+Type $>$@{L\+M\+N\+N$<$ Metric\+Type, Optimizer\+Type $>$}}


An implementation of Large Margin nearest neighbor metric learning technique.  


\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\textbf{ L\+M\+NN} (const arma\+::mat \&dataset, const arma\+::\+Row$<$ size\+\_\+t $>$ \&labels, const size\+\_\+t k, const Metric\+Type metric=Metric\+Type())
\begin{DoxyCompactList}\small\item\em Initialize the \doxyref{L\+M\+NN}{p.}{classmlpack_1_1lmnn_1_1LMNN} object, passing a dataset (distance metric is learned using this dataset) and labels. \end{DoxyCompactList}\item 
const arma\+::mat \& \textbf{ Dataset} () const
\begin{DoxyCompactList}\small\item\em Get the dataset reference. \end{DoxyCompactList}\item 
const size\+\_\+t \& \textbf{ K} () const
\begin{DoxyCompactList}\small\item\em Access the value of k. \end{DoxyCompactList}\item 
size\+\_\+t \textbf{ K} ()
\begin{DoxyCompactList}\small\item\em Modify the value of k. \end{DoxyCompactList}\item 
const arma\+::\+Row$<$ size\+\_\+t $>$ \& \textbf{ Labels} () const
\begin{DoxyCompactList}\small\item\em Get the labels reference. \end{DoxyCompactList}\item 
{\footnotesize template$<$typename... Callback\+Types$>$ }\\void \textbf{ Learn\+Distance} (arma\+::mat \&output\+Matrix, Callback\+Types \&\&... callbacks)
\begin{DoxyCompactList}\small\item\em Perform Large Margin Nearest Neighbors metric learning. \end{DoxyCompactList}\item 
const Optimizer\+Type \& \textbf{ Optimizer} () const
\begin{DoxyCompactList}\small\item\em Get the optimizer. \end{DoxyCompactList}\item 
Optimizer\+Type \& \textbf{ Optimizer} ()
\item 
const size\+\_\+t \& \textbf{ Range} () const
\begin{DoxyCompactList}\small\item\em Access the range value. \end{DoxyCompactList}\item 
size\+\_\+t \& \textbf{ Range} ()
\begin{DoxyCompactList}\small\item\em Modify the range value. \end{DoxyCompactList}\item 
const double \& \textbf{ Regularization} () const
\begin{DoxyCompactList}\small\item\em Access the regularization value. \end{DoxyCompactList}\item 
double \& \textbf{ Regularization} ()
\begin{DoxyCompactList}\small\item\em Modify the regularization value. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
\subsubsection*{template$<$typename Metric\+Type = metric\+::\+Squared\+Euclidean\+Distance, typename Optimizer\+Type = ens\+::\+A\+M\+S\+Grad$>$\newline
class mlpack\+::lmnn\+::\+L\+M\+N\+N$<$ Metric\+Type, Optimizer\+Type $>$}

An implementation of Large Margin nearest neighbor metric learning technique. 

The method seeks to improve clustering \& classification algorithms on a dataset by transforming the dataset representation in a more convenient form for them. It introduces the concept of target neighbors and impostors, focusing on the idea that the distance between impostors and the perimeters established by target neighbors should be large and that between target neighbors and data point should be small. It requires the knowledge of target neighbors beforehand. Moreover, target neighbors once initialized remain same.

For more details, see the following published paper\+:


\begin{DoxyCode}
@ARTICLE\{weinberger09distance,
  author = \{Weinberger, K.Q. and Saul, L.K.\},
  title = \{\{Distance metric learning \textcolor{keywordflow}{for} large margin nearest neighbor
      classification\}\},
  journal = \{The Journal of Machine Learning Research\},
  year = \{2009\},
  volume = \{10\},
  pages = \{207--244\},
  publisher = \{MIT Press\}
\}
\end{DoxyCode}



\begin{DoxyTemplParams}{Template Parameters}
{\em Metric\+Type} & The type of metric to use for computation. \\
\hline
{\em Optimizer\+Type} & Optimizer to use for developing distance. \\
\hline
\end{DoxyTemplParams}


Definition at line 55 of file lmnn.\+hpp.



\subsection{Constructor \& Destructor Documentation}
\mbox{\label{classmlpack_1_1lmnn_1_1LMNN_a212df5d9b57184556420c87ef7335926}} 
\index{mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}!L\+M\+NN@{L\+M\+NN}}
\index{L\+M\+NN@{L\+M\+NN}!mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}}
\subsubsection{L\+M\+N\+N()}
{\footnotesize\ttfamily \textbf{ L\+M\+NN} (\begin{DoxyParamCaption}\item[{const arma\+::mat \&}]{dataset,  }\item[{const arma\+::\+Row$<$ size\+\_\+t $>$ \&}]{labels,  }\item[{const size\+\_\+t}]{k,  }\item[{const Metric\+Type}]{metric = {\ttfamily MetricType()} }\end{DoxyParamCaption})}



Initialize the \doxyref{L\+M\+NN}{p.}{classmlpack_1_1lmnn_1_1LMNN} object, passing a dataset (distance metric is learned using this dataset) and labels. 

Initialization will copy both dataset and labels matrices to internal copies.


\begin{DoxyParams}{Parameters}
{\em dataset} & Input dataset. \\
\hline
{\em labels} & Input dataset labels. \\
\hline
{\em k} & Number of targets to consider. \\
\hline
{\em metric} & Type of metric used for computation. \\
\hline
\end{DoxyParams}


\subsection{Member Function Documentation}
\mbox{\label{classmlpack_1_1lmnn_1_1LMNN_aff320b9a86b77a150e630c01d5888273}} 
\index{mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}!Dataset@{Dataset}}
\index{Dataset@{Dataset}!mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}}
\subsubsection{Dataset()}
{\footnotesize\ttfamily const arma\+::mat\& Dataset (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Get the dataset reference. 



Definition at line 90 of file lmnn.\+hpp.

\mbox{\label{classmlpack_1_1lmnn_1_1LMNN_ab749ea30c4c3d750ef3a619f32dc3e75}} 
\index{mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}!K@{K}}
\index{K@{K}!mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}}
\subsubsection{K()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily const size\+\_\+t\& K (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Access the value of k. 



Definition at line 106 of file lmnn.\+hpp.

\mbox{\label{classmlpack_1_1lmnn_1_1LMNN_aeae9eca1b61b389943775d6eeb8325b7}} 
\index{mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}!K@{K}}
\index{K@{K}!mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}}
\subsubsection{K()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily size\+\_\+t K (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Modify the value of k. 



Definition at line 108 of file lmnn.\+hpp.

\mbox{\label{classmlpack_1_1lmnn_1_1LMNN_ae68718a757e9635f87377fd3935ca20d}} 
\index{mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}!Labels@{Labels}}
\index{Labels@{Labels}!mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}}
\subsubsection{Labels()}
{\footnotesize\ttfamily const arma\+::\+Row$<$size\+\_\+t$>$\& Labels (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Get the labels reference. 



Definition at line 93 of file lmnn.\+hpp.

\mbox{\label{classmlpack_1_1lmnn_1_1LMNN_a55126379a6e9673a59546f4e446e9ada}} 
\index{mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}!Learn\+Distance@{Learn\+Distance}}
\index{Learn\+Distance@{Learn\+Distance}!mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}}
\subsubsection{Learn\+Distance()}
{\footnotesize\ttfamily void Learn\+Distance (\begin{DoxyParamCaption}\item[{arma\+::mat \&}]{output\+Matrix,  }\item[{Callback\+Types \&\&...}]{callbacks }\end{DoxyParamCaption})}



Perform Large Margin Nearest Neighbors metric learning. 

The output distance matrix is written into the passed reference. If the \doxyref{Learn\+Distance()}{p.}{classmlpack_1_1lmnn_1_1LMNN_a55126379a6e9673a59546f4e446e9ada} is called with an output\+Matrix with correct dimensions, then that matrix will be used as the starting point for optimization.


\begin{DoxyTemplParams}{Template Parameters}
{\em Callback\+Types} & Types of Callback functions. \\
\hline
\end{DoxyTemplParams}

\begin{DoxyParams}{Parameters}
{\em output\+Matrix} & Covariance matrix of Mahalanobis distance. \\
\hline
{\em callbacks} & Callback function for ensmallen optimizer {\ttfamily Optimizer\+Type}. See {\tt https\+://www.\+ensmallen.\+org/docs.\+html\#callback-\/documentation}. \\
\hline
\end{DoxyParams}
\mbox{\label{classmlpack_1_1lmnn_1_1LMNN_a3bdf808beacdb2f464caa78076a23a0a}} 
\index{mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}!Optimizer@{Optimizer}}
\index{Optimizer@{Optimizer}!mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}}
\subsubsection{Optimizer()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily const Optimizer\+Type\& Optimizer (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Get the optimizer. 



Definition at line 111 of file lmnn.\+hpp.

\mbox{\label{classmlpack_1_1lmnn_1_1LMNN_a213f61b8936eadf8a162e45b4c6188d0}} 
\index{mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}!Optimizer@{Optimizer}}
\index{Optimizer@{Optimizer}!mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}}
\subsubsection{Optimizer()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily Optimizer\+Type\& Optimizer (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Definition at line 112 of file lmnn.\+hpp.

\mbox{\label{classmlpack_1_1lmnn_1_1LMNN_a8a26c8724520d749b483fe8dcfe7416b}} 
\index{mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}!Range@{Range}}
\index{Range@{Range}!mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}}
\subsubsection{Range()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily const size\+\_\+t\& Range (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Access the range value. 



Definition at line 101 of file lmnn.\+hpp.

\mbox{\label{classmlpack_1_1lmnn_1_1LMNN_ab2cebd1b43cb779465e7323255112bb4}} 
\index{mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}!Range@{Range}}
\index{Range@{Range}!mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}}
\subsubsection{Range()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily size\+\_\+t\& Range (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Modify the range value. 



Definition at line 103 of file lmnn.\+hpp.

\mbox{\label{classmlpack_1_1lmnn_1_1LMNN_ad3a3c8f810d08e2e922b3c30e29b7f11}} 
\index{mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}!Regularization@{Regularization}}
\index{Regularization@{Regularization}!mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}}
\subsubsection{Regularization()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily const double\& Regularization (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Access the regularization value. 



Definition at line 96 of file lmnn.\+hpp.

\mbox{\label{classmlpack_1_1lmnn_1_1LMNN_a9c741ac26a2c0ee8bb0fbe52534dd544}} 
\index{mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}!Regularization@{Regularization}}
\index{Regularization@{Regularization}!mlpack\+::lmnn\+::\+L\+M\+NN@{mlpack\+::lmnn\+::\+L\+M\+NN}}
\subsubsection{Regularization()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily double\& Regularization (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Modify the regularization value. 



Definition at line 98 of file lmnn.\+hpp.



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.\+0/src/mlpack/methods/lmnn/\textbf{ lmnn.\+hpp}\end{DoxyCompactItemize}
