mlpack  master
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>
17 
18 namespace mlpack {
19 namespace nca {
20 
41 template<typename MetricType = metric::SquaredEuclideanDistance>
43 {
44  public:
55  SoftmaxErrorFunction(const arma::mat& dataset,
56  const arma::Row<size_t>& labels,
57  MetricType metric = MetricType());
58 
66  double Evaluate(const arma::mat& covariance);
67 
78  double Evaluate(const arma::mat& covariance, const size_t i);
79 
88  void Gradient(const arma::mat& covariance, arma::mat& gradient);
89 
101  void Gradient(const arma::mat& covariance,
102  const size_t i,
103  arma::mat& gradient);
104 
108  const arma::mat GetInitialPoint() const;
109 
114  size_t NumFunctions() const { return dataset.n_cols; }
115 
116  private:
118  const arma::mat& dataset;
120  const arma::Row<size_t>& labels;
121 
123  MetricType metric;
124 
126  arma::mat lastCoordinates;
128  arma::mat stretchedDataset;
130  arma::vec p;
133  arma::vec denominators;
134 
137 
151  void Precalculate(const arma::mat& coordinates);
152 };
153 
154 } // namespace nca
155 } // namespace mlpack
156 
157 // Include implementation.
158 #include "nca_softmax_error_function_impl.hpp"
159 
160 #endif
The "softmax" stochastic neighbor assignment probability function.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
const arma::Row< size_t > & labels
Labels for each point in the dataset.
arma::vec denominators
Holds denominators for calculation of p_ij, for the non-separable Evaluate() and Gradient().
const arma::mat GetInitialPoint() const
Get the initial point.
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t NumFunctions() const
Get the number of functions the objective function can be decomposed into.
void Gradient(const arma::mat &covariance, arma::mat &gradient)
Evaluate the gradient of the softmax function for the given covariance matrix.
bool precalculated
False if nothing has ever been precalculated (only at construction time).
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...
double Evaluate(const arma::mat &covariance)
Evaluate the softmax function for the given covariance matrix.
arma::vec p
Holds calculated p_i, for the non-separable Evaluate() and Gradient().
MetricType metric
The instantiated metric.
void Precalculate(const arma::mat &coordinates)
Precalculate the denominators and numerators that will make up the p_ij, but only if the coordinates ...
arma::mat lastCoordinates
Last coordinates. Used for the non-separable Evaluate() and Gradient().
arma::mat stretchedDataset
Stretched dataset. Kept internal to avoid memory reallocations.