nca_softmax_error_function.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_NCA_NCA_SOFTMAX_ERROR_FUNCTION_HPP
14 #define MLPACK_METHODS_NCA_NCA_SOFTMAX_ERROR_FUNCTION_HPP
15 
16 #include <mlpack/prereqs.hpp>
18 
19 namespace mlpack {
20 namespace nca {
21 
42 template<typename MetricType = metric::SquaredEuclideanDistance>
44 {
45  public:
56  SoftmaxErrorFunction(const arma::mat& dataset,
57  const arma::Row<size_t>& labels,
58  MetricType metric = MetricType());
59 
63  void Shuffle();
64 
72  double Evaluate(const arma::mat& covariance);
73 
86  double Evaluate(const arma::mat& covariance,
87  const size_t begin,
88  const size_t batchSize = 1);
89 
98  void Gradient(const arma::mat& covariance, arma::mat& gradient);
99 
115  template <typename GradType>
116  void Gradient(const arma::mat& covariance,
117  const size_t begin,
118  GradType& gradient,
119  const size_t batchSize = 1);
120 
124  const arma::mat GetInitialPoint() const;
125 
130  size_t NumFunctions() const { return dataset.n_cols; }
131 
132  private:
134  arma::mat dataset;
137  arma::Row<size_t> labels;
138 
140  MetricType metric;
141 
143  arma::mat lastCoordinates;
145  arma::mat stretchedDataset;
147  arma::vec p;
150  arma::vec denominators;
151 
153  bool precalculated;
154 
168  void Precalculate(const arma::mat& coordinates);
169 };
170 
171 } // namespace nca
172 } // namespace mlpack
173 
174 // Include implementation.
175 #include "nca_softmax_error_function_impl.hpp"
176 
177 #endif
The "softmax" stochastic neighbor assignment probability function.
size_t NumFunctions() const
Get the number of functions the objective function can be decomposed into.
.hpp
Definition: add_to_po.hpp:21
void Shuffle()
Shuffle the dataset.
The core includes that mlpack expects; standard C++ includes and Armadillo.
double Evaluate(const arma::mat &covariance)
Evaluate the softmax function for the given covariance matrix.
const arma::mat GetInitialPoint() const
Get the initial point.
SoftmaxErrorFunction(const arma::mat &dataset, const arma::Row< size_t > &labels, MetricType metric=MetricType())
Initialize with the given kernel; useful when the kernel has some state to store, which is set elsewh...
void Gradient(const arma::mat &covariance, arma::mat &gradient)
Evaluate the gradient of the softmax function for the given covariance matrix.