1 | #ifndef theplu_yat_statistics_euclidean_vector_distance_h |
---|

2 | #define theplu_yat_statistics_euclidean_vector_distance_h |
---|

3 | |
---|

4 | // $Id: euclidean_vector_distance.h 899 2007-09-26 21:26:25Z peter $ |
---|

5 | |
---|

6 | #include "AveragerPair.h" |
---|

7 | #include "AveragerPairWeighted.h" |
---|

8 | #include "vector_distance.h" |
---|

9 | |
---|

10 | #include <cmath> |
---|

11 | |
---|

12 | namespace theplu { |
---|

13 | namespace yat { |
---|

14 | |
---|

15 | namespace statistics { |
---|

16 | |
---|

17 | /// |
---|

18 | /// Provides a "label" for |
---|

19 | /// the Euclidean distance measure. |
---|

20 | /// |
---|

21 | struct euclidean_vector_distance_tag |
---|

22 | : public vector_distance_tag |
---|

23 | { |
---|

24 | typedef euclidean_vector_distance_tag distance; |
---|

25 | }; |
---|

26 | |
---|

27 | |
---|

28 | /// |
---|

29 | /// implementation for distances between vectors |
---|

30 | /// (containers with random access iterators) using a Euclidean |
---|

31 | /// distance measure and iterators to unweighted containers. |
---|

32 | /// |
---|

33 | template <typename Iter1, typename Iter2> |
---|

34 | double vector_distance(Iter1 beg1,Iter1 end1, Iter2 beg2, |
---|

35 | const euclidean_vector_distance_tag& disttype, |
---|

36 | std::random_access_iterator_tag) |
---|

37 | { |
---|

38 | AveragerPair ap; |
---|

39 | add(ap,beg1,end1,beg2); |
---|

40 | return sqrt(ap.sum_squared_deviation()); |
---|

41 | } |
---|

42 | |
---|

43 | |
---|

44 | /// |
---|

45 | /// implementation for distances between vectors |
---|

46 | /// (containers with random access iterators) using a Euclidean |
---|

47 | /// distance measure and iterators to weighted containers. |
---|

48 | /// |
---|

49 | template <typename Iter1, typename Iter2> |
---|

50 | double vector_distance(Iter1 beg1, Iter1 end1, Iter2 beg2, |
---|

51 | const euclidean_vector_distance_tag& disttype, |
---|

52 | utility::weighted_random_access_iterator_tag) |
---|

53 | { |
---|

54 | AveragerPairWeighted ap; |
---|

55 | add(ap,beg1,end1,beg2); |
---|

56 | return sqrt(ap.n()*ap.msd()); |
---|

57 | } |
---|

58 | |
---|

59 | |
---|

60 | }}} // of namespace statistics, yat, and theplu |
---|

61 | |
---|

62 | #endif |
---|