SigUtil  0.95
Utility modules for modern C++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mahalanobis_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_MAHALANOBIS_DISTANCE_HPP
9 #define SIG_UTIL_MAHALANOBIS_DISTANCE_HPP
10 
11 #include "comparable_check.hpp"
12 #include "../calculation/ublas.hpp"
13 #include "../calculation/binary_operation.hpp"
14 
15 namespace sig
16 {
17 namespace impl
18 {
19  template <class T>
21  matrix_u<T> const& cov,
22  vector_u<T> const& v)
23  {
24  using boost::numeric;
25  return std::sqrt(ublas::inner_prod(v, ublas::prod(*invert_matrix(cov), v)));
26  }
27 }
28 
30 {
31  template <class T1, class T2>
32  double operator()(vector_u<T1> const& vec1, vector_u<T2> const& vec2) const
33  {
34  //assert(is_comparable(vec1, vec2, impl::NumericVectorTag()));
35 
36  return impl::mahalanobis_impl(covariance(vec1, vec2), minus(vec1, vec2));
37  }
38 };
39 
40 }
41 #endif
double operator()(vector_u< T1 > const &vec1, vector_u< T2 > const &vec2) const
double mahalanobis_impl(matrix_u< T > const &cov, vector_u< T > const &v)
boost::numeric::ublas::matrix< T > matrix_u
Definition: ublas.hpp:28
auto minus(T1 &&v1, T2 &&v2) -> decltype(binary_operation(minus_t(), std::forward< T1 >(v1), std::forward< T2 >(v2)))
auto invert_matrix(matrix_u< T > &&mat) -> Maybe< matrix_u< RT >>
逆行列を求める
Definition: ublas.hpp:204
boost::numeric::ublas::vector< T > vector_u
Definition: ublas.hpp:49
Definition: array.hpp:15