source: trunk/c++_tools/classifier/KernelWeighted_MEV.h @ 608

Last change on this file since 608 was 608, checked in by Peter, 15 years ago

set properties

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 3.0 KB
Line 
1// $Id$
2
3#ifndef _theplu_classifier_kernel_weighted_mev_
4#define _theplu_classifier_kernel_weighted_mev_
5
6#include <c++_tools/classifier/Kernel.h>
7
8#include <c++_tools/classifier/DataLookup1D.h>
9#include <c++_tools/classifier/KernelFunction.h>
10#include <c++_tools/classifier/MatrixLookup.h>
11//#include <c++_tools/gslapi/matrix.h>
12
13namespace theplu {
14namespace classifier {
15
16  ///
17  /// @brief Memory Efficient Kernel Class taking care of the
18  /// \f$ NxN \f$ kernel matrix, where \f$ N \f$ is number of
19  /// samples. Type of Kernel is defined by a KernelFunction. This
20  /// Memory Efficient Version (MEV) does not store the kernel matrix
21  /// in memory, but calculates an element when it is needed. When
22  /// memory allows do always use KernelWeighted_SEV instead.
23  ///   
24  /// @see Kernel_MEV KernelWeighted_SEV
25  ///
26  class KernelWeighted_MEV : public Kernel
27  {
28   
29  public:
30   
31    ///
32    /// Constructor taking the \a data matrix, the KernelFunction and a
33    /// \a weight matrix as input. Each column in the data matrix
34    /// corresponds to one sample.
35    ///
36    /// @note if @a data, @a kf, or @a weights is destroyed the
37    /// behaviour of the object is undefined
38    ///
39    KernelWeighted_MEV(const MatrixLookup& data, 
40                       const KernelFunction& kf, 
41                       const MatrixLookup& weights);
42
43    ///
44    /// @todo remove
45    ///
46    KernelWeighted_MEV(const KernelWeighted_MEV& other, 
47                       const std::vector<size_t>& index);
48
49    ///
50    /// @return Element at position (\a row, \a column) of the Kernel
51    /// matrix
52    ///
53    double operator()(const size_t row, const size_t column) const;
54
55    ///
56    /// Calculates the scalar product using the weighted
57    /// KernelFunction between data vector @a vec and column \f$ i \f$
58    /// in data matrix. For @a vec a vector of unity weights is used.
59    ///
60    /// @return kernel element between data @a ve and training sample @a i
61    ///
62    inline double element(const DataLookup1D& vec, const size_t i) const
63    { 
64      return (*kf_)(vec, DataLookup1D(*data_,i,false), 
65                    DataLookup1D(vec.size(),1.0),
66                    DataLookup1D(*weights_,i,false)); 
67    }
68
69    ///
70    /// Calculates the scalar product using the weighted
71    /// KernelFunction between data vector @a vec and column \f$ i \f$
72    /// in data matrix. For @a vec a vector of unity weights is used.
73    ///
74    /// @return kernel element between data @a ve and training sample @a i
75    ///
76    inline double element(const DataLookup1D& vec, const DataLookup1D& w, 
77                          const size_t i) const
78    { 
79      return (*kf_)(vec, DataLookup1D(*data_,i, false),
80                    w,DataLookup1D(*weights_,i, false)); 
81    }
82
83    ///
84    /// @todo remove
85    ///
86    const Kernel* selected(const std::vector<size_t>& index) const;
87
88    ///
89    /// @return true
90    ///
91    inline bool weighted(void) const { return true; }
92
93  private:
94    ///
95    /// Copy constructor (not implemented)
96    ///
97    KernelWeighted_MEV(const KernelWeighted_MEV&);
98    const KernelWeighted_MEV& operator=(const KernelWeighted_MEV&);
99
100
101  };
102
103}} // of namespace classifier and namespace theplu
104
105#endif
Note: See TracBrowser for help on using the repository browser.