SigUtil  0.95
Utility modules for modern C++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
binary_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_BINARY_DISTANCE_HPP
9 #define SIG_UTIL_BINARY_DISTANCE_HPP
10 
11 #include "comparable_check.hpp"
12 
13 namespace sig
14 {
15 
18 {
19  template <class C1, class C2,
20  typename = typename std::enable_if<std::is_integral<typename impl::container_traits<C1>::value_type>::value>::type,
21  typename = typename std::enable_if<std::is_integral<typename impl::container_traits<C2>::value_type>::value>::type
22  >
23  double operator()(C1 const& vec1, C2 const& vec2) const
24  {
25  assert(is_comparable(vec1, vec2, impl::NumericVectorTag()));
26 
27  int ether = 0, both = 0;
28  auto it1 = std::begin(vec1), end1 = std::end(vec1);
29  auto it2 = std::begin(vec2), end2 = std::end(vec2);
30 
31  for (; it1 != end1 && it2 != end2; ++it1, ++it2){
32  if (*it1 == 1 && *it2 == 1) ++both;
33  else if (*it1 == 1 || *it2 == 1) ++ether;
34  }
35  return static_cast<double>(ether) / (ether + both);
36  }
37 };
38 
40 
55 
56 }
57 #endif
auto end(C &&c) -> std::move_iterator< typename RC::iterator >
bool is_comparable(C1 const &v1, C2 const &v2, impl::NumericVectorTag)
2つのベクトルが比較可能か確認
double operator()(C1 const &vec1, C2 const &vec2) const
const BinaryDistance binary_distance
バイナリ距離を求める関数(関数オブジェクト)
バイナリ距離
Definition: array.hpp:15
auto begin(C &&c) -> std::move_iterator< typename RC::iterator >