Changeset 446


Ignore:
Timestamp:
Dec 15, 2005, 6:11:29 PM (17 years ago)
Author:
Peter
Message:

added copy constructor for KernelView? and added construction of KernelView? in test

Location:
trunk
Files:
3 edited

Legend:

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

    r336 r446  
    99namespace svm { 
    1010
    11 KernelView::KernelView(const Kernel& kernel, const std::vector<size_t>& index)
    12   : Kernel(), kernel_(&kernel), index_(index)
    13 {
    14   // to view into the original kernel rather than a view
    15   //if (kernel.is_view()){
    16   //  kernel_=kernel.kernel_;
    17   //  for (size_t i=0; i<index.size(); i++)
    18   //    index_[i]=kernel.index_[index[i]];
    19   //}
    20 }
     11  KernelView::KernelView(const Kernel& kernel, const std::vector<size_t>& index)
     12    : Kernel(), kernel_(&kernel), index_(index)
     13  {
     14  }
     15 
     16  KernelView::KernelView(const KernelView& other)
     17    : Kernel(), kernel_(other.kernel_), index_(other.index_)
     18  {
     19  }
    2120
    22 KernelView::~KernelView(void)
    23 {
    24 
     21    KernelView::~KernelView(void)
     22  {
     23 
    2524
    2625}} // of namespace svm and namespace theplu
  • trunk/lib/svm/KernelView.h

    r336 r446  
    2121  public:
    2222   
    23     ///
    24     /// Default constructor. Not implemented.
    25     ///
    26     KernelView(void);
    27 
    28     ///
     23    ///
    2924    /// Contructor taking the Kernel to view into and a vector of the
    3025    /// indeces we view into. The constructed Kernel matrix will have
     
    3732    KernelView(const Kernel& kernel, const std::vector<size_t>& index);
    3833   
    39     ///
    40     /// @todo
     34    ///
    4135    /// Copy constructor
    4236    ///
    4337    KernelView(const KernelView&);
    4438
    45     ///
     39    /// 
    4640    ///   Destructor
    4741    ///
     
    6155   
    6256
    63   private:
     57  private:
     58    ///
     59    /// Default constructor. Not implemented.
     60    ///
     61    KernelView(void);
     62
    6463    const Kernel* kernel_;
    6564    const std::vector<size_t>& index_;
  • trunk/test/kernel_test.cc

    r345 r446  
    66#include <c++_tools/gslapi/matrix.h>
    77#include <c++_tools/gslapi/vector.h>
     8#include <c++_tools/svm/KernelFunction.h>
    89#include <c++_tools/svm/PolynomialKernelFunction.h>
    910#include <c++_tools/svm/GaussianKernelFunction.h>
     11#include <c++_tools/svm/KernelView.h>
    1012#include <c++_tools/svm/Kernel_MEV.h>
    1113#include <c++_tools/svm/Kernel_SEV.h>
    1214
    1315#include <cmath>
     16#include <cstdlib>
    1417#include <fstream>
    1518#include <iostream>
    16 #include <cstdlib>
    17 
     19#include <vector>
    1820
    1921using namespace theplu;
     
    2729      if (fabs(kernel(i,j)-control(i,j))>error_bound)
    2830        return false;
     31
     32  // checking view
     33  std::vector<size_t> index(3);
     34  index[0]=1;
     35  index[1]=2;
     36  index[2]=3;
     37  svm::KernelView(kernel,index);
    2938
    3039  return true;
     
    4049        return false;
    4150
     51  // checking view
     52  std::vector<size_t> index(3);
     53  index[0]=1;
     54  index[1]=2;
     55  index[2]=3;
     56  svm::KernelView(kernel,index);
    4257  return true;
    4358}
    4459
    4560
    46 int main()
     61int main(const int argc,const char* argv[])
    4762
    4863
     64  std::ostream* error;
     65  if (argc>1 && argv[1]==std::string("-v"))
     66    error = &std::cerr;
     67  else {
     68    error = new std::ofstream("/dev/null");
     69    if (argc>1)
     70      std::cout << "kernel_test -v : for printing extra information\n";
     71  }
     72  *error << "testing kernels" << std::endl;
    4973  bool ok = true;
     74
    5075  // Peter, the hardcoded number below should be changed.
    5176  double error_bound = 1e-8;
     
    77102  delete kf;
    78103
     104  if (error!=&std::cerr)
     105    delete error;
     106
    79107  if (ok=true) 
    80108    return 0;
Note: See TracChangeset for help on using the changeset viewer.