Changeset 1170 for trunk/yat/classifier


Ignore:
Timestamp:
Feb 27, 2008, 1:06:55 AM (15 years ago)
Author:
Peter
Message:

removing DataLookup2D closes ticket:243

Location:
trunk/yat/classifier
Files:
2 deleted
9 edited

Legend:

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

    r1146 r1170  
    5959    ///
    6060    /// @param row_vector if true DataLookup1D is looking into a
    61     /// row of DataLookup2D, otherwise looking into a
     61    /// row of MatrixLookup, otherwise looking into a
    6262    /// column. @param index which row/column to look into.
    6363    ///
     
    9696
    9797    ///
    98     /// @brief Destructor deletes underlying DataLookup2D if object is owner
     98    /// @brief Destructor deletes underlying MatrixLookup if object is owner
    9999    ///
    100100    virtual ~DataLookup1D();
  • trunk/yat/classifier/InputRanker.h

    r1085 r1170  
    3636namespace classifier { 
    3737
    38   class DataLookup2D;
    3938  class MatrixLookup;
    4039  class MatrixLookupWeighted;
  • trunk/yat/classifier/KernelLookup.h

    r1167 r1170  
    298298       this was built from.
    299299   
    300        @note Returns a dynamically allocated DataLookup2D, which has
     300       @note Returns a dynamically allocated KernelLookup, which has
    301301       to be deleted by the caller to avoid memory leaks.
    302302    */
  • trunk/yat/classifier/Makefile.am

    r1112 r1170  
    3232  DataLookup1D.cc \
    3333  DataLookupWeighted1D.cc \
    34   DataLookup2D.cc \
    3534  FeatureSelector.cc \
    3635  FeatureSelectorIR.cc \
     
    6362  CrossValidationSampler.h \
    6463  DataLookup1D.h \
    65   DataLookup2D.h \
    6664  DataLookupWeighted1D.h \
    6765  EnsembleBuilder.h \
  • trunk/yat/classifier/MatrixLookup.cc

    r1169 r1170  
    3030#include <cassert>
    3131#include <fstream>
     32#include <vector>
    3233
    3334namespace theplu {
     
    3637
    3738  MatrixLookup::MatrixLookup(const utility::Matrix& data, const bool own)
    38     : DataLookup2D(own), data_(MatrixP(&data, own))
     39    : data_(MatrixP(&data, own))
    3940  {
    4041    column_index_ = utility::Index(data.columns());
    4142    row_index_ = utility::Index(data.rows());
     43    assert(rows()==data.rows());
     44    assert(columns()==data.columns());
     45    assert(validate());
    4246  }
    4347 
     
    4751                             const utility::Index& row,
    4852                             const utility::Index& col)
    49     : DataLookup2D(row,col), data_(MatrixP(&data, false))
    50   {
     53    : column_index_(col),
     54      data_(MatrixP(&data, false)),
     55      row_index_(row)
     56
     57  {
     58    assert(rows()==row.size());
     59    assert(columns()==col.size());
     60    assert(validate());
    5161  }
    5262 
     
    5666                             const utility::Index& index,
    5767                             const bool row)
    58     : DataLookup2D(), data_(MatrixP(&data, false))
     68    : data_(MatrixP(&data, false))
    5969  {
    6070    if (row){
     
    6676      row_index_ = utility::Index(data.rows());
    6777    }
     78    assert(row || rows()==data.rows());
     79    assert(row || columns()==index.size());
     80    assert(!row || rows()==index.size());
     81    assert(!row || columns()==data.columns());
     82    assert(validate());
    6883  }
    6984 
     
    7186
    7287  MatrixLookup::MatrixLookup(const MatrixLookup& other)
    73     : DataLookup2D(other), data_(other.data_)
    74   {
     88    : column_index_(other.column_index_),
     89      data_(other.data_),
     90      row_index_(other.row_index_)
     91  {
     92    assert(validate());
    7593  }
    7694
     
    8098                             const utility::Index& row,
    8199                             const utility::Index& col)
    82     : DataLookup2D(other,row,col), data_(other.data_)
    83   {
     100    : column_index_(utility::Index(other.column_index_, col)),
     101      data_(other.data_), row_index_(utility::Index(other.row_index_, row))
     102  {
     103    assert(rows()==row.size());
     104    assert(columns()==col.size());
     105    assert(validate());
    84106  }
    85107 
     
    88110  MatrixLookup::MatrixLookup(const MatrixLookup& other,
    89111                             const utility::Index& index, bool row)
    90     : DataLookup2D(other,index,row), data_(other.data_)
    91   {
     112    : data_(other.data_)
     113  {
     114    if (row){
     115      row_index_ = utility::Index(other.row_index_, index);
     116      column_index_= other.column_index_;
     117    }
     118    else{
     119      column_index_ = utility::Index(other.column_index_, index);
     120      row_index_= other.row_index_;
     121    }
     122    assert(validate());
    92123  }
    93124 
     
    96127  MatrixLookup::MatrixLookup(const size_t rows, const size_t columns,
    97128                             const double value)
    98     : DataLookup2D(rows,columns)
    99   {
    100     data_ = MatrixP(new utility::Matrix(1,1,value));
     129    : data_(MatrixP(new utility::Matrix(1,1,value)))
     130  {   
     131    column_index_ = utility::Index(std::vector<size_t>(columns, 0));
     132    row_index_ = utility::Index(std::vector<size_t>(rows,0));
     133    assert(validate());
    101134  }
    102135
    103136
    104137  MatrixLookup::MatrixLookup(std::istream& is, char sep)
    105     : DataLookup2D()
    106   {
    107     data_ = MatrixP(new utility::Matrix(is,sep));
     138    : data_(MatrixP(new utility::Matrix(is,sep)))
     139  {
     140    column_index_ = utility::Index(data_->columns());
    108141    row_index_ = utility::Index(data_->rows());
    109     column_index_ = utility::Index(data_->columns());
     142    assert(validate());
    110143  }
    111144
     
    133166  {
    134167    return const_row_iterator(const_row_iterator::iterator_type(*this,i,0), 1);
     168  }
     169
     170
     171  size_t MatrixLookup::columns(void) const
     172  {
     173    return column_index_.size();
    135174  }
    136175
     
    157196
    158197
     198  size_t MatrixLookup::rows(void) const
     199  {
     200    return row_index_.size();
     201  }
     202
     203
     204  bool MatrixLookup::validate(void) const
     205  {
     206    for (size_t i=0; i<row_index_.size(); ++i)
     207      if (row_index_[i]>=data_->rows())
     208        return false;
     209    for (size_t i=0; i<column_index_.size(); ++i)
     210      if (column_index_[i]>=data_->columns())
     211        return false;
     212    return true;
     213  }
     214
     215
    159216  bool MatrixLookup::weighted(void) const
    160217  {
     
    168225    assert(row<rows());
    169226    assert(column<columns());
     227    assert(row_index_[row]<data_->rows());
     228    assert(column_index_[column]<data_->columns());
    170229    return (*data_)(row_index_[row], column_index_[column]);
    171230  }
     
    176235  {
    177236    if (this!=&other){
    178       DataLookup2D::operator=(other);
     237      row_index_ = other.row_index_;
     238      column_index_ = other.column_index_;
    179239      data_ = other.data_;
    180240    }
     241    assert(validate());
    181242    return *this;
    182243  }
  • trunk/yat/classifier/MatrixLookup.h

    r1169 r1170  
    2727*/
    2828
    29 #include "DataLookup2D.h"
    3029#include "yat/utility/Container2DIterator.h"
    3130#include "yat/utility/Index.h"
     
    7271  /// constructors and assignments.
    7372  ///
    74   class MatrixLookup : public DataLookup2D
     73  class MatrixLookup
    7574  {
    7675  public:
     
    257256
    258257    /**
     258       \return number of columns
     259    */
     260    size_t columns(void) const;
     261
     262    /**
    259263       \return const_iterator pointing to end of matrix
    260264     */
     
    270274     */
    271275    const_row_iterator end_row(size_t) const;
     276
     277    /**
     278       \return number of rows
     279    */
     280    size_t rows(void) const;
    272281
    273282    ///
     
    296305    friend class MatrixLookupWeighted;
    297306
     307    utility::Index column_index_;
    298308    typedef utility::SmartPtr<const utility::Matrix> MatrixP;
    299309    MatrixP data_;
     310    utility::Index row_index_;
     311
     312    // for assertions
     313    bool validate(void) const;
    300314  }; 
    301315 
    302316  ///
    303   /// The output operator DataLookup2D
     317  /// The output operator MatrixLookup
    304318  ///
    305319  std::ostream& operator<< (std::ostream& s, const MatrixLookup&);
  • trunk/yat/classifier/MatrixLookupWeighted.cc

    r1169 r1170  
    2727#include "yat/utility/Matrix.h"
    2828
    29 #include <algorithm>
    3029#include <cassert>
    3130#include <fstream>
     31#include <vector>
    3232
    3333namespace theplu {
     
    4444    row_index_ = utility::Index(data.rows());
    4545    column_index_ = utility::Index(data.columns());
     46    assert(validate());
    4647  }
    4748
    4849
    4950  MatrixLookupWeighted::MatrixLookupWeighted(const utility::Matrix& data)
    50     : DataLookup2D(), data_(MatrixP(&data, false))
     51    : data_(MatrixP(&data, false))
    5152  {
    5253    utility::Matrix weights;
     
    5556    row_index_ = utility::Index(data.rows());
    5657    column_index_ = utility::Index(data.columns());
     58    assert(validate());
    5759  }
    5860
    5961
    6062  MatrixLookupWeighted::MatrixLookupWeighted(const MatrixLookup& ml)
    61     : DataLookup2D(ml), data_(ml.data_)
    62   {
    63     weights_= MatrixP(new utility::Matrix(data_->rows(), data_->columns(),1.0));
     63    : column_index_(ml.column_index_), data_(ml.data_),
     64      row_index_(ml.row_index_),
     65      weights_(MatrixP(new utility::Matrix(data_->rows(),data_->columns(),1.0)))
     66  {
     67    assert(validate());
    6468  }
    6569 
     
    6973                                             const utility::Index& row,
    7074                                             const utility::Index& col)
    71     : DataLookup2D(row,col), data_(MatrixP(new utility::Matrix(data), false)),
    72       weights_(MatrixP(new utility::Matrix(weights), false))
    73   {
     75    : column_index_(col), data_(MatrixP(new utility::Matrix(data), false)),
     76      row_index_(row), weights_(MatrixP(new utility::Matrix(weights), false))
     77  {
     78    assert(validate());
    7479  }
    7580 
     
    8085                                             const utility::Index& index,
    8186                                             const bool row)
    82     : DataLookup2D(), data_(MatrixP(new utility::Matrix(data), false)),
     87    : data_(MatrixP(new utility::Matrix(data), false)),
    8388      weights_(MatrixP(new utility::Matrix(weights), false))
    8489  {
     
    9398      row_index_ = utility::Index(data.rows());
    9499    }
     100    assert(validate());
    95101  }
    96102 
     
    106112
    107113  MatrixLookupWeighted::MatrixLookupWeighted(const MatrixLookupWeighted& other)
    108     : DataLookup2D(other), data_(other.data_), weights_(other.weights_)
    109   {
     114    : column_index_(other.column_index_), data_(other.data_),
     115      row_index_(other.row_index_), weights_(other.weights_)
     116  {
     117    assert(validate());
    110118  }
    111119
     
    115123                                             const utility::Index& row,
    116124                                             const utility::Index& col)
    117     : DataLookup2D(other,row,col), data_(other.data_), weights_(other.weights_)
    118   {
     125    : column_index_(utility::Index(other.column_index_, col)),
     126      data_(other.data_), row_index_(utility::Index(other.row_index_, row)),
     127      weights_(other.weights_)
     128  {
     129    assert(validate());
    119130  }
    120131 
     
    124135                                             const utility::Index& index,
    125136                                             bool row)
    126     : DataLookup2D(other,index,row), data_(other.data_),
     137    : data_(other.data_),
    127138      weights_(other.weights_)
    128139  {
     140    if (row){
     141      row_index_ = utility::Index(other.row_index_, index);
     142      column_index_= other.column_index_;
     143    }
     144    else{
     145      column_index_ = utility::Index(other.column_index_, index);
     146      row_index_= other.row_index_;
     147    }
     148    assert(validate());
    129149  }
    130150 
     
    135155                                             const double value,
    136156                                             const double weight)
    137     : DataLookup2D(rows,columns),
     157    : column_index_(utility::Index(std::vector<size_t>(rows, 0))),
    138158      data_(MatrixP(new utility::Matrix(1,1,value))),
     159      row_index_(utility::Index(std::vector<size_t>(columns, 0))),
    139160      weights_(MatrixP(new utility::Matrix(1,1,weight)))
    140161  {
     162    assert(validate());
    141163  }
    142164
    143165 
    144166  MatrixLookupWeighted::MatrixLookupWeighted(std::istream& is, char sep)
    145     : DataLookup2D()
    146   {
    147     data_ = MatrixP(new utility::Matrix(is,sep));
     167    : data_(MatrixP(new utility::Matrix(is,sep)))
     168  {
     169    column_index_ = utility::Index(data_->columns());
    148170    row_index_ = utility::Index(data_->rows());
    149     column_index_ = utility::Index(data_->columns());
    150171    utility::Matrix weights;
    151172    utility::nan(*data_,weights);
    152173    // Peter, should be possible to avoid this copying
    153174    weights_= MatrixP(new utility::Matrix(weights));
     175    assert(validate());
    154176  }
    155177 
     
    183205
    184206
     207  size_t MatrixLookupWeighted::columns(void) const
     208  {
     209    return column_index_.size();
     210  }
     211
     212
    185213  double MatrixLookupWeighted::data(size_t row, size_t column) const
    186214  {
     215    assert(row<rows());
     216    assert(column<columns());
     217    assert(row_index_[row]<data_->rows());
     218    assert(column_index_[column]<data_->columns());
    187219    return (*data_)(row_index_[row], column_index_[column]);
    188220  }
     
    212244
    213245
     246  size_t MatrixLookupWeighted::rows(void) const
     247  {
     248    return row_index_.size();
     249  }
     250
     251
     252  bool MatrixLookupWeighted::validate(void) const
     253  {
     254    for (size_t i=0; i<row_index_.size(); ++i)
     255      if (row_index_[i]>=data_->rows())
     256        return false;
     257    for (size_t i=0; i<column_index_.size(); ++i)
     258      if (column_index_[i]>=data_->columns())
     259        return false;
     260    for (size_t i=0; i<row_index_.size(); ++i)
     261      if (row_index_[i]>=weights_->rows())
     262        return false;
     263    for (size_t i=0; i<column_index_.size(); ++i)
     264      if (column_index_[i]>=weights_->columns())
     265        return false;
     266    return true;
     267  }
     268
     269
    214270  double MatrixLookupWeighted::weight(size_t row, size_t column) const
    215271  {
     272    assert(row<rows());
     273    assert(column<columns());
     274    assert(row_index_[row]<weights_->rows());
     275    assert(column_index_[column]<weights_->columns());
    216276    return (*weights_)(row_index_[row], column_index_[column]);
    217277  }
     
    238298  {
    239299    if (this!=&other){
    240       DataLookup2D::operator=(other);
     300      column_index_=other.column_index_;
     301      row_index_=other.row_index_;
    241302      data_ = other.data_;
    242303      weights_ = other.weights_;
    243304    }
     305    assert(validate());
    244306    return *this;
    245307  }
  • trunk/yat/classifier/MatrixLookupWeighted.h

    r1169 r1170  
    2626*/
    2727
    28 #include "DataLookup2D.h"
    2928#include "yat/utility/Container2DIterator.h"
     29#include "yat/utility/Index.h"
    3030#include "yat/utility/IteratorPolicy.h"
    3131#include "yat/utility/SmartPtr.h"
     
    6767  /// constructors and assignments.
    6868  ///
    69   class MatrixLookupWeighted : public DataLookup2D
     69  class MatrixLookupWeighted
    7070  {
    7171 
     
    284284    const_row_iterator begin_row(size_t) const;
    285285
     286    /**
     287       \return number of columns
     288    */
     289    size_t columns(void) const;
     290
    286291    ///
    287292    /// @return data value of element (@a row, @a column)
     
    303308     */
    304309    const_row_iterator end_row(size_t) const;
     310
     311    /**
     312       \return number of rows
     313    */
     314    size_t rows(void) const;
    305315
    306316    ///
     
    333343  private:
    334344    typedef utility::SmartPtr<const utility::Matrix> MatrixP;
     345    utility::Index column_index_;
    335346    MatrixP data_;
     347    utility::Index row_index_;
    336348    MatrixP weights_;
     349
     350    // for assertions
     351    bool validate(void) const;
    337352  }; 
    338353 
  • trunk/yat/classifier/SVM.h

    r1125 r1170  
    7474    ///
    7575    virtual ~SVM();
    76 
    77     //const DataLookup2D& data(void) const;
    7876
    7977    ///
Note: See TracChangeset for help on using the changeset viewer.