Changeset 1088 for trunk/yat


Ignore:
Timestamp:
Feb 14, 2008, 3:26:19 PM (14 years ago)
Author:
Peter
Message:

Closes #247. Removed IteratorWeighted? iterators over weighted container instead can use Iterator with a special Policy.

Location:
trunk/yat
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/classifier/DataLookup2D.cc

    r1000 r1088  
    123123
    124124
     125  double DataLookup2D::data(size_t i, size_t j) const
     126  {
     127    return (*this)(i,j);
     128  }
     129
     130
    125131  size_t DataLookup2D::rows(void) const
    126132  {
    127133    return row_index_.size();
     134  }
     135
     136
     137  double DataLookup2D::weight(size_t i, size_t j) const
     138  {
     139    return 1.0;
    128140  }
    129141
  • trunk/yat/classifier/DataLookup2D.h

    r1000 r1088  
    110110    size_t columns(void) const;
    111111
     112   
     113    /**
     114       \return data
     115    */
     116    virtual double data(size_t i, size_t j) const;
     117   
    112118    ///
    113119    /// @return number of rows
     
    139145                    const std::vector<size_t>& val) const=0;
    140146
     147    /**
     148       \return data
     149    */
     150    virtual double weight(size_t i, size_t j) const;
     151   
    141152    ///
    142153    /// Is lookup weighted?
  • trunk/yat/classifier/DataLookupWeighted1D.cc

    r1000 r1088  
    6969  DataLookupWeighted1D::const_iterator DataLookupWeighted1D::begin(void) const
    7070  {
    71     return DataLookupWeighted1D::const_iterator(*this, 0);
     71    if (column_vector_)
     72      return const_iterator(const_iterator::iterator_type(*matrix_, 0, index_),
     73                            matrix_->columns());
     74    return const_iterator(const_iterator::iterator_type(*matrix_, index_, 0),1);
    7275  }
    7376
     
    8184  DataLookupWeighted1D::const_iterator DataLookupWeighted1D::end(void) const
    8285  {
    83     return DataLookupWeighted1D::const_iterator(*this, size());
     86    if (column_vector_)
     87      return const_iterator(const_iterator::iterator_type(*matrix_,
     88                                                          matrix_->rows(),
     89                                                          index_),
     90                            matrix_->columns());
     91    return const_iterator(const_iterator::iterator_type(*matrix_,index_+1,0),1);
    8492  }
    8593
  • trunk/yat/classifier/DataLookupWeighted1D.h

    r1000 r1088  
    2626*/
    2727
    28 #include "yat/utility/IteratorWeighted.h"
     28#include "DataLookup2D.h"
     29#include "yat/utility/Iterator.h"
     30#include "yat/utility/IteratorPolicy.h"
     31#include "yat/utility/StrideIterator.h"
    2932
    3033#include <iostream>
     34#include <utility>
    3135#include <vector>
    3236
     
    4650 
    4751  public:
    48    
    49     /// 'Read Only' Iterator
    50     typedef utility::IteratorWeighted<const double, const classifier::DataLookupWeighted1D>
     52    /// 'Read Only' iterator
     53    typedef utility::StrideIterator<
     54    utility::Iterator<const DataLookup2D, const std::pair<double, double>,
     55                      void, const std::pair<double, double>,
     56                      utility::IteratorPolicyWeighted<const DataLookup2D,
     57                                                      const double,
     58                                                      const double> > >
    5159    const_iterator;
    5260
  • trunk/yat/classifier/EnsembleBuilder.h

    r1087 r1088  
    2727*/
    2828
    29 #include "FeatureSelector.h";
     29#include "FeatureSelector.h"
    3030#include "Sampler.h"
    3131#include "SubsetGenerator.h"
  • trunk/yat/statistics/AveragerPairWeighted.h

    r1043 r1088  
    149149  {
    150150    for ( ; first1 != last1; ++first1, ++first2) {
    151       ap.add(utility::iterator_traits_data(first1),
    152              utility::iterator_traits_data(first2),
    153              utility::iterator_traits_weight(first1),
    154              utility::iterator_traits_weight(first2));
     151      ap.add(utility::iterator_traits<Iter1>().data(first1),
     152             utility::iterator_traits<Iter2>().data(first2),
     153             utility::iterator_traits<Iter1>().weight(first1),
     154             utility::iterator_traits<Iter2>().weight(first2));
    155155    }
    156156  }
  • trunk/yat/statistics/AveragerWeighted.h

    r1043 r1088  
    218218  {
    219219    for ( ; first != last; ++first)
    220       a.add(utility::iterator_traits_data(first),
    221             utility::iterator_traits_weight(first));
     220      a.add(utility::iterator_traits<Iter>().data(first),
     221            utility::iterator_traits<Iter>().weight(first));
    222222  }
    223223
  • trunk/yat/utility/Iterator.h

    r1083 r1088  
    261261    //Iterator& operator=(const Iterator&);
    262262  };
     263
     264  /**
     265     Whether Iterator is weighted is desiced by Policy.
     266   */
     267  template<typename A, typename B, typename C, typename D, typename Policy>
     268  struct weighted_iterator_traits<Iterator<A, B, C, D, Policy> > {
     269    typedef typename Policy::weighted_iterator_type type;
     270  };
     271
     272  template<typename A, typename B, typename C, typename D, typename E>
     273  struct iterator_traits<Iterator<A, B, C, D, E> > {
     274    /**
     275       \return data
     276    */
     277    double data(Iterator<A, B, C, D, E> iter) const
     278    { return iter.data(); }
     279
     280    /**
     281       \return weight
     282    */
     283    double weight(Iterator<A, B, C, D, E> iter) const
     284    { return iter.weight(); }
     285
     286  };
     287
     288
    263289}}} // of namespace utility, yat, and theplu
    264290
  • trunk/yat/utility/Makefile.am

    r1081 r1088  
    3737  Alignment.h ColumnStream.h CommandLine.h \
    3838  Exception.h FileUtil.h Iterator.h IteratorPolicy.h iterator_traits.h \
    39   IteratorWeighted.h kNNI.h matrix.h NNI.h \
     39  kNNI.h matrix.h NNI.h \
    4040  Option.h OptionArg.h OptionFile.h OptionInFile.h OptionOutFile.h \
    4141  OptionHelp.h OptionSwitch.h \
  • trunk/yat/utility/StrideIterator.h

    r1066 r1088  
    4444  struct weighted_iterator_traits<StrideIterator<Iter> > {
    4545    typedef typename weighted_iterator_traits<Iter>::type type;
     46  };
     47
     48  template <class Iter>
     49  struct iterator_traits<StrideIterator<Iter> > {
     50    /**
     51       \return data that is *iter
     52    */
     53    double data(StrideIterator<Iter> iter) const
     54    { iterator_traits<Iter> jojo;
     55      return jojo.data(iter.base()); }
     56
     57    /**
     58       \return 1.0
     59    */
     60    double weight(StrideIterator<Iter> iter) const
     61    { return iterator_traits<Iter>().weight(iter.base()); }
     62
    4663  };
    4764
  • trunk/yat/utility/iterator_traits.h

    r1041 r1088  
    120120
    121121  /**
    122     Function to be used to make compile-time decision how to return
    123     data from an iterator separating two cases: weighted and
    124     unweighted.
     122     \brief traits to make unweighted iterator work in as a weighted
    125123
    126     In this way unweighted iterators can be used in a weighted context.
     124     This class must be implemented for every iterator that can be weighted.
     125
     126     \see StrideIterator and Iterator
    127127   */
    128   // Peter, perhaps these should be templatized, but for now return
    129   // type double is hard coded.
    130128  template <class Iter>
    131   double iterator_traits_data(Iter iter)
    132   { return iterator_traits_data(iter, typename
    133                                 weighted_iterator_traits<Iter>::type()); }
     129  struct iterator_traits {
     130    // Peter, perhaps these should be templatized, but for now return
     131    // type double is hard coded.
     132    /**
     133       \return data that is *iter
     134    */
     135    double data(Iter iter) const
     136    { check_iterator_is_unweighted(iter); return *iter; }
    134137
    135   /**
    136      \return data for weighted iterator
    137    */
    138   template <class Iter>
    139   double iterator_traits_data(Iter i, weighted_type)
    140   { return i.data(); }
     138    /**
     139       \return 1.0
     140    */
     141    double weight(Iter iter) const
     142    { check_iterator_is_unweighted(iter); return 1.0; }
    141143
    142   /**
    143      \return data for unweighted data
    144    */
    145   template <class Iter>
    146   double iterator_traits_data(Iter i, unweighted_type)
    147   { return *i; }
    148 
    149   /**
    150     Function to be used to make compile-time decision how to return
    151     data from an iterator separating two cases: weighted and
    152     unweighted.
    153 
    154     In this way unweighted iterators can be used in a weighted context
    155     and weight will be set to unity.
    156    */
    157   // Peter, perhaps these should be templatized, but for now return
    158   // type double is hard coded.
    159   template <class Iter>
    160   double iterator_traits_weight(Iter iter)
    161   { return iterator_traits_weight(iter, typename
    162                                   weighted_iterator_traits<Iter>::type()); }
    163 
    164   /**
    165      \return weight for weighted iterator
    166    */
    167   template <class Iter>
    168   double iterator_traits_weight(Iter i, weighted_type)
    169   { return i.weight(); }
    170 
    171   /**
    172      \return weight for unweighted iterator
    173    */
    174   template <class Iter>
    175   double iterator_traits_weight(Iter i, unweighted_type)
    176   { return 1.0; }
    177 
     144  };
    178145
    179146}}} // of namespace utility, yat, and theplu
Note: See TracChangeset for help on using the changeset viewer.