mlpack  1.0.12
nca_softmax_error_function.hpp
Go to the documentation of this file.
1 
15 #ifndef __MLPACK_METHODS_NCA_NCA_SOFTMAX_ERROR_FUNCTION_HPP
16 #define __MLPACK_METHODS_NCA_NCA_SOFTMAX_ERROR_FUNCTION_HPP
17 
18 #include <mlpack/core.hpp>
19 
20 namespace mlpack {
21 namespace nca {
22 
43 template<typename MetricType = metric::SquaredEuclideanDistance>
45 {
46  public:
57  SoftmaxErrorFunction(const arma::mat& dataset,
58  const arma::Col<size_t>& labels,
59  MetricType metric = MetricType());
60 
68  double Evaluate(const arma::mat& covariance);
69 
80  double Evaluate(const arma::mat& covariance, const size_t i);
81 
90  void Gradient(const arma::mat& covariance, arma::mat& gradient);
91 
103  void Gradient(const arma::mat& covariance,
104  const size_t i,
105  arma::mat& gradient);
106 
110  const arma::mat GetInitialPoint() const;
111 
116  size_t NumFunctions() const { return dataset.n_cols; }
117 
118  // convert the obkect into a string
119  std::string ToString() const;
120 
121  private:
123  const arma::mat& dataset;
125  const arma::Col<size_t>& labels;
126 
128  MetricType metric;
129 
131  arma::mat lastCoordinates;
133  arma::mat stretchedDataset;
135  arma::vec p;
138  arma::vec denominators;
139 
142 
156  void Precalculate(const arma::mat& coordinates);
157 };
158 
159 }; // namespace nca
160 }; // namespace mlpack
161 
162 // Include implementation.
163 #include "nca_softmax_error_function_impl.hpp"
164 
165 #endif
The "softmax" stochastic neighbor assignment probability function.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:23
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.