MLPACK  1.0.7
nca_softmax_error_function.hpp
Go to the documentation of this file.
1 
23 #ifndef __MLPACK_METHODS_NCA_NCA_SOFTMAX_ERROR_FUNCTION_HPP
24 #define __MLPACK_METHODS_NCA_NCA_SOFTMAX_ERROR_FUNCTION_HPP
25 
26 #include <mlpack/core.hpp>
27 
28 namespace mlpack {
29 namespace nca {
30 
51 template<typename MetricType = metric::SquaredEuclideanDistance>
53 {
54  public:
65  SoftmaxErrorFunction(const arma::mat& dataset,
66  const arma::Col<size_t>& labels,
67  MetricType metric = MetricType());
68 
76  double Evaluate(const arma::mat& covariance);
77 
88  double Evaluate(const arma::mat& covariance, const size_t i);
89 
98  void Gradient(const arma::mat& covariance, arma::mat& gradient);
99 
111  void Gradient(const arma::mat& covariance,
112  const size_t i,
113  arma::mat& gradient);
114 
118  const arma::mat GetInitialPoint() const;
119 
124  size_t NumFunctions() const { return dataset.n_cols; }
125 
126  private:
128  const arma::mat& dataset;
130  const arma::Col<size_t>& labels;
131 
133  MetricType metric;
134 
136  arma::mat lastCoordinates;
138  arma::mat stretchedDataset;
140  arma::vec p;
143  arma::vec denominators;
144 
147 
161  void Precalculate(const arma::mat& coordinates);
162 };
163 
164 }; // namespace nca
165 }; // namespace mlpack
166 
167 // Include implementation.
168 #include "nca_softmax_error_function_impl.hpp"
169 
170 #endif