yat  0.13.2pre
EuclideanDistance.h
1 #ifndef theplu_yat_statistics_euclidean_distance_h
2 #define theplu_yat_statistics_euclidean_distance_h
3 
4 // $Id: EuclideanDistance.h 2202 2010-02-21 18:39:13Z peter $
5 
6 /*
7  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson, Markus Ringnér
8  Copyright (C) 2010 Peter Johansson
9 
10  This file is part of the yat library, http://dev.thep.lu.se/yat
11 
12  The yat library is free software; you can redistribute it and/or
13  modify it under the terms of the GNU General Public License as
14  published by the Free Software Foundation; either version 3 of the
15  License, or (at your option) any later version.
16 
17  The yat library is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with yat. If not, see <http://www.gnu.org/licenses/>.
24 */
25 
26 #include "AveragerPair.h"
27 #include "AveragerPairWeighted.h"
28 #include "yat/utility/iterator_traits.h"
29 
30 #include <cmath>
31 
32 namespace theplu {
33 namespace yat {
34 namespace statistics {
35 
44  {
63  template <typename ForwardIterator1, typename ForwardIterator2>
64  double operator()(ForwardIterator1 beg1, ForwardIterator1 end1,
65  ForwardIterator2 beg2) const
66  {
68  typename weighted_if_any2<ForwardIterator1,ForwardIterator2>::type tag;
69  return this->distance(beg1, end1, beg2, tag);
70  }
71 
72  private:
73  template <typename Iter1, typename Iter2>
74  double distance (Iter1 beg1,Iter1 end1, Iter2 beg2,
76  {
77  AveragerPair ap;
78  add(ap,beg1,end1,beg2);
79  return sqrt(ap.sum_squared_deviation());
80  }
81 
82  template <typename Iter1, typename Iter2>
83  double distance (Iter1 beg1,Iter1 end1, Iter2 beg2,
85  {
86  AveragerPairWeighted ap;
87  add(ap,beg1,end1,beg2);
88  return sqrt(std::distance(beg1,end1)*ap.msd());
89  }
90 
91  };
92 
93 }}} // of namespace statistics, yat, and theplu
94 
95 #endif
Definition: iterator_traits.h:47
Calculates the Euclidean distance between two points given by elements of ranges. ...
Definition: EuclideanDistance.h:43
double sum_squared_deviation(void) const
Class for taking care of mean and covariance of two variables.
Definition: AveragerPair.h:46
Definition: iterator_traits.h:55
double operator()(ForwardIterator1 beg1, ForwardIterator1 end1, ForwardIterator2 beg2) const
Calculates the Euclidean distance between elements of two ranges.
Definition: EuclideanDistance.h:64
void add(T &o, ForwardIterator first, ForwardIterator last, const classifier::Target &target)
Definition: utility.h:282
Definition: iterator_traits.h:159

Generated on Wed Jan 4 2017 02:23:07 for yat by  doxygen 1.8.5