MLPACK  1.0.10
nca.hpp
Go to the documentation of this file.
1 
22 #ifndef __MLPACK_METHODS_NCA_NCA_HPP
23 #define __MLPACK_METHODS_NCA_NCA_HPP
24 
25 #include <mlpack/core.hpp>
28 
30 
31 namespace mlpack {
32 namespace nca {
33 
57 template<typename MetricType = metric::SquaredEuclideanDistance,
58  template<typename> class OptimizerType = optimization::SGD>
59 class NCA
60 {
61  public:
75  NCA(const arma::mat& dataset,
76  const arma::Col<size_t>& labels,
77  MetricType metric = MetricType());
78 
88  void LearnDistance(arma::mat& outputMatrix);
89 
91  const arma::mat& Dataset() const { return dataset; }
93  const arma::Col<size_t>& Labels() const { return labels; }
94 
96  const OptimizerType<SoftmaxErrorFunction<MetricType> >& Optimizer() const
97  { return optimizer; }
98  OptimizerType<SoftmaxErrorFunction<MetricType> >& Optimizer()
99  { return optimizer; }
100 
101  // Returns a string representation of this object.
102  std::string ToString() const;
103 
104  private:
106  const arma::mat& dataset;
108  const arma::Col<size_t>& labels;
109 
111  MetricType metric;
112 
115 
117  OptimizerType<SoftmaxErrorFunction<MetricType> > optimizer;
118 };
119 
120 }; // namespace nca
121 }; // namespace mlpack
122 
123 // Include the implementation.
124 #include "nca_impl.hpp"
125 
126 #endif
SoftmaxErrorFunction< MetricType > errorFunction
The function to optimize.
Definition: nca.hpp:114
MetricType metric
Metric to be used.
Definition: nca.hpp:111
const arma::mat & dataset
Dataset reference.
Definition: nca.hpp:106
The "softmax" stochastic neighbor assignment probability function.
OptimizerType< SoftmaxErrorFunction< MetricType > > optimizer
The optimizer to use.
Definition: nca.hpp:117
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:31
LMetric< 2, false > SquaredEuclideanDistance
Definition: lmetric.hpp:100
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:96
const arma::mat & Dataset() const
Get the dataset reference.
Definition: nca.hpp:91
std::string ToString() const
const arma::Col< size_t > & Labels() const
Get the labels reference.
Definition: nca.hpp:93
Stochastic Gradient Descent is a technique for minimizing a function which can be expressed as a sum ...
Definition: sgd.hpp:86
An implementation of Neighborhood Components Analysis, both a linear dimensionality reduction techniq...
Definition: nca.hpp:59
const arma::Col< size_t > & labels
Labels reference.
Definition: nca.hpp:108
void LearnDistance(arma::mat &outputMatrix)
Perform Neighborhood Components Analysis.
OptimizerType< SoftmaxErrorFunction< MetricType > > & Optimizer()
Definition: nca.hpp:98