mlpack: mlpack::nca::NCA< MetricType, OptimizerType > Class Template Reference
mlpack  2.2.0
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...

Public Member Functions

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

Private Attributes

const arma::mat & dataset
 Dataset reference. More...
 
SoftmaxErrorFunction< MetricType > errorFunction
 The function to optimize. More...
 
const arma::Row< size_t > & labels
 Labels reference. More...
 
MetricType metric
 Metric to be used. More...
 
OptimizerType< SoftmaxErrorFunction< MetricType > > optimizer
 The optimizer to use. More...
 

Detailed Description

template<typename MetricType = metric::SquaredEuclideanDistance, template< typename > class OptimizerType = optimization::SGD>
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}
}

Definition at line 49 of file nca.hpp.

Constructor & Destructor Documentation

◆ NCA()

template<typename MetricType = metric::SquaredEuclideanDistance, template< typename > class OptimizerType = optimization::SGD>
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.
stepSizeStep size for stochastic gradient descent.
maxIterationsMaximum iterations for stochastic gradient descent.
toleranceTolerance for termination of stochastic gradient descent.
shuffleWhether or not to shuffle the dataset during SGD.
metricInstantiated metric to use.

Member Function Documentation

◆ Dataset()

template<typename MetricType = metric::SquaredEuclideanDistance, template< typename > class OptimizerType = optimization::SGD>
const arma::mat& mlpack::nca::NCA< MetricType, OptimizerType >::Dataset ( ) const
inline

Get the dataset reference.

Definition at line 81 of file nca.hpp.

References mlpack::nca::NCA< MetricType, OptimizerType >::dataset.

◆ Labels()

template<typename MetricType = metric::SquaredEuclideanDistance, template< typename > class OptimizerType = optimization::SGD>
const arma::Row<size_t>& mlpack::nca::NCA< MetricType, OptimizerType >::Labels ( ) const
inline

Get the labels reference.

Definition at line 83 of file nca.hpp.

References mlpack::nca::NCA< MetricType, OptimizerType >::labels.

◆ LearnDistance()

template<typename MetricType = metric::SquaredEuclideanDistance, template< typename > class OptimizerType = optimization::SGD>
void mlpack::nca::NCA< MetricType, OptimizerType >::LearnDistance ( arma::mat &  outputMatrix)

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.

Parameters
output_matrixCovariance matrix of Mahalanobis distance.

◆ Optimizer() [1/2]

template<typename MetricType = metric::SquaredEuclideanDistance, template< typename > class OptimizerType = optimization::SGD>
const OptimizerType<SoftmaxErrorFunction<MetricType> >& mlpack::nca::NCA< MetricType, OptimizerType >::Optimizer ( ) const
inline

Get the optimizer.

Definition at line 86 of file nca.hpp.

References mlpack::nca::NCA< MetricType, OptimizerType >::optimizer.

◆ Optimizer() [2/2]

template<typename MetricType = metric::SquaredEuclideanDistance, template< typename > class OptimizerType = optimization::SGD>
OptimizerType<SoftmaxErrorFunction<MetricType> >& mlpack::nca::NCA< MetricType, OptimizerType >::Optimizer ( )
inline

Definition at line 88 of file nca.hpp.

References mlpack::nca::NCA< MetricType, OptimizerType >::optimizer.

Member Data Documentation

◆ dataset

template<typename MetricType = metric::SquaredEuclideanDistance, template< typename > class OptimizerType = optimization::SGD>
const arma::mat& mlpack::nca::NCA< MetricType, OptimizerType >::dataset
private

Dataset reference.

Definition at line 93 of file nca.hpp.

Referenced by mlpack::nca::NCA< MetricType, OptimizerType >::Dataset().

◆ errorFunction

template<typename MetricType = metric::SquaredEuclideanDistance, template< typename > class OptimizerType = optimization::SGD>
SoftmaxErrorFunction<MetricType> mlpack::nca::NCA< MetricType, OptimizerType >::errorFunction
private

The function to optimize.

Definition at line 101 of file nca.hpp.

◆ labels

template<typename MetricType = metric::SquaredEuclideanDistance, template< typename > class OptimizerType = optimization::SGD>
const arma::Row<size_t>& mlpack::nca::NCA< MetricType, OptimizerType >::labels
private

Labels reference.

Definition at line 95 of file nca.hpp.

Referenced by mlpack::nca::NCA< MetricType, OptimizerType >::Labels().

◆ metric

template<typename MetricType = metric::SquaredEuclideanDistance, template< typename > class OptimizerType = optimization::SGD>
MetricType mlpack::nca::NCA< MetricType, OptimizerType >::metric
private

Metric to be used.

Definition at line 98 of file nca.hpp.

◆ optimizer

template<typename MetricType = metric::SquaredEuclideanDistance, template< typename > class OptimizerType = optimization::SGD>
OptimizerType<SoftmaxErrorFunction<MetricType> > mlpack::nca::NCA< MetricType, OptimizerType >::optimizer
private

The optimizer to use.

Definition at line 104 of file nca.hpp.

Referenced by mlpack::nca::NCA< MetricType, OptimizerType >::Optimizer().


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