SigUtil  0.95
Utility modules for modern C++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
minkowski_distance.hpp
Go to the documentation of this file.
1 /*
2 Copyright© 2014 Akihiro Nishimura
3 
4 This software is released under the MIT License.
5 http://opensource.org/licenses/mit-license.php
6 */
7 
8 #ifndef SIG_UTIL_MINKOWSKI_DISTANCE_HPP
9 #define SIG_UTIL_MINKOWSKI_DISTANCE_HPP
10 
11 #include "comparable_check.hpp"
12 
13 namespace sig
14 {
16 
28 template <size_t P>
30 {
31  template <class C1, class C2>
32  double operator()(C1 const& vec1, C2 const& vec2) const
33  {
34  using T = typename std::common_type<typename impl::container_traits<C1>::value_type, typename impl::container_traits<C2>::value_type>::type;
35 
36  assert(is_comparable(vec1, vec2, impl::NumericVectorTag()));
37 
38  return std::pow(
39  std::inner_product(std::begin(vec1), std::end(vec1), std::begin(vec2), 0.0, std::plus<double>(), [&](T v1, T v2){ return std::pow(std::abs(v1 - v2), P); }),
40  1.0 / P
41  );
42  }
43 };
44 
46 
48 
63 
64 
67 
82 
83 }
84 #endif
const EuclideanDistance euclidean_distance
ユークリッド距離を求める関数(関数オブジェクト)
double operator()(C1 const &vec1, C2 const &vec2) const
ミンコフスキー距離
const ManhattanDistance manhattan_distance
マンハッタン距離を求める関数(関数オブジェクト)
auto end(C &&c) -> std::move_iterator< typename RC::iterator >
bool is_comparable(C1 const &v1, C2 const &v2, impl::NumericVectorTag)
2つのベクトルが比較可能か確認
Definition: array.hpp:15
auto begin(C &&c) -> std::move_iterator< typename RC::iterator >