MLPACK  1.0.10
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  // convert the obkect into a string
127  std::string ToString() const;
128 
129  private:
131  const arma::mat& dataset;
133  const arma::Col<size_t>& labels;
134 
136  MetricType metric;
137 
139  arma::mat lastCoordinates;
141  arma::mat stretchedDataset;
143  arma::vec p;
146  arma::vec denominators;
147 
150 
164  void Precalculate(const arma::mat& coordinates);
165 };
166 
167 }; // namespace nca
168 }; // namespace mlpack
169 
170 // Include implementation.
171 #include "nca_softmax_error_function_impl.hpp"
172 
173 #endif