facilities.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_CORE_CV_METRICS_FACILITIES_HPP
14 #define MLPACK_CORE_CV_METRICS_FACILITIES_HPP
15 
16 #include <mlpack/core.hpp>
18 
19 namespace mlpack {
20 namespace cv {
21 
30 template<typename DataType>
31 void AssertSizes(const DataType& data,
32  const arma::Row& labels,
33  const std::string& callerDescription)
34 {
35  if (data.n_cols != labels.n_elem)
36  {
37  std::ostringstream oss;
38  oss << callerDescription << ": number of points (" << data.n_cols << ") "
39  << "does not match number of labels (" << labels.n_elem << ")!"
40  << std::endl;
41  throw std::invalid_argument(oss.str());
42  }
43 }
44 
51 template<typename DataType, typename Metric>
52 DataType PairwiseDistances(const DataType& data,
53  const Metric& metric)
54 {
55  DataType distances = DataType(data.n_cols, data.n_cols, arma::fill::none);
56  for (size_t i = 0; i < data.n_cols; i++)
57  {
58  for (size_t j = 0; j < i; j++)
59  {
60  distances(i, j) = metric.Evaluate(data.col(i), data.col(j));
61  distances(j, i) = distances(i, j);
62  }
63  }
64  distances.diag().zeros();
65  return distances;
66 }
67 
68 } // namespace cv
69 } // namespace mlpack
70 
71 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
void AssertSizes(const DataType &data, const arma::Row< size_t > &labels, const std::string &callerDescription)
Assert there is the same number of the given data points and labels.
Definition: facilities.hpp:31
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...
DataType PairwiseDistances(const DataType &data, const Metric &metric)
Pairwise distance of the given data.
Definition: facilities.hpp:52