Changeset 629


Ignore:
Timestamp:
Sep 5, 2006, 10:31:04 AM (15 years ago)
Author:
Peter
Message:

fixes #125 removing obsolete function and cleaning in Kernel classes.

Location:
trunk/c++_tools/classifier
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/c++_tools/classifier/GaussianKernelFunction.cc

    r627 r629  
    6969
    7070
    71   double GaussianKernelFunction::operator()(const DataLookup1D& a1,
    72                                             const DataLookup1D& a2,
    73                                             const DataLookup1D& w1,
    74                                             const DataLookup1D& w2) const   
    75   {
    76     assert(a1.size()==a2.size());
    77     assert(w1.size()==w2.size());
    78     assert(a1.size()==w1.size());
    79     double d2 = 0;
    80     double normalization_factor = 0;
    81     for (size_t i=0; i<a1.size(); i++) {
    82       // ignoring Nan with accompanied weight zero
    83       if (w1(i) && w2(i)){
    84         d2 += w1(i) * w2(i) * (a1(i)-a2(i)) * (a1(i)-a2(i));
    85         normalization_factor += w1(i) * w2(i);
    86       }
    87     }
    88     // to make it coherent with no weight case
    89     normalization_factor /= a1.size();
    90     return exp(d2/normalization_factor/sigma2_);
    91   }
    92  
    93 
    94 
    9571}} // of namespace svn and namespace theplu
  • trunk/c++_tools/classifier/GaussianKernelFunction.h

    r627 r629  
    5252                      const DataLookupWeighted1D& y) const;
    5353
    54     ///
    55     ///returning the scalar product of two vectors in feature space using the
    56     ///Gaussian kernel with weights.
    57     ///
    58     double operator()(const DataLookup1D& a1,
    59                       const DataLookup1D& a2,
    60                       const DataLookup1D& w1,
    61                       const DataLookup1D& w2) const;
    62          
    6354  private:
    6455    double sigma2_;
  • trunk/c++_tools/classifier/Kernel.h

    r628 r629  
    120120    ///
    121121    // Peter make non-virtual?
    122     virtual bool weighted(void) const=0;
     122    inline bool weighted(void) const { return data_w_; }
    123123
    124124  protected:
  • trunk/c++_tools/classifier/KernelFunction.h

    r627 r629  
    5151                              const DataLookupWeighted1D&) const = 0;
    5252   
    53     ///
    54     /// @return scalar product of two vector in feature space.
    55     ///
    56     virtual double operator()(const DataLookup1D&,
    57                               const DataLookup1D&,
    58                               const DataLookup1D&,
    59                               const DataLookup1D&) const = 0;
    60    
    6153  }; // class KernelFunction
    6254
  • trunk/c++_tools/classifier/Kernel_MEV.h

    r628 r629  
    6363    double operator()(const size_t row, const size_t column) const;
    6464   
     65    ///
    6566    ///
    66     /// Calculates the scalar product using the KernelFunction between
    67     /// data vector @a vec and column \f$ i \f$ in data matrix.
    6867    ///
    69     /// @return kernel element between data @a vec and training sample @a i
    70     ///
    71     inline double element(const DataLookup1D& vec, const size_t i) const
    72     { return kf_->operator()(vec, DataLookup1D(*data_,i,false)); }
    73      
    74     ///
    75     /// Using the KernelFunction this function calculates the scalar
    76     /// product between vector @a vec and the column \f$ i \f$ in data
    77     /// matrix. The KernelFunction expects a weight vector for each of
    78     /// the two data vectors and as this Kernel is non-weighted each
    79     /// value in the data matrix is associated to a unity weight.
    80     ///
    81     /// @return weighted kernel element between data @a vec and
    82     /// training sample @a i
    83     ///
    84     inline double element(const DataLookup1D& vec, const DataLookup1D& w,
    85                           const size_t i) const
    86     {return (*kf_)(vec, DataLookup1D(*data_,i,false),
    87                    w, DataLookup1D(w.size(),1.0));}
    88 
    89     /// @todo remove
    9068    const Kernel_MEV* selected(const std::vector<size_t>& index) const;
    91 
    92     ///
    93     /// @return false
    94     ///
    95     inline bool weighted(void) const { return false; }
    9669
    9770  private:
  • trunk/c++_tools/classifier/Kernel_SEV.h

    r628 r629  
    5757
    5858    ///
    59     /// Calculates the scalar product using the KernelFunction between
    60     /// data vector @a vec and column \f$ i \f$ in data matrix.
    61     ///
    62     /// @return kernel element between data @a vec and training sample @a i
    63     ///
    64     double element(const DataLookup1D& vec, const size_t i) const;
    65 
    66     ///
    67     /// Using the KernelFunction this function calculates the scalar
    68     /// product between vector @a vec and the column \f$ i \f$ in data
    69     /// matrix. The KernelFunction expects a weight vector for each of
    70     /// the two data vectors and as this Kernel is non-weighted each
    71     /// value in the data matrix is associated to a unity weight.
    72     ///
    73     /// @return weighted kernel element between data @a vec and
    74     /// training sample @a i
    75     ///
    76     double element(const DataLookup1D& vec, const DataLookup1D& w,
    77                    const size_t i) const;
    78 
    79     ///
    8059    /// @todo remove this function
    8160    ///
    8261    const Kernel* selected(const std::vector<size_t>& index) const;
    83 
    84     ///
    85     /// @return false
    86     ///
    87     inline bool weighted(void) const { return false; }
    8862
    8963  private:
  • trunk/c++_tools/classifier/PolynomialKernelFunction.cc

    r627 r629  
    5151
    5252
    53 double PolynomialKernelFunction::operator()(const DataLookup1D& a1,
    54                                             const DataLookup1D& a2,
    55                                             const DataLookup1D& w1,
    56                                             const DataLookup1D& w2) const   
    57 {
    58   statistics::AveragerPairWeighted averager;
    59   for (size_t i=0; i<a1.size(); i++)
    60     averager.add(a1(i),a2(i),w1(i),w2(i));
    61 
    62   if(order_>1)
    63     return pow(1+averager.sum_xy(),order_);
    64   return averager.sum_xy();
    65 }
    66 
    6753}} // of namespace cpptools and namespace theplu
  • trunk/c++_tools/classifier/PolynomialKernelFunction.h

    r627 r629  
    6060
    6161
    62     ///
    63     ///returning the scalar product of two vectors in feature space
    64     ///using the polynomial kernel with weights. Having all weights
    65     ///equal to unity yields the same as non-weighted version.
    66     ///
    67     /// @return If order is larger than one: \f$ (1+x \cdot y)^{order}
    68     /// \f$ \n If order is one (linear): \f$ \frac{\sum w_xw_yxy} \f$
    69     ///
    70     ///
    71     double operator()(const DataLookup1D& x, const DataLookup1D& y,
    72                       const DataLookup1D& wx, const DataLookup1D& wy) const;
    73    
    7462  private:
    7563    int order_;
Note: See TracChangeset for help on using the changeset viewer.