mlpack  2.2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
nca.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_NCA_NCA_HPP
13 #define MLPACK_METHODS_NCA_NCA_HPP
14 
15 #include <mlpack/prereqs.hpp>
18 
20 
21 namespace mlpack {
22 namespace nca {
23 
47 template<typename MetricType = metric::SquaredEuclideanDistance,
48  template<typename> class OptimizerType = optimization::SGD>
49 class NCA
50 {
51  public:
65  NCA(const arma::mat& dataset,
66  const arma::Row<size_t>& labels,
67  MetricType metric = MetricType());
68 
78  void LearnDistance(arma::mat& outputMatrix);
79 
81  const arma::mat& Dataset() const { return dataset; }
83  const arma::Row<size_t>& Labels() const { return labels; }
84 
86  const OptimizerType<SoftmaxErrorFunction<MetricType> >& Optimizer() const
87  { return optimizer; }
88  OptimizerType<SoftmaxErrorFunction<MetricType> >& Optimizer()
89  { return optimizer; }
90 
91  private:
93  const arma::mat& dataset;
95  const arma::Row<size_t>& labels;
96 
98  MetricType metric;
99 
101  SoftmaxErrorFunction<MetricType> errorFunction;
102 
104  OptimizerType<SoftmaxErrorFunction<MetricType> > optimizer;
105 };
106 
107 } // namespace nca
108 } // namespace mlpack
109 
110 // Include the implementation.
111 #include "nca_impl.hpp"
112 
113 #endif
The &quot;softmax&quot; stochastic neighbor assignment probability function.
NCA(const arma::mat &dataset, const arma::Row< size_t > &labels, MetricType metric=MetricType())
Construct the Neighborhood Components Analysis object.
const OptimizerType< SoftmaxErrorFunction< MetricType > > & Optimizer() const
Get the optimizer.
Definition: nca.hpp:86
The core includes that mlpack expects; standard C++ includes and Armadillo.
OptimizerType< SoftmaxErrorFunction< MetricType > > & Optimizer()
Definition: nca.hpp:88
const arma::mat & Dataset() const
Get the dataset reference.
Definition: nca.hpp:81
Stochastic Gradient Descent is a technique for minimizing a function which can be expressed as a sum ...
Definition: sgd.hpp:76
LMetric< 2, false > SquaredEuclideanDistance
The squared Euclidean (L2) distance.
Definition: lmetric.hpp:107
An implementation of Neighborhood Components Analysis, both a linear dimensionality reduction techniq...
Definition: nca.hpp:49
const arma::Row< size_t > & Labels() const
Get the labels reference.
Definition: nca.hpp:83
void LearnDistance(arma::mat &outputMatrix)
Perform Neighborhood Components Analysis.