12 #ifndef MLPACK_CORE_METRICS_LMETRIC_IMPL_HPP 13 #define MLPACK_CORE_METRICS_LMETRIC_IMPL_HPP 22 template<
int Power,
bool TakeRoot>
23 template<
typename VecTypeA,
typename VecTypeB>
28 typename VecTypeA::elem_type sum = 0;
29 for (
size_t i = 0; i < a.n_elem; ++i)
30 sum += std::pow(fabs(a[i] - b[i]), Power);
35 return std::pow(sum, (1.0 / Power));
40 template<
typename VecTypeA,
typename VecTypeB>
45 return arma::accu(abs(a - b));
49 template<
typename VecTypeA,
typename VecTypeB>
54 return arma::accu(abs(a - b));
59 template<
typename VecTypeA,
typename VecTypeB>
64 return arma::norm(a - b, 2);
68 template<
typename VecTypeA,
typename VecTypeB>
73 return accu(arma::square(a - b));
78 template<
typename VecTypeA,
typename VecTypeB>
83 typename VecTypeA::elem_type sum = 0;
84 for (
size_t i = 0; i < a.n_elem; ++i)
85 sum += std::pow(fabs(a[i] - b[i]), 3.0);
87 return std::pow(arma::accu(arma::pow(arma::abs(a - b), 3.0)), 1.0 / 3.0);
91 template<
typename VecTypeA,
typename VecTypeB>
96 return arma::accu(arma::pow(arma::abs(a - b), 3.0));
101 template<
typename VecTypeA,
typename VecTypeB>
106 return arma::as_scalar(arma::max(arma::abs(a - b)));
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
static VecTypeA::elem_type Evaluate(const VecTypeA &a, const VecTypeB &b)
Computes the distance between two points.
Definition: lmetric_impl.hpp:24