Changeset 1127 for trunk/yat


Ignore:
Timestamp:
Feb 22, 2008, 11:46:59 PM (13 years ago)
Author:
Peter
Message:

undoing [1126] which did not compile. forgot to run make check. sorry for any...

Location:
trunk/yat
Files:
4 edited

Legend:

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

    r1126 r1127  
    2929
    3030#include <cassert>
     31#ifndef NDEBUG
     32#include <algorithm>
     33#endif
    3134
    3235namespace theplu {
     
    3538
    3639  KernelLookup::KernelLookup(const Kernel& kernel, const bool own)
    37     : column_index_(utility::Index(kernel.size())),
    38       kernel_(utility::SmartPtr<const Kernel>(&kernel, own)),
    39       row_index_(utility::Index(kernel.size()))
    40   {
     40    : DataLookup2D(own), kernel_(&kernel)
     41  {
     42    column_index_.reserve(kernel.size());
     43    for(size_t i=0; i<kernel.size(); i++)
     44      column_index_.push_back(i);
     45    row_index_=column_index_;
    4146  }
    4247
    4348
    4449  KernelLookup::KernelLookup(const Kernel& kernel,
    45                              const utility::Index& row,
    46                              const utility::Index& column,
     50                             const std::vector<size_t>& row,
     51                             const std::vector<size_t>& column,
    4752                             const bool owner)
    48     : column_index_(column),
    49       kernel_(utility::SmartPtr<const Kernel>(&kernel, false)),
    50       row_index_(row)
    51   {
     53    : DataLookup2D(row,column,owner), kernel_(&kernel)
     54  {
     55    // Checking that each row index is less than kernel.rows()
     56    assert(row.empty() ||
     57           *(std::max_element(row.begin(),row.end()))<kernel_->size());
     58    // Checking that each column index is less than kernel.column()
     59    assert(column.empty() ||
     60           *(std::max_element(column.begin(),column.end()))<kernel_->size());
    5261  }
    5362
    5463
    5564  KernelLookup::KernelLookup(const KernelLookup& other,
    56                              const utility::Index& row,
    57                              const utility::Index& column)
    58     : column_index_(utility::Index(other.column_index_, column)),
    59       kernel_(other.kernel_),
    60       row_index_(utility::Index(other.row_index_, row))
    61   {
     65                             const std::vector<size_t>& row,
     66                             const std::vector<size_t>& column)
     67    : DataLookup2D(other,row,column), kernel_(other.kernel_)
     68  {
     69    ref_count_=other.ref_count_;
     70    if (ref_count_)
     71      ++(*ref_count_);
    6272  }
    6373 
    6474
    6575  KernelLookup::KernelLookup(const KernelLookup& other)
    66     : column_index_(other.column_index_),
    67       kernel_(other.kernel_),
    68       row_index_(other.row_index_)
    69   {
     76    : DataLookup2D(other), kernel_(other.kernel_)
     77  {
     78    // Checking that no index is out of range
     79    assert(row_index_.empty() ||
     80           *(max_element(row_index_.begin(), row_index_.end()))<
     81           kernel_->size());
     82    assert(column_index_.empty() ||
     83           *(max_element(column_index_.begin(), column_index_.end()))<
     84           kernel_->size());
     85    ref_count_=other.ref_count_;
     86    if (ref_count_)
     87      ++(*ref_count_);
    7088  }
    7189 
    7290
    7391  KernelLookup::KernelLookup(const KernelLookup& other,
    74                              const utility::Index& index,
     92                             const std::vector<size_t>& index,
    7593                             const bool row)
    76     : kernel_(other.kernel_)
    77   {
    78     if (row) {
    79       row_index_ = utility::Index(other.row_index_, index);
    80       column_index_ = other.column_index_;
    81     }
    82     else {
    83       row_index_ = other.row_index_;
    84       column_index_ = utility::Index(other.column_index_, index);
    85     }
     94    : DataLookup2D(other,index,row), kernel_(other.kernel_)
     95  {
     96    assert(kernel_->size());
     97
     98    // Checking that no index is out of range
     99    assert(row_index_.empty() ||
     100           *(max_element(row_index_.begin(), row_index_.end()))<
     101           kernel_->size());
     102    assert(column_index_.empty() ||
     103           *(max_element(column_index_.begin(), column_index_.end()))<
     104           kernel_->size());
     105    ref_count_=other.ref_count_;
     106    if (ref_count_)
     107      ++(*ref_count_);
    86108  }
    87109 
     
    89111  KernelLookup::~KernelLookup(void)
    90112  {
     113    if (ref_count_)
     114      if (!--(*ref_count_))
     115        delete kernel_;
    91116  }
    92117
     
    113138
    114139
    115   size_t KernelLookup::columns(void) const
    116   {
    117     return column_index_.size();
    118   }
    119 
    120 
    121140  const DataLookup2D* KernelLookup::data(void) const
    122141  {
    123     return kernel_->data().training_data(column_index_.vector());
     142    return kernel_->data().training_data(column_index_);
    124143  }
    125144
     
    157176
    158177
    159   size_t KernelLookup::rows(void) const
    160   {
    161     return row_index_.size();
    162   }
    163 
    164 
    165178  const KernelLookup*
    166   KernelLookup::selected(const utility::Index& inputs) const
     179  KernelLookup::selected(const std::vector<size_t>& inputs) const
    167180  {
    168181    const Kernel* kernel;
     
    172185      assert(ml);
    173186      const MatrixLookupWeighted* ms =
    174         new MatrixLookupWeighted(*ml,inputs.vector(),true);
     187        new MatrixLookupWeighted(*ml,inputs,true);
    175188      kernel = kernel_->make_kernel(*ms, false);
    176189    }
     
    180193      assert(m);
    181194      // matrix with selected features
    182       const MatrixLookup* ms = new MatrixLookup(*m,inputs.vector(),true);
     195      const MatrixLookup* ms = new MatrixLookup(*m,inputs,true);
    183196      kernel = kernel_->make_kernel(*ms,true);
    184197    }
     
    222235        kernel_->make_kernel(*tmp, true);
    223236
    224       return new KernelLookup(*kernel, utility::Index(row_index),
    225                               utility::Index(column_index), true);
     237      return new KernelLookup(*kernel, row_index, column_index, true);
    226238    }
    227239
     
    261273                                                         *weight_all, true);
    262274    const Kernel* kernel = kernel_->make_kernel(*tmp, true);
    263     return new KernelLookup(*kernel, row_index_, utility::Index(column_index),
    264                             true);
     275    return new KernelLookup(*kernel, row_index_, column_index, true);
    265276  }
    266277
     
    312323    const Kernel* kernel =
    313324      kernel_->make_kernel(MatrixLookupWeighted(*data_all, *weight_all, true));
    314     return new KernelLookup(*kernel, row_index_, utility::Index(column_index),
    315                             true);
     325    return new KernelLookup(*kernel, row_index_, column_index, true);
    316326  }
    317327
     
    320330  KernelLookup::training_data(const std::vector<size_t>& train) const
    321331  {
    322     return new KernelLookup(*this,utility::Index(train),utility::Index(train));
     332    return new KernelLookup(*this,train,train);
    323333  }
    324334
     
    328338                                const std::vector<size_t>& validation) const
    329339  {
    330     return new KernelLookup(*this,utility::Index(train),
    331                             utility::Index(validation));
     340    return new KernelLookup(*this,train,validation);
    332341  }
    333342
  • trunk/yat/classifier/KernelLookup.h

    r1126 r1127  
    3131#include "MatrixLookup.h"
    3232#include "yat/utility/Container2DIterator.h"
    33 #include "yat/utility/Index.h"
    3433#include "yat/utility/iterator_traits.h"
    35 #include "yat/utility/SmartPtr.h"
    3634#include "yat/utility/StrideIterator.h"
     35
     36
     37#include <vector>
    3738
    3839namespace theplu {
    3940namespace yat {
    40   namespace utility{
    41     class Index;
    42   }
    4341namespace classifier {
    4442
     
    6866  /// constructors and assignments.
    6967  ///
    70   class KernelLookup
     68  class KernelLookup : public DataLookup2D
    7169  {
    7270
     
    118116    /// undefined.
    119117    ///
    120     /// @note For training usage row Index shall always be equal to
    121     /// column Index.
    122     ///
    123     KernelLookup(const Kernel& kernel, const utility::Index& row,
    124                  const utility::Index& column, const bool owner=false);
     118    /// @note For training usage row index shall always be equal to
     119    /// column index.
     120    ///
     121    KernelLookup(const Kernel& kernel, const std::vector<size_t>& row,
     122                 const std::vector<size_t>& column, const bool owner=false);
    125123
    126124    ///
     
    140138    ///
    141139    /// Contructor building a sub-KernelLookup from a KernelLookup
    142     /// defined by row index and column index. In the
     140    /// defined by row index vector and column index vector. In the
    143141    /// created Lookup the element in the \f$ i \f$ th row in the
    144142    /// \f$ j \f$ th column is identical to the element in row row[i] and
     
    153151    /// column index.
    154152    ///
    155     KernelLookup(const KernelLookup& kl, const utility::Index& row,
    156                  const utility::Index& column);
    157 
    158     ///
    159     /// Constructor taking the column (default) or row Index as
     153    KernelLookup(const KernelLookup& kl, const std::vector<size_t>& row,
     154                 const std::vector<size_t>& column);
     155
     156    ///
     157    /// Constructor taking the column (default) or row index vector as
    160158    /// input. If @a row is false the created KernelLookup will have
    161159    /// equally many rows as @a kernel.
     
    168166    /// undefined.
    169167    ///
    170     KernelLookup(const KernelLookup& kernel, const utility::Index&,
     168    KernelLookup(const KernelLookup& kernel, const std::vector<size_t>&,
    171169                 const bool row=false);
    172170
     
    200198     */
    201199    const_row_iterator begin_row(size_t) const;
    202 
    203     /**
    204        \return Number of columns
    205     */
    206     size_t columns(void) const;
    207200
    208201    ///
     
    252245
    253246    /**
    254        \return Number of columns
    255     */
    256     size_t rows(void) const;
    257 
    258     /**
    259247       Each element in returned KernelLookup is calculated using only
    260248       selected features (defined by @a index). Each element
     
    265253       to be deleted by the caller to avoid memory leaks.
    266254    */
    267     const KernelLookup* selected(const utility::Index& index) const;
     255    const KernelLookup* selected(const std::vector<size_t>& index) const;
    268256   
    269257    /**
     
    338326    const KernelLookup& operator=(const KernelLookup&);
    339327
    340     utility::Index column_index_;
    341     utility::SmartPtr<const Kernel> kernel_;
    342     utility::Index row_index_;
     328    const Kernel* kernel_;
    343329   
    344330  }; // class KernelLookup
  • trunk/yat/utility/Index.cc

    r1126 r1127  
    4747
    4848
    49   Index::Index(const std::vector<size_t>& vec)
    50     : index_(SmartPtr<const std::vector<size_t> >(new std::vector<size_t>(vec)))
    51   {}
    52 
    53 
    5449  Index::Index(const Index& a, const Index& b)
    5550  {
     
    6863
    6964
    70   const std::vector<size_t>& Index::vector(void) const
    71   {
    72     return *index_;
    73   }
    74 
    75 
    7665  const size_t& Index::operator[](size_t i) const
    7766  {
  • trunk/yat/utility/Index.h

    r1126 r1127  
    6363
    6464    /**
    65        \brief Constructor
    66 
    67        \a vec is copied
    68      */
    69     explicit Index(const std::vector<size_t>& vec);
     65       \brief access operator
     66    */
     67    const size_t& operator[](size_t) const;
    7068
    7169    /**
     
    7371    */
    7472    size_t size(void) const;
    75 
    76     /**
    77        \brief underlying std::vector
    78     */
    79     const std::vector<size_t>& vector(void) const;
    80 
    81     /**
    82        \brief access operator
    83     */
    84     const size_t& operator[](size_t) const;
    8573
    8674  private:
Note: See TracChangeset for help on using the changeset viewer.