Changeset 1167 for trunk/yat/classifier


Ignore:
Timestamp:
Feb 26, 2008, 9:02:28 PM (13 years ago)
Author:
Peter
Message:

refs #342 in KernelLookup? and DataLookup2D - nothing changed in MatrixLookups?

Location:
trunk/yat/classifier
Files:
5 edited

Legend:

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

    r1134 r1167  
    123123    size_t rows(void) const;
    124124
    125     ///
    126     /// @return Data based on selected features.
    127     ///
    128     virtual const DataLookup2D* selected(const utility::Index&) const=0;
    129 
    130     ///
    131     /// @return sub-Lookup of the DataLookup2D
    132     ///
    133     /// @note Returns a dynamically allocated DataLookup2D, which has
    134     /// to be deleted by the caller to avoid memory leaks.
    135     ///
    136     virtual const DataLookup2D*
    137     training_data(const utility::Index&) const=0;
    138 
    139     ///
    140     /// @return sub-Lookup of the DataLookup2D
    141     ///
    142     /// @note Returns a dynamically allocated DataLookup2D, which has
    143     /// to be deleted by the caller to avoid memory leaks.
    144     ///
    145     virtual const DataLookup2D*
    146     validation_data(const utility::Index& train,
    147                     const utility::Index& val) const=0;
    148 
    149125    /**
    150126       \return data
  • trunk/yat/classifier/KernelLookup.cc

    r1165 r1167  
    2323
    2424#include "KernelLookup.h"
    25 #include "DataLookup2D.h"
    2625#include "MatrixLookup.h"
    2726#include "MatrixLookupWeighted.h"
     
    335334
    336335
     336  /*
    337337  const KernelLookup*
    338338  KernelLookup::training_data(const utility::Index& train) const
     
    340340    return new KernelLookup(*this,train,train);
    341341  }
     342  */
    342343
    343344
     
    351352
    352353
    353   const KernelLookup*
    354   KernelLookup::validation_data(const utility::Index& train,
    355                                 const utility::Index& validation) const
    356   {
    357     return new KernelLookup(*this,train,validation);
    358   }
    359 
    360 
    361354  bool KernelLookup::weighted(void) const
    362355  {
  • trunk/yat/classifier/KernelLookup.h

    r1165 r1167  
    304304
    305305    /**
    306        \brief Creates a sub-Kernel identical to the one created using
    307        KernelLookup(*this, train, train).
    308    
    309        \return pointer to dynamically allocated sub-Lookup of the
    310        KernelLookup
    311    
    312        \note Returns a dynamically allocated DataLookup2D, which has
    313        to be deleted by the caller to avoid memory leaks.
    314     */
    315     const KernelLookup* training_data(const utility::Index& train) const;
    316 
    317     /**
    318        In returned kernel each row corresponds to a training sample
    319        and each column corresponds to a validation sample. The created
    320        sub-KernelLookup is equivalent to using KernelLooup(*this,
    321        train, validation).
    322    
    323        \return sub-Lookup of the DataLookup2D
    324    
    325        \note Returns a dynamically allocated DataLookup2D, which has
    326        to be deleted by the caller to avoid memory leaks.
    327     */
    328     const KernelLookup*
    329     validation_data(const utility::Index& train,
    330                     const utility::Index& validation) const;
    331 
    332     /**
    333306       \return true if underlying Kernel is weighted
    334307    */
  • trunk/yat/classifier/SVindex.cc

    r1121 r1167  
    2323
    2424#include "SVindex.h"
    25 #include "DataLookup2D.h"
    2625#include "yat/random/random.h"
    2726#include "yat/statistics/Averager.h"
  • trunk/yat/classifier/SubsetGenerator.h

    r1165 r1167  
    133133    const Target& validation_target(std::vector<Target>::size_type i) const;
    134134
    135     ///
    136     /// @return true if weighted
    137     /// @todo remove this function
    138     //bool weighted(void) const;
    139 
    140135  private:
    141136    void build(const MatrixLookup&);
     
    168163    training_data_.reserve(sampler_.size());
    169164    validation_data_.reserve(sampler_.size());
    170     for (size_t i=0; i<sampler_.size(); ++i){
    171       // Dynamically allocated. Must be deleted in destructor.
    172       training_data_.push_back(data.training_data(sampler.training_index(i)));
    173       validation_data_.push_back(data.validation_data(sampler.training_index(i),
    174                                                       sampler.validation_index(i)));
    175 
    176       training_target_.push_back(Target(target(),sampler.training_index(i)));
    177       validation_target_.push_back(Target(target(),
    178                                           sampler.validation_index(i)));
    179       utility::yat_assert<std::runtime_error>(training_data_.size()==i+1);
    180       utility::yat_assert<std::runtime_error>(training_target_.size()==i+1);
    181       utility::yat_assert<std::runtime_error>(validation_data_.size()==i+1);
    182       utility::yat_assert<std::runtime_error>(validation_target_.size()==i+1);
    183     }
    184 
    185     // No feature selection, hence features same for all partitions
    186     // and can be stored in features_[0]
    187     features_.push_back(utility::Index(data.rows()));
    188 
     165    build(data);
    189166    utility::yat_assert<std::runtime_error>(training_data_.size()==size());
    190167    utility::yat_assert<std::runtime_error>(training_target_.size()==size());
     
    196173  template<typename T>
    197174  SubsetGenerator<T>::SubsetGenerator(const Sampler& sampler,
    198                                    const T& data,
    199                                    FeatureSelector& fs)
     175                                      const T& data,
     176                                      FeatureSelector& fs)
    200177    : f_selector_(&fs), sampler_(sampler)
    201178  {
     
    229206      training_target_.push_back(Target(target(),training_index(k)));
    230207      validation_target_.push_back(Target(target(),validation_index(k)));
    231       // training data with no feature selection
    232       const MatrixLookup* train_data_all_feat =
    233         ml.training_data(training_index(k));
    234       // use these data to create feature selection
    235       utility::yat_assert<std::runtime_error>(train_data_all_feat);
    236       f_selector_->update(*train_data_all_feat, training_target(k));
     208      if (f_selector_){
     209        // training data with no feature selection
     210        const MatrixLookup* train_data_all_feat =
     211          ml.training_data(training_index(k));
     212        // use these data to create feature selection
     213        utility::yat_assert<std::runtime_error>(train_data_all_feat);
     214        f_selector_->update(*train_data_all_feat, training_target(k));
    237215        // get features
    238       features_.push_back(f_selector_->features());
    239       utility::yat_assert<std::runtime_error>(train_data_all_feat);
    240       delete train_data_all_feat;
     216        features_.push_back(f_selector_->features());
     217        utility::yat_assert<std::runtime_error>(train_data_all_feat);
     218        delete train_data_all_feat;
     219      }
     220      else // no feature selection
     221        features_.push_back(utility::Index(ml.rows()));
     222
    241223     
    242224      // Dynamically allocated. Must be deleted in destructor.
     
    256238      training_target_.push_back(Target(target(),training_index(k)));
    257239      validation_target_.push_back(Target(target(),validation_index(k)));
    258       // training data with no feature selection
    259       const MatrixLookupWeighted* train_data_all_feat =
    260         ml.training_data(training_index(k));
    261       // use these data to create feature selection
    262       f_selector_->update(*train_data_all_feat, training_target(k));
    263       // get features
    264       features_.push_back(f_selector_->features());
    265       delete train_data_all_feat;
    266      
     240      if (f_selector_){
     241        // training data with no feature selection
     242        const MatrixLookupWeighted* train_data_all_feat =
     243          ml.training_data(training_index(k));
     244        // use these data to create feature selection
     245        f_selector_->update(*train_data_all_feat, training_target(k));
     246        // get features
     247        features_.push_back(f_selector_->features());
     248        delete train_data_all_feat;
     249      }
     250      else // no feature selection
     251        features_.push_back(utility::Index(ml.rows()));
     252
     253
    267254      // Dynamically allocated. Must be deleted in destructor.
    268255      training_data_.push_back(new MatrixLookupWeighted(ml, features_.back(),
     
    280267      validation_target_.push_back(Target(target(),validation_index(k)));
    281268
    282       if (kernel.weighted()){
    283         utility::SmartPtr<const MatrixLookupWeighted> ml=kernel.data_weighted();
    284         f_selector_->update(MatrixLookupWeighted(*ml,training_index(k),false),
    285                             training_target(k));
     269      if (f_selector_){
     270        if (kernel.weighted()){
     271          utility::SmartPtr<const MatrixLookupWeighted> ml=
     272            kernel.data_weighted();
     273          f_selector_->update(MatrixLookupWeighted(*ml,training_index(k),false),
     274                              training_target(k));
     275        }
     276        else {
     277          utility::SmartPtr<const MatrixLookup> ml=kernel.data();
     278          f_selector_->update(MatrixLookup(*ml,training_index(k), false),
     279                              training_target(k));
     280        }
     281        features_.push_back(f_selector_->features());
     282        const KernelLookup* kl = kernel.selected(features_.back());
     283        // Dynamically allocated. Must be deleted in destructor.
     284        training_data_.push_back(new KernelLookup(kernel,training_index(k),
     285                                                  training_index(k)));
     286        validation_data_.push_back(new KernelLookup(kernel, training_index(k),
     287                                                    validation_index(k)));
     288        utility::yat_assert<std::runtime_error>(kl);
     289        delete kl;
    286290      }
    287       else {
    288         utility::SmartPtr<const MatrixLookup> ml=kernel.data();
    289         f_selector_->update(MatrixLookup(*ml,training_index(k), false),
    290                             training_target(k));
    291       }
    292       utility::Index dummie=f_selector_->features();
    293       features_.push_back(dummie);
    294       //features_.push_back(f_selector_->features());
    295       const KernelLookup* kl = kernel.selected(features_.back());
     291      else {// no feature selection
     292        training_data_.push_back(new KernelLookup(kernel, training_index(k),
     293                                                  training_index(k)));
     294        validation_data_.push_back(new KernelLookup(kernel,
     295                                                    training_index(k),
     296                                                    validation_index(k)));
     297      }
    296298     
    297       // Dynamically allocated. Must be deleted in destructor.
    298       training_data_.push_back(kl->training_data(training_index(k)));
    299       validation_data_.push_back(kl->validation_data(training_index(k),
    300                                                      validation_index(k)));
    301       utility::yat_assert<std::runtime_error>(kl);
    302       delete kl;
    303299    }
    304300  }
Note: See TracChangeset for help on using the changeset viewer.