Changeset 1306 for trunk/yat


Ignore:
Timestamp:
May 15, 2008, 12:44:30 AM (13 years ago)
Author:
Peter
Message:

adding a similar AveragerPair? traits and using it in PearsonDistance? to simplify the code

Location:
trunk/yat/statistics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/statistics/PearsonDistance.h

    r1275 r1306  
    2626*/
    2727
    28 #include "AveragerPair.h"
    29 #include "AveragerPairWeighted.h"
     28#include "averager_traits.h"
    3029#include "yat/utility/iterator_traits.h"
    3130
     
    6362    (Iter1 beg1,Iter1 end1, Iter2 beg2) const
    6463    {
    65       return this->distance(beg1, end1, beg2, 
    66                       typename utility::weighted_if_any2<Iter1,Iter2>::type());
    67     }
    68 
    69   private:
    70     template <typename Iter1, typename Iter2>
    71     double distance (Iter1 beg1,Iter1 end1, Iter2 beg2,
    72                      utility::unweighted_iterator_tag) const
    73     {
    74       AveragerPairWeighted ap;
     64      typename averager_pair<Iter1, Iter2>::type ap;
    7565      add(ap,beg1,end1,beg2);
    7666      return 1-ap.correlation();
    7767    }
    78 
    79     template <typename Iter1, typename Iter2>
    80     double distance (Iter1 beg1,Iter1 end1, Iter2 beg2,
    81                      utility::weighted_iterator_tag) const
    82     {
    83       AveragerPairWeighted ap;
    84       add(ap,beg1,end1,beg2);
    85       return 1-ap.correlation();
    86     }
    87    
    8868  };
    8969
  • trunk/yat/statistics/averager_traits.h

    r1305 r1306  
    2525*/
    2626
    27 #include "yat/utility/iterator_traits.h"
    2827#include "Averager.h"
    2928#include "AveragerWeighted.h"
     29#include "AveragerPair.h"
     30#include "AveragerPairWeighted.h"
     31#include "yat/utility/iterator_traits.h"
    3032
    3133namespace theplu {
     
    4951  */
    5052    typedef Averager type;
     53    typedef AveragerPair pair_type;
    5154  };
    5255
     
    6164  */
    6265    typedef AveragerWeighted type;
     66    typedef AveragerPairWeighted pair_type;
    6367  };
    6468
    6569  /**
    66       Convenience wrapper around averager_t
    67       \see averager_t
     70      Convenience wrapper around averager_traits
    6871      \see weighted_iterator_traits                                         \
    6972  */
     
    7982  };
    8083
     84  /**
     85      Convenience wrapper around averager_traits
     86      \see weighted_iterator_traits                                         \
     87  */
     88  template <typename Iterator1, typename Iterator2>
     89  struct averager_pair
     90  {
     91  /**
     92      Convenience Metafunction taking iterator as argument and return
     93      either Averager (if both iterators are unweighted) or AveragerWeighted
     94      otherwise.
     95  */
     96    typedef typename
     97      averager_traits<
     98        typename utility::weighted_if_any2<Iterator1, Iterator2>::type
     99      >::pair_type type;
     100  };
     101
    81102}}} // of namespace statistics, yat, and theplu
    82103
Note: See TracChangeset for help on using the changeset viewer.