SigUtil  0.95
Utility modules for modern C++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
canberra_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_CANBERRA_DISTANCE_HPP
9 #define SIG_UTIL_CANBERRA_DISTANCE_HPP
10 
11 #include "../functional/high_order.hpp"
12 #include "comparable_check.hpp"
13 
14 namespace sig
15 {
16 
19 {
20  template <class C1, class C2>
21  double operator()(C1 const& vec1, C2 const& vec2) const
22  {
23  using T = typename std::common_type<typename impl::container_traits<C1>::value_type, typename impl::container_traits<C2>::value_type>::type;
24 
25  assert(is_comparable(vec1, vec2, impl::NumericVectorTag()));
26  auto tmp = sig::zipWith([](T val1, T val2){ return static_cast<T>(std::abs(val1 - val2)) / (std::abs(val1) + std::abs(val2)); }, vec1, vec2);
27 
28  return std::accumulate(std::begin(tmp), std::end(tmp), T(), std::plus<T>());
29  }
30 };
31 
33 
48 
49 }
50 #endif
const CanberraDistance canberra_distance
キャンベラ距離を求める関数(関数オブジェクト)
auto end(C &&c) -> std::move_iterator< typename RC::iterator >
bool is_comparable(C1 const &v1, C2 const &v2, impl::NumericVectorTag)
2つのベクトルが比較可能か確認
auto zipWith(F &&func, C1 &&list1, C2 &&list2)
2引数高階関数
Definition: high_order.hpp:88
double operator()(C1 const &vec1, C2 const &vec2) const
キャンベラ距離
Definition: array.hpp:15
auto begin(C &&c) -> std::move_iterator< typename RC::iterator >