mlpack  3.4.2
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>
20 
21 namespace mlpack {
22 namespace nca {
23 
44 template<typename MetricType = metric::SquaredEuclideanDistance>
46 {
47  public:
58  SoftmaxErrorFunction(const arma::mat& dataset,
59  const arma::Row<size_t>& labels,
60  MetricType metric = MetricType());
61 
65  void Shuffle();
66 
74  double Evaluate(const arma::mat& covariance);
75 
88  double Evaluate(const arma::mat& covariance,
89  const size_t begin,
90  const size_t batchSize = 1);
91 
100  void Gradient(const arma::mat& covariance, arma::mat& gradient);
101 
117  template <typename GradType>
118  void Gradient(const arma::mat& covariance,
119  const size_t begin,
120  GradType& gradient,
121  const size_t batchSize = 1);
122 
126  const arma::mat GetInitialPoint() const;
127 
132  size_t NumFunctions() const { return dataset.n_cols; }
133 
134  private:
136  arma::mat dataset;
139  arma::Row<size_t> labels;
140 
142  MetricType metric;
143 
145  arma::mat lastCoordinates;
147  arma::mat stretchedDataset;
149  arma::vec p;
152  arma::vec denominators;
153 
155  bool precalculated;
156 
170  void Precalculate(const arma::mat& coordinates);
171 };
172 
173 } // namespace nca
174 } // namespace mlpack
175 
176 // Include implementation.
177 #include "nca_softmax_error_function_impl.hpp"
178 
179 #endif
mlpack::nca::SoftmaxErrorFunction
The "softmax" stochastic neighbor assignment probability function.
Definition: nca_softmax_error_function.hpp:46
prereqs.hpp
The core includes that mlpack expects; standard C++ includes and Armadillo.
lmetric.hpp
mlpack::nca::SoftmaxErrorFunction::NumFunctions
size_t NumFunctions() const
Get the number of functions the objective function can be decomposed into.
Definition: nca_softmax_error_function.hpp:132
mlpack::nca::SoftmaxErrorFunction::Evaluate
double Evaluate(const arma::mat &covariance, const size_t begin, const size_t batchSize=1)
Evaluate the softmax objective function for the given covariance matrix on the given batch size from ...
mlpack
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: add_to_cli11.hpp:21
mlpack::nca::SoftmaxErrorFunction::Shuffle
void Shuffle()
Shuffle the dataset.
make_alias.hpp
mlpack::nca::SoftmaxErrorFunction::GetInitialPoint
const arma::mat GetInitialPoint() const
Get the initial point.
mlpack::nca::SoftmaxErrorFunction::SoftmaxErrorFunction
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...
mlpack::nca::SoftmaxErrorFunction::Gradient
void Gradient(const arma::mat &covariance, arma::mat &gradient)
Evaluate the gradient of the softmax function for the given covariance matrix.
shuffle_data.hpp
mlpack::nca::SoftmaxErrorFunction::Evaluate
double Evaluate(const arma::mat &covariance)
Evaluate the softmax function for the given covariance matrix.
mlpack::nca::SoftmaxErrorFunction::Gradient
void Gradient(const arma::mat &covariance, const size_t begin, GradType &gradient, const size_t batchSize=1)
Evaluate the gradient of the softmax function for the given covariance matrix on the given batch size...