Changeset 167


Ignore:
Timestamp:
Sep 23, 2004, 11:21:11 AM (17 years ago)
Author:
Peter
Message:

.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SVM.cc

    r162 r167  
    2020namespace cpptools { 
    2121
    22   SVM::SVM(const gslapi::matrix& kernel, const gslapi::vector& target,
    23            const std::vector<size_t> train_set)
     22  SVM::SVM(const Kernel& kernel,
     23           const gslapi::vector& target,
     24           const std::vector<size_t>& train_set)
    2425  : alpha_(target.size(),0),
    2526    bias_(0),
     
    4142
    4243
     44
    4345  std::pair<size_t,size_t>
    4446  SVM::choose(const theplu::gslapi::vector& E, 
     
    9597  }
    9698 
     99 
     100
    97101  bool SVM::train()
    98102  {
     
    107111      target_train(i) = target_(train_set_[i]);
    108112      for (unsigned int j=0; j<train_set_.size(); j++)
    109         kernel_train(i,j) = kernel_(train_set_[i],train_set_[j]);
     113        kernel_train(i,j) = kernel_.get()(train_set_[i],train_set_[j]);
    110114    }
    111115
  • trunk/src/SVM.h

    r162 r167  
    66// C++ tools include
    77/////////////////////
     8#include "Kernel.h"
     9#include "matrix.h"
    810#include "vector.h"
    9 #include "matrix.h"
     11
    1012
    1113// Standard C++ includes
     
    3335    /// Constructor taking the kernel matrix and the target vector as input
    3436    ///
    35     SVM(const gslapi::matrix&, const gslapi::vector&,
    36         const std::vector<size_t> = std::vector<size_t>());
     37    SVM(const Kernel&, const gslapi::vector&,
     38        const std::vector<size_t>& = std::vector<size_t>());
    3739         
    3840    ///
     
    4749
    4850    ///
    49     /// Function returns the output from SVM
    50     ///
    51     inline gslapi::vector get_output(void) const
    52     { return (kernel_ * alpha_.mul_elements(target_) +
    53               gslapi::vector(target_.size(),bias_) );}
    54 
    55     ///
    5651    /// @return number of maximal epochs
    5752    ///
     
    6358    inline void max_epochs(const unsigned long int d) {max_epochs_=d;}
    6459   
     60    ///
     61    /// @return output
     62    ///
     63    inline theplu::gslapi::vector output(void)
     64    {return kernel_.get() * alpha_.mul_elements(target_)+
     65       theplu::gslapi::vector(alpha_.size(),bias_);}
     66
    6567    ///
    6668    /// Changing the C-parameter
     
    8486    double bias_;
    8587    double c_;
    86     gslapi::matrix kernel_;
     88    Kernel kernel_;
    8789    unsigned long int max_epochs_;
    8890    gslapi::vector target_;
Note: See TracChangeset for help on using the changeset viewer.