Ignore:
Timestamp:
Feb 7, 2008, 7:47:34 PM (15 years ago)
Author:
Peter
Message:

Simplifying distance structure

File:
1 edited

Legend:

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

    r1031 r1050  
    66/*
    77  Copyright (C) 2007 Peter Johansson, Markus Ringnér
     8  Copyright (C) 2008 Peter Johansson
    89
    910  This file is part of the yat library, http://trac.thep.lu.se/yat
     
    2526*/
    2627
    27 #include "distance.h"
    28 
    2928#include "AveragerPair.h"
    3029#include "AveragerPairWeighted.h"
     
    3332namespace theplu {
    3433namespace yat {
    35 
    3634namespace statistics {
    3735
    38   ///
    39   /// Provides a "label" for
    40   /// the Pearson distance measure.
    41   ///
    42   struct pearson_distance_tag
    43     : public distance_tag
     36  struct PearsonDistance
    4437  {
    45     /// \brief tag for pearson distance
    46     typedef pearson_distance_tag distance;
     38    template <typename Iter1, typename Iter2>
     39    double operator()
     40    (Iter1 beg1,Iter1 end1, Iter2 beg2) const
     41    {
     42      return this->distance(beg1, end1, beg2, 
     43                      typename utility::weighted_if_any2<Iter1,Iter2>::type());
     44    }
     45
     46  private:
     47    template <typename Iter1, typename Iter2>
     48    double distance (Iter1 beg1,Iter1 end1, Iter2 beg2,
     49                     utility::unweighted_type) const
     50    {
     51      AveragerPairWeighted ap;
     52      add(ap,beg1,end1,beg2);
     53      return 1-ap.correlation();
     54    }
     55
     56    template <typename Iter1, typename Iter2>
     57    double distance (Iter1 beg1,Iter1 end1, Iter2 beg2,
     58                     utility::weighted_type) const
     59    {
     60      AveragerPairWeighted ap;
     61      add(ap,beg1,end1,beg2);
     62      return 1-ap.correlation();
     63    }
     64   
    4765  };
    4866
    49 
    50   ///
    51   /// implementation for distances between vectors
    52   /// (containers with random access iterators) using a Pearson
    53   /// distance measure and iterators to unweighted containers.
    54   ///
    55   template <class Iter>
    56   double distance(Iter beg1,Iter end1, Iter beg2,
    57                          const pearson_distance_tag& disttype,
    58                          utility::unweighted_type)
    59   {
    60     AveragerPair ap;
    61     add(ap,beg1,end1,beg2);
    62     return 1-ap.correlation();
    63   }
    64  
    65   ///
    66   /// implementation for distances between vectors
    67   /// (containers with random access iterators) using a Pearson
    68   /// distance measure and iterators to unweighted containers.
    69   ///
    70   template <class Iter>
    71   double distance(Iter beg1,Iter end1, Iter beg2,
    72                          const pearson_distance_tag& disttype,
    73                          utility::weighted_type)
    74   {
    75     AveragerPairWeighted ap;
    76     add(ap,beg1,end1,beg2);
    77     return 1-ap.correlation();
    78   }
    79 
    80  
    8167}}} // of namespace statistics, yat, and theplu
    8268   
Note: See TracChangeset for help on using the changeset viewer.