Changeset 1163


Ignore:
Timestamp:
Feb 26, 2008, 6:15:43 PM (16 years ago)
Author:
Peter
Message:

replacing DataLookup2D* data_ in Kernel with a MatrixLookup?*. The weighted case was already covered by a MatrixLookup2D*

Location:
trunk/yat/classifier
Files:
4 edited

Legend:

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

    r1146 r1163  
    3030#include "MatrixLookupWeighted.h"
    3131
     32#include <cassert>
    3233#include <vector>
    3334
     
    3839  Kernel::Kernel(const MatrixLookup& data, const KernelFunction& kf,
    3940                 const bool own)
    40     : data_(&data), data_w_(0), kf_(&kf), ref_count_w_(NULL)
     41    : ml_(&data), mlw_(0), kf_(&kf), ref_count_w_(NULL)
    4142  {
    4243    if (own)
     
    4950  Kernel::Kernel(const MatrixLookupWeighted& data, const KernelFunction& kf,
    5051                 const bool own)
    51     : data_(&data), data_w_(&data), kf_(&kf)
     52    : ml_(NULL), mlw_(&data), kf_(&kf)
    5253  {
    5354    if (own){
    54       ref_count_ = new u_int(1);
    5555      ref_count_w_ = new u_int(1);
    5656    }
    5757    else {
    58       ref_count_ = NULL;
    5958      ref_count_w_ = NULL;
    6059    }
     60    ref_count_ = NULL;
    6161  }
    6262
     
    6565    : kf_(other.kf_)
    6666  {
    67     data_ = other.data_->selected(utility::Index(index));
    68     ref_count_ = new u_int(1);
    6967   
    70     if (other.data_w_){
    71       data_w_ = other.data_w_->selected(utility::Index(index));
     68    if (other.weighted()){
     69      mlw_ = other.mlw_->selected(utility::Index(index));
    7270      ref_count_w_ = new u_int(1);
     71      ml_=NULL;
     72      ref_count_ = NULL;
    7373    }
    7474    else{
    75       data_w_=NULL;
     75      ml_ = other.ml_->selected(utility::Index(index));
     76      ref_count_ = new u_int(1);
     77      mlw_=NULL;
    7678      ref_count_w_ = NULL;
    7779    }
     
    8486    if (ref_count_)
    8587      if (!--(*ref_count_))
    86         delete data_;
     88        delete ml_;
    8789
    8890    if (ref_count_w_)
    8991      if (!--(*ref_count_w_))
    90         delete data_w_;
     92        delete mlw_;
    9193
    9294  }
     
    9597  const DataLookup2D& Kernel::data(void) const
    9698  {
    97     return *data_;
     99    if (weighted())
     100      return *mlw_;
     101    return *ml_;
    98102  }
    99103
     
    101105  double Kernel::element(const DataLookup1D& vec, const size_t i) const
    102106  {
    103     if (data_w_)
    104       return kf_->operator()(vec, DataLookupWeighted1D(*data_w_,i, false));
     107    if (weighted())
     108      return kf_->operator()(vec, DataLookupWeighted1D(*mlw_,i, false));
    105109    else
    106       return kf_->operator()(vec,DataLookup1D(dynamic_cast<const MatrixLookup&>
    107                                               (*data_),i, false));
     110      return kf_->operator()(vec,DataLookup1D(*ml_,i, false));
    108111  }
    109112
     
    111114  double Kernel::element(const DataLookupWeighted1D& vec, const size_t i) const
    112115  {
    113     if (data_w_)
    114       return kf_->operator()(vec, DataLookupWeighted1D(*data_w_,i, false));
     116    if (weighted())
     117      return kf_->operator()(vec, DataLookupWeighted1D(*mlw_,i, false));
    115118    else
    116       return kf_->operator()(vec, DataLookup1D(dynamic_cast<const MatrixLookup&>
    117                                               (*data_),i, false));
     119      return kf_->operator()(vec, DataLookup1D(*ml_,i, false));
    118120  }
    119121
     
    121123  size_t Kernel::size(void) const
    122124  {
    123     return data_->columns();
     125    if (weighted())
     126      return mlw_->columns();
     127    assert(ml_);
     128    return ml_->columns();
    124129  }
    125130
     
    127132  bool Kernel::weighted(void) const
    128133  {
    129     return data_w_;
     134    return mlw_;
    130135  }
    131136
  • trunk/yat/classifier/Kernel.h

    r1125 r1163  
    162162  protected:
    163163    /// underlying data
    164     const DataLookup2D* data_;
     164    const MatrixLookup* ml_;
    165165    /// same as data_ if weifghted otherwise a NULL pointer
    166     const MatrixLookupWeighted* data_w_;
     166    const MatrixLookupWeighted* mlw_;
    167167    /// type of Kernel Function e.g. Gaussian (aka RBF)
    168168    const KernelFunction* kf_;
  • trunk/yat/classifier/Kernel_MEV.cc

    r1146 r1163  
    6868  double Kernel_MEV::operator()(const size_t row, const size_t column) const
    6969  {
    70     if (data_w_)
    71       return (*kf_)(DataLookupWeighted1D(*data_w_,row,false),
    72                     DataLookupWeighted1D(*data_w_,column,false));
     70    if (weighted())
     71      return (*kf_)(DataLookupWeighted1D(*mlw_,row,false),
     72                    DataLookupWeighted1D(*mlw_,column,false));
    7373    else
    74       return (*kf_)(DataLookup1D(dynamic_cast<const MatrixLookup&>
    75                                  (*data_),row,false),
    76                     DataLookup1D(dynamic_cast<const MatrixLookup&>
    77                                  (*data_),column,false));
     74      return (*kf_)(DataLookup1D(*ml_,row,false),
     75                    DataLookup1D(*ml_,column,false));
    7876  }
    7977
  • trunk/yat/classifier/Kernel_SEV.cc

    r1146 r1163  
    4747    : Kernel(data,kf, own)
    4848  {
    49     kernel_matrix_.resize(data_->columns(),data_->columns());
     49    kernel_matrix_.resize(data.columns(),data.columns());
    5050    for (size_t i=0; i<kernel_matrix_.rows(); i++)
    5151      for (size_t j=i; j<kernel_matrix_.columns(); j++)
     
    6666  void Kernel_SEV::build_kernel(void)
    6767  {
    68     kernel_matrix_.resize(data_->columns(),data_->columns());
     68    kernel_matrix_.resize(size(),size());
    6969    for (size_t i=0; i<kernel_matrix_.rows(); i++)
    7070      for (size_t j=i; j<kernel_matrix_.columns(); j++)
    7171        kernel_matrix_(i,j) = kernel_matrix_(j,i) =
    72           (*kf_)(DataLookup1D(dynamic_cast<const MatrixLookup&>(*data_),i,false),
    73                  DataLookup1D(dynamic_cast<const MatrixLookup&>(*data_),j,false));
     72          (*kf_)(DataLookup1D(*ml_,i,false),
     73                 DataLookup1D(*ml_,j,false));
    7474  }
    7575
Note: See TracChangeset for help on using the changeset viewer.