MLPACK  1.0.11
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
The "softmax" stochastic neighbor assignment probability function.
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.
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.
SoftmaxErrorFunction(const arma::mat &dataset, const arma::Col< size_t > &labels, MetricType metric=MetricType())
Initialize with the given kernel; useful when the kernel has some state to store, which is set elsewh...
bool precalculated
False if nothing has ever been precalculated (only at construction time).
double Evaluate(const arma::mat &covariance)
Evaluate the softmax function for the given covariance matrix.
std::string ToString() const
arma::vec p
Holds calculated p_i, for the non-separable Evaluate() and Gradient().
MetricType metric
The instantiated metric.
const arma::Col< size_t > & labels
Labels for each point in the dataset.
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.