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>
17 #include <ensmallen.hpp>
18 
20 
21 namespace mlpack {
22 namespace nca {
23 
47 template<typename MetricType = metric::SquaredEuclideanDistance,
48  typename OptimizerType = ens::StandardSGD>
49 class NCA
50 {
51  public:
65  NCA(const arma::mat& dataset,
66  const arma::Row<size_t>& labels,
67  MetricType metric = MetricType());
68 
81  template<typename... CallbackTypes>
82  void LearnDistance(arma::mat& outputMatrix, CallbackTypes&&... callbacks);
83 
85  const arma::mat& Dataset() const { return dataset; }
87  const arma::Row<size_t>& Labels() const { return labels; }
88 
90  const OptimizerType& Optimizer() const { return optimizer; }
91  OptimizerType& Optimizer() { return optimizer; }
92 
93  private:
95  const arma::mat& dataset;
97  const arma::Row<size_t>& labels;
98 
100  MetricType metric;
101 
103  SoftmaxErrorFunction<MetricType> errorFunction;
104 
106  OptimizerType optimizer;
107 };
108 
109 } // namespace nca
110 } // namespace mlpack
111 
112 // Include the implementation.
113 #include "nca_impl.hpp"
114 
115 #endif
The "softmax" 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.
strip_type.hpp
Definition: add_to_po.hpp:21
const arma::mat & Dataset() const
Get the dataset reference.
Definition: nca.hpp:85
The core includes that mlpack expects; standard C++ includes and Armadillo.
const arma::Row< size_t > & Labels() const
Get the labels reference.
Definition: nca.hpp:87
OptimizerType & Optimizer()
Definition: nca.hpp:91
void LearnDistance(arma::mat &outputMatrix, CallbackTypes &&... callbacks)
Perform Neighborhood Components Analysis.
const OptimizerType & Optimizer() const
Get the optimizer.
Definition: nca.hpp:90
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