mlpack
Public Member Functions | List of all members
mlpack::nca::NCA< MetricType, OptimizerType > Class Template Reference

An implementation of Neighborhood Components Analysis, both a linear dimensionality reduction technique and a distance learning technique. More...

#include <nca.hpp>

Public Member Functions

 NCA (const arma::mat &dataset, const arma::Row< size_t > &labels, MetricType metric=MetricType())
 Construct the Neighborhood Components Analysis object. More...
 
template<typename... CallbackTypes>
void LearnDistance (arma::mat &outputMatrix, CallbackTypes &&... callbacks)
 Perform Neighborhood Components Analysis. More...
 
const arma::mat & Dataset () const
 Get the dataset reference.
 
const arma::Row< size_t > & Labels () const
 Get the labels reference.
 
const OptimizerType & Optimizer () const
 Get the optimizer.
 
OptimizerType & Optimizer ()
 

Detailed Description

template<typename MetricType = metric::SquaredEuclideanDistance, typename OptimizerType = ens::StandardSGD>
class mlpack::nca::NCA< MetricType, OptimizerType >

An implementation of Neighborhood Components Analysis, both a linear dimensionality reduction technique and a distance learning technique.

The method seeks to improve k-nearest-neighbor classification on a dataset by scaling the dimensions. The method is nonparametric, and does not require a value of k. It works by using stochastic ("soft") neighbor assignments and using optimization techniques over the gradient of the accuracy of the neighbor assignments.

For more details, see the following published paper:

@inproceedings{Goldberger2004,
author = {Goldberger, Jacob and Roweis, Sam and Hinton, Geoff and
Salakhutdinov, Ruslan},
booktitle = {Advances in Neural Information Processing Systems 17},
pages = {513--520},
publisher = {MIT Press},
title = {{Neighbourhood Components Analysis}},
year = {2004}
}

Constructor & Destructor Documentation

◆ NCA()

template<typename MetricType , typename OptimizerType >
mlpack::nca::NCA< MetricType, OptimizerType >::NCA ( const arma::mat &  dataset,
const arma::Row< size_t > &  labels,
MetricType  metric = MetricType() 
)

Construct the Neighborhood Components Analysis object.

This simply stores the reference to the dataset and labels as well as the parameters for optimization before the actual optimization is performed.

Parameters
datasetInput dataset.
labelsInput dataset labels.
metricInstantiated metric to use.

Member Function Documentation

◆ LearnDistance()

template<typename MetricType , typename OptimizerType >
template<typename... CallbackTypes>
void mlpack::nca::NCA< MetricType, OptimizerType >::LearnDistance ( arma::mat &  outputMatrix,
CallbackTypes &&...  callbacks 
)

Perform Neighborhood Components Analysis.

The output distance learning matrix is written into the passed reference. If LearnDistance() is called with an outputMatrix which has the correct size (dataset.n_rows x dataset.n_rows), 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.

The documentation for this class was generated from the following files: