mlpack  master
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 
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
SoftmaxErrorFunction< MetricType > errorFunction
The function to optimize.
Definition: nca.hpp:101
MetricType metric
Metric to be used.
Definition: nca.hpp:98
const arma::mat & dataset
Dataset reference.
Definition: nca.hpp:93
The "softmax" stochastic neighbor assignment probability function.
OptimizerType< SoftmaxErrorFunction< MetricType > > optimizer
The optimizer to use.
Definition: nca.hpp:104
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
The core includes that mlpack expects; standard C++ includes and Armadillo.
LMetric< 2, false > SquaredEuclideanDistance
The squared Euclidean (L2) distance.
Definition: lmetric.hpp:107
const OptimizerType< SoftmaxErrorFunction< MetricType > > & Optimizer() const
Get the optimizer.
Definition: nca.hpp:86
NCA(const arma::mat &dataset, const arma::Row< size_t > &labels, MetricType metric=MetricType())
Construct the Neighborhood Components Analysis object.
const arma::Row< size_t > & Labels() const
Get the labels reference.
Definition: nca.hpp:83
const arma::mat & Dataset() const
Get the dataset reference.
Definition: nca.hpp:81
const arma::Row< size_t > & labels
Labels reference.
Definition: nca.hpp:95
Stochastic Gradient Descent is a technique for minimizing a function which can be expressed as a sum ...
Definition: sgd.hpp:76
An implementation of Neighborhood Components Analysis, both a linear dimensionality reduction techniq...
Definition: nca.hpp:49
void LearnDistance(arma::mat &outputMatrix)
Perform Neighborhood Components Analysis.
OptimizerType< SoftmaxErrorFunction< MetricType > > & Optimizer()
Definition: nca.hpp:88