Changeset 1201 for trunk/yat/classifier


Ignore:
Timestamp:
Mar 5, 2008, 3:56:13 AM (16 years ago)
Author:
Peter
Message:

returning SmartPtr? rather than conventional pointer when object is dynamically allocated - also fixed bug in SubsetGenerator? for Kernel with feature selection

Location:
trunk/yat/classifier
Files:
3 edited

Legend:

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

    r1168 r1201  
    2828
    2929#include <cassert>
    30 #ifndef NDEBUG
    31 #include <algorithm>
    32 #endif
    3330
    3431namespace theplu {
     
    187184
    188185
    189   const KernelLookup*
     186  utility::SmartPtr<const KernelLookup>
    190187  KernelLookup::selected(const utility::Index& inputs) const
    191188  {
     
    203200      kernel = kernel_->make_kernel(*ms,true);
    204201    }
    205     return new KernelLookup(*kernel, true);
    206   }
    207 
    208 
    209   const KernelLookup* KernelLookup::test_kernel(const MatrixLookup& data) const
    210   {
    211 
     202    return utility::SmartPtr<const KernelLookup>
     203      (new KernelLookup(*kernel, true));
     204  }
     205
     206
     207  utility::SmartPtr<const KernelLookup>
     208  KernelLookup::test_kernel(const MatrixLookup& data) const
     209  {
    212210    if (!weighted()){
    213211      assert(data.rows()==kernel_->data().rows());
     
    242240        kernel_->make_kernel(*tmp, true);
    243241
    244       return new KernelLookup(*kernel, utility::Index(row_index),
    245                               utility::Index(column_index), true);
     242      return utility::SmartPtr<const KernelLookup>
     243        (new KernelLookup(*kernel, utility::Index(row_index),
     244                          utility::Index(column_index), true));
    246245    }
    247246
     
    281280                                                         *weight_all, true);
    282281    const Kernel* kernel = kernel_->make_kernel(*tmp, true);
    283     return new KernelLookup(*kernel, row_index_,
    284                             utility::Index(column_index), true);
    285   }
    286 
    287 
    288 
    289   const KernelLookup*
     282
     283
     284    return utility::SmartPtr<const KernelLookup>
     285      (new KernelLookup(*kernel, row_index_,
     286                        utility::Index(column_index), true));
     287  }
     288
     289
     290
     291  utility::SmartPtr<const KernelLookup>
    290292  KernelLookup::test_kernel(const MatrixLookupWeighted& data) const
    291293  {
     
    329331    const Kernel* kernel =
    330332      kernel_->make_kernel(MatrixLookupWeighted(*data_all, *weight_all, true));
    331     return new KernelLookup(*kernel, row_index_,
    332                             utility::Index(column_index), true);
     333    return utility::SmartPtr<const KernelLookup>
     334      (new KernelLookup(*kernel, row_index_,
     335                        utility::Index(column_index), true));
    333336  }
    334337
  • trunk/yat/classifier/KernelLookup.h

    r1170 r1201  
    267267       corresponds to the same pair of samples as in the original
    268268       KernelLookup.
    269 
    270        \note Returns a dynamically allocated KernelLookup, which has
    271        to be deleted by the caller to avoid memory leaks.
    272     */
    273     const KernelLookup* selected(const utility::Index& index) const;
     269    */
     270    utility::SmartPtr<const KernelLookup>
     271    selected(const utility::Index& index) const;
    274272   
     273    /**
     274       This function is useful when predicting on an independent data
     275       set using a kernel-based classifier. In returned KernelLookup
     276       column \f$ i \f$ corresponds to column \f$ i \f$ in @a
     277       data. Row \f$ i \f$ in returned KernelLookup corresponds to
     278       same sample as row \f$ i \f$ in @a this. In other words, this
     279       function returns a KernelLookup containing the kernel elements
     280       between the passed @a data and the internal underlying data @a
     281       this was built from.
     282    */
     283    utility::SmartPtr<const KernelLookup>
     284    test_kernel(const MatrixLookup& data) const;
     285
    275286    /**
    276287       This function is useful when predicting on an independent data
     
    286297       to be deleted by the caller to avoid memory leaks.
    287298    */
    288     const KernelLookup* test_kernel(const MatrixLookup& data) const;
    289 
    290     /**
    291        This function is useful when predicting on an independent data
    292        set using a kernel-based classifier. In returned KernelLookup
    293        column \f$ i \f$ corresponds to column \f$ i \f$ in @a
    294        data. Row \f$ i \f$ in returned KernelLookup corresponds to
    295        same sample as row \f$ i \f$ in @a this. In other words, this
    296        function returns a KernelLookup containing the kernel elements
    297        between the passed @a data and the internal underlying data @a
    298        this was built from.
    299    
    300        @note Returns a dynamically allocated KernelLookup, which has
    301        to be deleted by the caller to avoid memory leaks.
    302     */
    303     const KernelLookup* test_kernel(const MatrixLookupWeighted& data) const;
     299    utility::SmartPtr<const KernelLookup>
     300    test_kernel(const MatrixLookupWeighted& data) const;
    304301
    305302    /**
  • trunk/yat/classifier/SubsetGenerator.h

    r1186 r1201  
    3333#include "Sampler.h"
    3434#include "yat/utility/Index.h"
     35#include "yat/utility/SmartPtr.h"
    3536#include "yat/utility/yat_assert.h"
    3637
     
    278279        }
    279280        features_.push_back(f_selector_->features());
    280         const KernelLookup* kl = kernel.selected(features_.back());
     281        utility::SmartPtr<const KernelLookup> kl =
     282          kernel.selected(features_.back());
    281283        // Dynamically allocated. Must be deleted in destructor.
    282         training_data_.push_back(new KernelLookup(kernel,training_index(k),
     284        training_data_.push_back(new KernelLookup(*kl,training_index(k),
    283285                                                  training_index(k)));
    284         validation_data_.push_back(new KernelLookup(kernel, training_index(k),
     286        validation_data_.push_back(new KernelLookup(*kl, training_index(k),
    285287                                                    validation_index(k)));
    286         utility::yat_assert<std::runtime_error>(kl);
    287         delete kl;
    288288      }
    289289      else {// no feature selection
Note: See TracChangeset for help on using the changeset viewer.