LMNN< MetricType, OptimizerType > Class Template Reference

An implementation of Large Margin nearest neighbor metric learning technique. More...

Public Member Functions

 LMNN (const arma::mat &dataset, const arma::Row< size_t > &labels, const size_t k, const MetricType metric=MetricType())
 Initialize the LMNN object, passing a dataset (distance metric is learned using this dataset) and labels. More...

 
const arma::mat & Dataset () const
 Get the dataset reference. More...

 
const size_t & K () const
 Access the value of k. More...

 
size_t K ()
 Modify the value of k. More...

 
const arma::Row< size_t > & Labels () const
 Get the labels reference. More...

 
template<typename... CallbackTypes>
void LearnDistance (arma::mat &outputMatrix, CallbackTypes &&... callbacks)
 Perform Large Margin Nearest Neighbors metric learning. More...

 
const OptimizerType & Optimizer () const
 Get the optimizer. More...

 
OptimizerType & Optimizer ()
 
const size_t & Range () const
 Access the range value. More...

 
size_t & Range ()
 Modify the range value. More...

 
const double & Regularization () const
 Access the regularization value. More...

 
double & Regularization ()
 Modify the regularization value. More...

 

Detailed Description


template
<
typename
MetricType
=
metric::SquaredEuclideanDistance
,
typename
OptimizerType
=
ens::AMSGrad
>

class mlpack::lmnn::LMNN< MetricType, OptimizerType >

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:

@ARTICLE{weinberger09distance,
author = {Weinberger, K.Q. and Saul, L.K.},
title = {{Distance metric learning for large margin nearest neighbor
classification}},
journal = {The Journal of Machine Learning Research},
year = {2009},
volume = {10},
pages = {207--244},
publisher = {MIT Press}
}
Template Parameters
MetricTypeThe type of metric to use for computation.
OptimizerTypeOptimizer to use for developing distance.

Definition at line 55 of file lmnn.hpp.

Constructor & Destructor Documentation

◆ LMNN()

LMNN ( const arma::mat &  dataset,
const arma::Row< size_t > &  labels,
const size_t  k,
const MetricType  metric = MetricType() 
)

Initialize the LMNN object, passing a dataset (distance metric is learned using this dataset) and labels.

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

Parameters
datasetInput dataset.
labelsInput dataset labels.
kNumber of targets to consider.
metricType of metric used for computation.

Member Function Documentation

◆ Dataset()

const arma::mat& Dataset ( ) const
inline

Get the dataset reference.

Definition at line 90 of file lmnn.hpp.

◆ K() [1/2]

const size_t& K ( ) const
inline

Access the value of k.

Definition at line 106 of file lmnn.hpp.

◆ K() [2/2]

size_t K ( )
inline

Modify the value of k.

Definition at line 108 of file lmnn.hpp.

◆ Labels()

const arma::Row<size_t>& Labels ( ) const
inline

Get the labels reference.

Definition at line 93 of file lmnn.hpp.

◆ LearnDistance()

void LearnDistance ( arma::mat &  outputMatrix,
CallbackTypes &&...  callbacks 
)

Perform Large Margin Nearest Neighbors metric learning.

The output distance matrix is written into the passed reference. If the LearnDistance() is called with an outputMatrix with correct dimensions, then that matrix will be used as the starting point for optimization.

Template Parameters
CallbackTypesTypes of Callback functions.
Parameters
outputMatrixCovariance matrix of Mahalanobis distance.
callbacksCallback function for ensmallen optimizer OptimizerType. See https://www.ensmallen.org/docs.html#callback-documentation.

◆ Optimizer() [1/2]

const OptimizerType& Optimizer ( ) const
inline

Get the optimizer.

Definition at line 111 of file lmnn.hpp.

◆ Optimizer() [2/2]

OptimizerType& Optimizer ( )
inline

Definition at line 112 of file lmnn.hpp.

◆ Range() [1/2]

const size_t& Range ( ) const
inline

Access the range value.

Definition at line 101 of file lmnn.hpp.

◆ Range() [2/2]

size_t& Range ( )
inline

Modify the range value.

Definition at line 103 of file lmnn.hpp.

◆ Regularization() [1/2]

const double& Regularization ( ) const
inline

Access the regularization value.

Definition at line 96 of file lmnn.hpp.

◆ Regularization() [2/2]

double& Regularization ( )
inline

Modify the regularization value.

Definition at line 98 of file lmnn.hpp.


The documentation for this class was generated from the following file:
  • /home/ryan/src/mlpack.org/_src/mlpack-git/src/mlpack/methods/lmnn/lmnn.hpp