yat  0.8.3pre
EuclideanDistance.h
00001 #ifndef theplu_yat_statistics_euclidean_distance_h
00002 #define theplu_yat_statistics_euclidean_distance_h
00003 
00004 // $Id: EuclideanDistance.h 2202 2010-02-21 18:39:13Z peter $
00005 
00006 /*
00007   Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson, Markus Ringnér
00008   Copyright (C) 2010 Peter Johansson
00009 
00010   This file is part of the yat library, http://dev.thep.lu.se/yat
00011 
00012   The yat library is free software; you can redistribute it and/or
00013   modify it under the terms of the GNU General Public License as
00014   published by the Free Software Foundation; either version 3 of the
00015   License, or (at your option) any later version.
00016 
00017   The yat library is distributed in the hope that it will be useful,
00018   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00020   General Public License for more details.
00021 
00022   You should have received a copy of the GNU General Public License
00023   along with yat. If not, see <http://www.gnu.org/licenses/>.
00024 */
00025 
00026 #include "AveragerPair.h"
00027 #include "AveragerPairWeighted.h"
00028 #include "yat/utility/iterator_traits.h"
00029 
00030 #include <cmath>
00031 
00032 namespace theplu {
00033 namespace yat {
00034 namespace statistics {
00035   
00043   struct EuclideanDistance
00044   {   
00063     template <typename ForwardIterator1, typename ForwardIterator2>
00064     double operator()(ForwardIterator1 beg1, ForwardIterator1 end1, 
00065                       ForwardIterator2 beg2) const
00066     {
00067       using utility::weighted_if_any2;
00068       typename weighted_if_any2<ForwardIterator1,ForwardIterator2>::type tag; 
00069       return this->distance(beg1, end1, beg2, tag); 
00070     }
00071 
00072   private:
00073     template <typename Iter1, typename Iter2>
00074     double distance (Iter1 beg1,Iter1 end1, Iter2 beg2, 
00075                      utility::unweighted_iterator_tag) const
00076     {
00077       AveragerPair ap;
00078       add(ap,beg1,end1,beg2);
00079       return sqrt(ap.sum_squared_deviation());
00080     }
00081 
00082     template <typename Iter1, typename Iter2>
00083     double distance (Iter1 beg1,Iter1 end1, Iter2 beg2, 
00084                      utility::weighted_iterator_tag) const
00085     {
00086       AveragerPairWeighted ap;
00087       add(ap,beg1,end1,beg2);
00088       return sqrt(std::distance(beg1,end1)*ap.msd());
00089     }
00090     
00091   };
00092 
00093 }}} // of namespace statistics, yat, and theplu
00094     
00095 #endif

Generated on Thu Dec 20 2012 03:12:58 for yat by  doxygen 1.8.0-20120409