mlpack  1.0.12
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::Col<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::Col<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  // Returns a string representation of this object.
94  std::string ToString() const;
95 
96  private:
98  const arma::mat& dataset;
100  const arma::Col<size_t>& labels;
101 
103  MetricType metric;
104 
107 
109  OptimizerType<SoftmaxErrorFunction<MetricType> > optimizer;
110 };
111 
112 }; // namespace nca
113 }; // namespace mlpack
114 
115 // Include the implementation.
116 #include "nca_impl.hpp"
117 
118 #endif
SoftmaxErrorFunction< MetricType > errorFunction
The function to optimize.
Definition: nca.hpp:106
MetricType metric
Metric to be used.
Definition: nca.hpp:103
const arma::mat & dataset
Dataset reference.
Definition: nca.hpp:98
The "softmax" stochastic neighbor assignment probability function.
OptimizerType< SoftmaxErrorFunction< MetricType > > optimizer
The optimizer to use.
Definition: nca.hpp:109
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:23
LMetric< 2, false > SquaredEuclideanDistance
Definition: lmetric.hpp:92
NCA(const arma::mat &dataset, const arma::Col< size_t > &labels, MetricType metric=MetricType())
Construct the Neighborhood Components Analysis object.
const OptimizerType< SoftmaxErrorFunction< MetricType > > & Optimizer() const
Get the optimizer.
Definition: nca.hpp:88
const arma::mat & Dataset() const
Get the dataset reference.
Definition: nca.hpp:83
std::string ToString() const
const arma::Col< size_t > & Labels() const
Get the labels reference.
Definition: nca.hpp:85
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::Col< size_t > & labels
Labels reference.
Definition: nca.hpp:100
void LearnDistance(arma::mat &outputMatrix)
Perform Neighborhood Components Analysis.
OptimizerType< SoftmaxErrorFunction< MetricType > > & Optimizer()
Definition: nca.hpp:90