Changeset 1050 for trunk/yat


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

Simplifying distance structure

Location:
trunk/yat
Files:
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/classifier/IGP.h

    r1031 r1050  
    3030#include "yat/utility/vector.h"
    3131#include "yat/utility/yat_assert.h"
    32 #include "yat/statistics/distance.h"
    3332
    3433#include <cmath>
     
    7170  private:
    7271    utility::vector igp_;
     72    Distance distance_;
    7373
    7474    const MatrixLookup& matrix_;
     
    9494      for(u_int j=0; j<target_.size(); j++) {           
    9595        DataLookup1D b(matrix_,j,false);
    96         double dist=statistics::
    97           distance(a.begin,a.end(),b.begin(),
    98                           statistics::distance_traits<Distance>::distace());
     96        double dist=distance_(a.begin, a.end(), b.begin());
    9997        if(j!=i && dist<mindist) {
    10098          mindist=dist;
  • trunk/yat/classifier/KNN.h

    r1042 r1050  
    2525*/
    2626
     27#include "DataLookup1D.h"
    2728#include "DataLookupWeighted1D.h"
    2829#include "MatrixLookup.h"
     
    3031#include "SupervisedClassifier.h"
    3132#include "Target.h"
    32 #include "yat/statistics/distance.h"
    3333#include "yat/utility/matrix.h"
    3434#include "yat/utility/yat_assert.h"
     
    113113    u_int k_;
    114114
     115    Distance distance_;
    115116    ///
    116117    /// Calculates the distances between a data set and the training
     
    156157        for(size_t j=0; j<test.columns(); j++) {
    157158          classifier::DataLookup1D test(*test_unweighted,j,false);
    158           (*distances)(i,j) =
    159             statistics::distance(classifier::DataLookup1D(data_,
    160                                                           i,false).begin(),
    161                                  classifier::DataLookup1D(data_,
    162                                                           i,false).end(),
    163                                  test.begin(),
    164                                  typename statistics::
    165                                  distance_traits<Distance>::distance());
     159          classifier::DataLookup1D tmp(data_,i,false);
     160          (*distances)(i,j) = distance_(tmp.begin(), tmp.end(), test.begin());
    166161          utility::yat_assert<std::runtime_error>(!std::isnan((*distances)(i,j)));
    167162        }
     
    180175            classifier::DataLookupWeighted1D test(*test_weighted,j,false);
    181176            utility::yat_assert<std::runtime_error>(training.size()==test.size());
    182             (*distances)(i,j) =
    183               statistics::distance(training.begin(),training.end(),
    184                                    test.begin(), typename statistics::distance_traits<Distance>::distance());
     177            (*distances)(i,j) = distance_(training.begin(), training.end(),
     178                                          test.begin());
    185179            utility::yat_assert<std::runtime_error>(!std::isnan((*distances)(i,j)));
    186180          }
  • trunk/yat/classifier/NCC.h

    r1042 r1050  
    3737#include "yat/statistics/Averager.h"
    3838#include "yat/statistics/AveragerWeighted.h"
    39 #include "yat/statistics/distance.h"
    40 
    4139#include "yat/utility/Iterator.h"
    4240#include "yat/utility/IteratorWeighted.h"
     
    112110    utility::matrix* centroids_;
    113111    bool centroids_nan_;
     112    Distance distance_;
    114113
    115114    // data_ has to be of type DataLookup2D to accomodate both
     
    270269        DataLookup1D centroid(unweighted_centroids,k,false);           
    271270        utility::yat_assert<std::runtime_error>(in.size()==centroid.size());
    272         prediction(k,j)=statistics::
    273           distance(in.begin(),in.end(),centroid.begin(),
    274                    typename statistics::distance_traits<Distance>::distance());
     271        prediction(k,j) = distance_(in.begin(), in.end(), centroid.begin());
    275272      }
    276273    }
     
    287284        DataLookupWeighted1D centroid(weighted_centroids,k,false);
    288285        utility::yat_assert<std::runtime_error>(in.size()==centroid.size());
    289         prediction(k,j)=statistics::
    290           distance(in.begin(),in.end(),centroid.begin(),
    291                    typename statistics::distance_traits<Distance>::distance());
     286        prediction(k,j) = distance_(in.begin(), in.end(), centroid.begin());
    292287      }
    293288    }
  • trunk/yat/statistics/Makefile.am

    r1031 r1050  
    4040include_statistics_HEADERS = AUC.h Averager.h AveragerPair.h \
    4141  AveragerWeighted.h AveragerPairWeighted.h \
    42   distance.h euclidean_distance.h Fisher.h \
     42  euclidean_distance.h Fisher.h \
    4343  FoldChange.h Histogram.h \
    4444  KolmogorovSmirnov.h \
  • trunk/yat/statistics/euclidean_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
     
    2728#include "AveragerPair.h"
    2829#include "AveragerPairWeighted.h"
    29 #include "distance.h"
    3030#include "yat/utility/iterator_traits.h"
    3131
     
    3434namespace theplu {
    3535namespace yat {
    36 
    3736namespace statistics {
    3837
    39   ///
    40   /// Provides a "label" for
    41   /// the Euclidean distance measure.
    42   ///
    43   struct euclidean_distance_tag
    44     : public distance_tag
     38  struct EuclideanDistance
    4539  {
    46     /// \brief tag for euclidean distance
    47     typedef euclidean_distance_tag distance;
     40    template <typename Iter1, typename Iter2>
     41    double operator()
     42    (Iter1 beg1,Iter1 end1, Iter2 beg2) const
     43    {
     44      return this->distance(beg1, end1, beg2, 
     45                      typename utility::weighted_if_any2<Iter1,Iter2>::type());
     46    }
     47
     48  private:
     49    template <typename Iter1, typename Iter2>
     50    double distance (Iter1 beg1,Iter1 end1, Iter2 beg2,
     51                     utility::unweighted_type) const
     52    {
     53      AveragerPair ap;
     54      add(ap,beg1,end1,beg2);
     55      return sqrt(ap.sum_squared_deviation());
     56    }
     57
     58    template <typename Iter1, typename Iter2>
     59    double distance (Iter1 beg1,Iter1 end1, Iter2 beg2,
     60                     utility::weighted_type) const
     61    {
     62      AveragerPairWeighted ap;
     63      add(ap,beg1,end1,beg2);
     64      return sqrt(std::distance(beg1,end1)*ap.msd());
     65    }
     66   
    4867  };
    4968
    50 
    51   ///
    52   /// implementation for distances between vectors
    53   /// (containers with random access iterators) using a Euclidean
    54   /// distance measure and iterators to unweighted containers.
    55   ///
    56   template <typename Iter1, typename Iter2>
    57   double distance(Iter1 beg1,Iter1 end1, Iter2 beg2,
    58                          const euclidean_distance_tag& disttype,
    59                          utility::unweighted_type)
    60   {
    61     AveragerPair ap;
    62     add(ap,beg1,end1,beg2);
    63     return sqrt(ap.sum_squared_deviation());
    64   }
    65  
    66 
    67   ///
    68   /// implementation for distances between vectors
    69   /// (containers with random access iterators) using a Euclidean
    70   /// distance measure and iterators to weighted containers.
    71   ///
    72   template <typename Iter1, typename Iter2>
    73   double distance(Iter1 beg1, Iter1 end1, Iter2 beg2,
    74                          const euclidean_distance_tag& disttype,
    75                          utility::weighted_type)
    76   {
    77     AveragerPairWeighted ap;
    78     add(ap,beg1,end1,beg2);
    79     return sqrt(std::distance(beg1,end1)*ap.msd());
    80   }
    81 
    82  
    8369}}} // of namespace statistics, yat, and theplu
    8470   
  • 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   
  • trunk/yat/utility/SmartPtr.h

    r1048 r1050  
    3939    /**
    4040       \brief Constructor
     41
     42       \param p underlying pointer
     43       \param owner if true SmartPtr will be owner of pointer and if
     44       there is no more owner delete it in destructor.
     45
     46       Never use this constructor to create two SmartPtr to the same
     47       pointer such as
     48       \code
     49       MyClass* my_pointer = new MyClass;
     50       SmartPtr<MyClass> sp(my_pointer);
     51       SmartPtr<MyClass> sp2(my_pointer); // this is evil
     52       \endcode
     53       since this will cause multiple deletion. Instead use copy constructor
     54       \code
     55       MyClass* my_pointer = new MyClass;
     56       SmartPtr<MyClass> sp(my_pointer);
     57       SmartPtr<MyClass> sp2(sp);
     58       \endcode
     59       so the internal reference counter is updated.
    4160    */
    4261    explicit SmartPtr(T* p=NULL, bool owner=true)
Note: See TracChangeset for help on using the changeset viewer.