Changeset 330


Ignore:
Timestamp:
Jun 1, 2005, 11:30:47 PM (16 years ago)
Author:
Peter
Message:

added an abstract base class for Kernel from which Kernel_SEV Kernel_MEV are inherited. Also added a separate class for viewing into subKernels

Location:
trunk/lib/svm
Files:
4 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/svm/Kernel_MEV.cc

    r307 r330  
    1010namespace svm { 
    1111
    12 Kernel_MEV::Kernel_MEV(const gslapi::matrix& data, const KernelFunction& kf)
    13   : data_(data), kf_(&kf)
    14 {
    15 }
     12  Kernel_MEV::Kernel_MEV(const gslapi::matrix& data, const KernelFunction& kf)
     13    : Kernel(data, kf)
     14  {
     15  }
    1616
    1717
    18 Kernel_MEV::~Kernel_MEV(void)
    19 {
    20 
    2118
    22 double Kernel_MEV::operator()(size_t row, size_t column) const
    23 {
    24   return (*kf_)(data_.TEMP_col_return(row),data_.TEMP_col_return(column));
    25 }
     19  Kernel_MEV::~Kernel_MEV(void)
     20  {
     21  }
     22
     23
     24
     25  double Kernel_MEV::operator()(size_t row, size_t column) const
     26  {
     27    return (*kf_)(data_.TEMP_col_return(row),data_.TEMP_col_return(column));
     28  }
    2629
    2730
  • trunk/lib/svm/Kernel_MEV.h

    r322 r330  
    44#define _theplu_svm_kernel_mev
    55
     6#include <c++_tools/svm/Kernel.h>
    67#include <c++_tools/gslapi/matrix.h>
    78
     
    2223  ///   @see also Kernel_SEV
    2324  ///
    24   class Kernel_MEV
     25  class Kernel_MEV : public Kernel
    2526  {
    2627   
    2728  public:
    2829   
     30    ///
     31    ///  Default constructor (not implemented)
     32    ///
    2933    Kernel_MEV();
    3034
     
    5357    /// matrix
    5458    ///
    55     virtual double operator()(const size_t row,const size_t column) const;
     59    double operator()(const size_t row,const size_t column) const;
    5660
    57     ///
    58     /// @brief number of samples
    59     ///
    60     inline size_t size(void) const { return data_.columns(); }
    61    
    62   protected:
    63     const gslapi::matrix& data_;
    64     const KernelFunction* kf_;
    6561
    6662  }; // class Kernel_MEV
  • trunk/lib/svm/Kernel_SEV.cc

    r307 r330  
    33#include <c++_tools/svm/Kernel_SEV.h>
    44
     5#include <c++_tools/svm/Kernel.h>
    56#include <c++_tools/svm/KernelFunction.h>
    6 #include <c++_tools/svm/Kernel_MEV.h>
    77#include <c++_tools/gslapi/matrix.h>
    88#include <c++_tools/gslapi/vector.h>
     
    1212
    1313Kernel_SEV::Kernel_SEV(const gslapi::matrix& data, const KernelFunction& kf)
    14   : Kernel_MEV(data,kf)
     14  : Kernel(data,kf)
    1515{
    16   kernel_ = gslapi::matrix(data.columns(),data.columns());
    17   for (size_t i=0; i<kernel_.rows(); i++)
    18     for (size_t j=i; j<kernel_.columns(); j++)
    19       kernel_(i,j) = kernel_(j,i) =
     16  kernel_matrix_ = gslapi::matrix(data.columns(),data.columns());
     17  for (size_t i=0; i<kernel_matrix_.rows(); i++)
     18    for (size_t j=i; j<kernel_matrix_.columns(); j++)
     19      kernel_matrix_(i,j) = kernel_matrix_(j,i) =
    2020        (*kf_)(data_.TEMP_col_return(i),data_.TEMP_col_return(j));
    2121
  • trunk/lib/svm/Kernel_SEV.h

    r322 r330  
    55
    66#include <c++_tools/gslapi/matrix.h>
    7 #include <c++_tools/svm/Kernel_MEV.h>
     7#include <c++_tools/svm/Kernel.h>
    88
    99
     
    2424  ///   @see also Kernel_MEV
    2525  ///
    26   class Kernel_SEV : public Kernel_MEV
     26  class Kernel_SEV : public Kernel
    2727  {
    2828   
     
    5151    ///
    5252    inline double operator()(const size_t row,const size_t column) const
    53     { return kernel_(row,column); }
     53    { return kernel_matrix_(row,column); }
    5454   
    5555  private:
    56     gslapi::matrix kernel_;
     56    gslapi::matrix kernel_matrix_;
    5757
    5858  }; // class Kernel_SEV
  • trunk/lib/svm/Makefile.am

    r319 r330  
    1010libsvm_la_SOURCES = \
    1111  ConsensusInputRanker.cc CrossValidation.cc GaussianKernelFunction.cc \
    12   InputRanker.cc Kernel_MEV.cc Kernel_SEV.cc \
     12  InputRanker.cc Kernel.cc Kernel_MEV.cc Kernel_SEV.cc \
    1313  PolynomialKernelFunction.cc  SVM.cc
    1414
     
    1717include_svm_HEADERS = \
    1818  ConsensusInputRanker.h CrossValidation.h GaussianKernelFunction.h \
    19   InputRanker.h KernelFunction.h Kernel_MEV.h Kernel_SEV.h \
     19  InputRanker.h Kernel.h KernelFunction.h Kernel_MEV.h Kernel_SEV.h \
    2020  PolynomialKernelFunction.h SVM.h
  • trunk/lib/svm/SVM.cc

    r323 r330  
    44#include <c++_tools/svm/SVM.h>
    55
    6 #include <c++_tools/svm/Kernel_MEV.h>
     6#include <c++_tools/svm/Kernel.h>
    77#include <c++_tools/gslapi/matrix.h>
    88#include <c++_tools/gslapi/vector.h>
     
    137137  }
    138138
    139   SVM::SVM(const Kernel_MEV& kernel,
    140            const gslapi::vector& target)
     139  SVM::SVM(const Kernel& kernel, const gslapi::vector& target)
    141140           
    142141  : alpha_(target.size(),0),
    143142    bias_(0),
    144143    C_inverse_(0),
    145     kernel_(kernel),
     144    kernel_(&kernel),
    146145    max_epochs_(10000000),
    147146    output_(target.size(),0),
     
    160159  {
    161160    // initializing variables for optimization
    162     assert(target_.size()==kernel_.size());
     161    assert(target_.size()==kernel_->size());
    163162    assert(target_.size()==alpha_.size());
    164163
     
    358357      output_(i)=0;
    359358      for (size_t j=0; j<output_.size(); j++)
    360         output_(i)+=alpha_(j)*target_(j)*kernel_(i,j);
     359        output_(i)+=alpha_(j)*target_(j)*(*kernel_)(i,j);
    361360    }
    362361
  • trunk/lib/svm/SVM.h

    r323 r330  
    44#define _theplu_svm_svm_
    55
    6 #include <c++_tools/svm/Kernel_MEV.h>
     6#include <c++_tools/svm/Kernel.h>
    77#include <c++_tools/gslapi/vector.h>
    88
     
    1313namespace theplu {
    1414namespace svm { 
     15
     16  class Kernel;
    1517
    1618  // @internal Class keeping track of which samples are support vectors and
     
    8991
    9092  ///
    91   /// Class for SVM using Keerthi's second modification of Platt's SMO.
     93  /// Class for SVM using Keerthi's second modification of Platt's
     94  /// Sequential Minimal Optimization. The SVM uses all data given for
     95  /// training. If validation or testing is wanted this should be
     96  /// taken care of outside (in the kernel).
    9297  ///   
    9398  class SVM
     
    101106
    102107    ///
    103     /// Constructor taking the kernel and the target vector as input.
    104     ///
    105     SVM(const Kernel_MEV&,
    106         const gslapi::vector&);
     108    /// Constructor taking the kernel and the target vector as
     109    /// input. @note if the kernel or target is destroyed the SVM is
     110    /// no longer defined
     111    ///
     112    SVM(const Kernel&, const gslapi::vector&);
    107113
    108114    ///
     
    168174    double bias_;
    169175    double C_inverse_;
    170     const Kernel_MEV& kernel_;
     176    const Kernel* kernel_;
    171177    unsigned long int max_epochs_;
    172178    gslapi::vector output_;
     
    202208
    203209    ///
    204     /// @return kernel modified in with diagonal term (soft margin)
     210    /// @return kernel modified with diagonal term (soft margin)
    205211    ///
    206212    inline double kernel_mod(const size_t i, const size_t j) const
    207     { return i!=j ? kernel_(i,j) : kernel_(i,j) + C_inverse_; }
     213    { return i!=j ? (*kernel_)(i,j) : (*kernel_)(i,j) + C_inverse_; }
    208214   
    209215  };
Note: See TracChangeset for help on using the changeset viewer.