MLPACK
1.0.4
|
00001 00023 #ifndef __MLPACK_METHODS_NCA_NCA_SOFTMAX_ERROR_FUNCTION_HPP 00024 #define __MLPACK_METHODS_NCA_NCA_SOFTMAX_ERROR_FUNCTION_HPP 00025 00026 #include <mlpack/core.hpp> 00027 00028 namespace mlpack { 00029 namespace nca { 00030 00051 template<typename MetricType = metric::SquaredEuclideanDistance> 00052 class SoftmaxErrorFunction 00053 { 00054 public: 00065 SoftmaxErrorFunction(const arma::mat& dataset, 00066 const arma::uvec& labels, 00067 MetricType metric = MetricType()); 00068 00076 double Evaluate(const arma::mat& covariance); 00077 00088 double Evaluate(const arma::mat& covariance, const size_t i); 00089 00098 void Gradient(const arma::mat& covariance, arma::mat& gradient); 00099 00111 void Gradient(const arma::mat& covariance, 00112 const size_t i, 00113 arma::mat& gradient); 00114 00118 const arma::mat GetInitialPoint() const; 00119 00124 size_t NumFunctions() const { return dataset.n_cols; } 00125 00126 private: 00127 const arma::mat& dataset; 00128 const arma::uvec& labels; 00129 00130 MetricType metric; 00131 00133 arma::mat lastCoordinates; 00135 arma::mat stretchedDataset; 00137 arma::vec p; 00140 arma::vec denominators; 00141 00143 bool precalculated; 00144 00158 void Precalculate(const arma::mat& coordinates); 00159 }; 00160 00161 }; // namespace nca 00162 }; // namespace mlpack 00163 00164 // Include implementation. 00165 #include "nca_softmax_error_function_impl.hpp" 00166 00167 #endif