mlpack  2.0.1
nca.hpp
Go to the documentation of this file.
1 
14 #ifndef __MLPACK_METHODS_NCA_NCA_HPP
15 #define __MLPACK_METHODS_NCA_NCA_HPP
16 
17 #include <mlpack/core.hpp>
20 
22 
23 namespace mlpack {
24 namespace nca {
25 
49 template<typename MetricType = metric::SquaredEuclideanDistance,
50  template<typename> class OptimizerType = optimization::SGD>
51 class NCA
52 {
53  public:
67  NCA(const arma::mat& dataset,
68  const arma::Row<size_t>& labels,
69  MetricType metric = MetricType());
70 
80  void LearnDistance(arma::mat& outputMatrix);
81 
83  const arma::mat& Dataset() const { return dataset; }
85  const arma::Row<size_t>& Labels() const { return labels; }
86 
88  const OptimizerType<SoftmaxErrorFunction<MetricType> >& Optimizer() const
89  { return optimizer; }
90  OptimizerType<SoftmaxErrorFunction<MetricType> >& Optimizer()
91  { return optimizer; }
92 
93  private:
95  const arma::mat& dataset;
97  const arma::Row<size_t>& labels;
98 
100  MetricType metric;
101 
104 
106  OptimizerType<SoftmaxErrorFunction<MetricType> > optimizer;
107 };
108 
109 } // namespace nca
110 } // namespace mlpack
111 
112 // Include the implementation.
113 #include "nca_impl.hpp"
114 
115 #endif
SoftmaxErrorFunction< MetricType > errorFunction
The function to optimize.
Definition: nca.hpp:103
MetricType metric
Metric to be used.
Definition: nca.hpp:100
const arma::mat & dataset
Dataset reference.
Definition: nca.hpp:95
The "softmax" stochastic neighbor assignment probability function.
OptimizerType< SoftmaxErrorFunction< MetricType > > optimizer
The optimizer to use.
Definition: nca.hpp:106
Linear algebra utility functions, generally performed on matrices or vectors.
LMetric< 2, false > SquaredEuclideanDistance
The squared Euclidean (L2) distance.
Definition: lmetric.hpp:108
NCA(const arma::mat &dataset, const arma::Row< size_t > &labels, MetricType metric=MetricType())
Construct the Neighborhood Components Analysis object.
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
const OptimizerType< SoftmaxErrorFunction< MetricType > > & Optimizer() const
Get the optimizer.
Definition: nca.hpp:88
const arma::Row< size_t > & labels
Labels reference.
Definition: nca.hpp:97
const arma::mat & Dataset() const
Get the dataset reference.
Definition: nca.hpp:83
Stochastic Gradient Descent is a technique for minimizing a function which can be expressed as a sum ...
Definition: sgd.hpp:78
An implementation of Neighborhood Components Analysis, both a linear dimensionality reduction techniq...
Definition: nca.hpp:51
const arma::Row< size_t > & Labels() const
Get the labels reference.
Definition: nca.hpp:85
void LearnDistance(arma::mat &outputMatrix)
Perform Neighborhood Components Analysis.
OptimizerType< SoftmaxErrorFunction< MetricType > > & Optimizer()
Definition: nca.hpp:90