# Changeset 627

Ignore:
Timestamp:
Sep 5, 2006, 7:39:45 AM (16 years ago)
Message:

fixes #124 also extended interface of AveragerPairWeighted? supporting DataLookupWeighted1D

Location:
trunk
Files:
8 edited

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

 r616 #include #include #include #include return exp(-d2/sigma2_); } double GaussianKernelFunction::operator()(const DataLookup1D& x, const DataLookupWeighted1D& y) const { assert(x.size()==y.size()); double d2 = 0; double normalization_factor = 0; for (size_t i=0; i
• ## trunk/c++_tools/classifier/GaussianKernelFunction.h

 r616 public: /// ///Constructor taking the sigma_ , i.e. the width of the Gaussian,as ///input. Default is sigma_ = 1. /// /// Constructor taking the sigma_ , i.e. the width of the Gaussian,as /// input. Default is sigma_ = 1. /// GaussianKernelFunction(double = 1); /// /// returning the scalar product of two vectors in feature space using the /// Gaussian kernel. @return \f$exp((x - y)^{2}/\sigma^2) \f$ \n /// Gaussian kernel. @return \f$exp(-(x - y)^{2}/\sigma^2) \f$ \n /// double operator()(const DataLookup1D& a1, const DataLookup1D& a2) const; double operator()(const DataLookup1D& x, const DataLookup1D& y) const; /** \f$\exp(-d^2/\sigma^2) \f$ where \f$d^2 = \sum w_y(x_i-y_i)^2 / \sum w_y * N \f$ **/ double operator()(const DataLookup1D& x, const DataLookupWeighted1D& y) const; /** \f$\exp(-d^2/\sigma^2) \f$ where \f$d^2 = \sum w_xw_y(x_i-y_i)^2 / \sum w_xw_y * N \f$ **/ double operator()(const DataLookupWeighted1D& x, const DataLookupWeighted1D& y) const; ///
• ## trunk/c++_tools/classifier/KernelFunction.h

 r608 namespace classifier { class DataLookup1D; class DataLookupWeighted1D; /// /// @return scalar product of two vector in feature space. /// virtual double operator()(const DataLookup1D&, const DataLookupWeighted1D&) const = 0; /// /// @return scalar product of two vector in feature space. /// inline double operator()(const DataLookupWeighted1D& vec_w, const DataLookup1D& vec) const { return this->operator()(vec,vec_w); } /// /// @return scalar product of two vector in feature space. /// virtual double operator()(const DataLookupWeighted1D&, const DataLookupWeighted1D&) const = 0; /// /// @return scalar product of two vector in feature space. /// virtual double operator()(const DataLookup1D&, const DataLookup1D&,
• ## trunk/c++_tools/classifier/PolynomialKernelFunction.cc

 r616 // $Id$ #include #include #include #include } double PolynomialKernelFunction::operator()(const DataLookup1D& x, const DataLookup1D& y) const { assert(x.size()==y.size()); return ((order_>1) ? pow(1+x*y,order_) : x*y); } double PolynomialKernelFunction::operator()(const DataLookup1D& x, const DataLookupWeighted1D& y) const { assert(x.size()==y.size()); statistics::AveragerPairWeighted averager; averager.add(x,y); if(order_>1) return pow(1+averager.sum_xy(),order_); return averager.sum_xy(); } double PolynomialKernelFunction::operator()(const DataLookupWeighted1D& x, const DataLookupWeighted1D& y) const { assert(x.size()==y.size()); statistics::AveragerPairWeighted averager; averager.add(x,y); if(order_>1) return pow(1+averager.sum_xy(),order_); return averager.sum_xy(); } double PolynomialKernelFunction::operator()(const DataLookup1D& a1, const DataLookup1D& a2, averager.add(a1(i),a2(i),w1(i),w2(i)); // a1.size() term to make it coherent with no weight case if(order_>1) return pow(1+averager.sum_xy()/averager.sum_w()*a1.size(),order_); return averager.sum_xy()/averager.sum_w()*a1.size(); return pow(1+averager.sum_xy(),order_); return averager.sum_xy(); }

 r608 // $Id$ #ifndef _theplu_classifier_polynomial_kernel_function_ #define _theplu_classifier_polynomial_kernel_function_ // $Id$ #include /// ///returning the scalar product of two vectors in feature space using the ///polynomial kernel. @return If order is larger than one: \f$(1+x \cdot ///y)^{order} \f$ \n If order is one (linear): \f$x \cdot y \f$ /// returning the scalar product of two vectors in feature space using the /// polynomial kernel. @return If order is larger than one: \f$(1+x \cdot /// y)^{order} \f$ \n If order is one (linear): \f$x \cdot y \f$ /// inline double operator()(const DataLookup1D& a1, const DataLookup1D& a2) const { return ((order_>1) ? pow(1+a1*a2,order_) : a1*a2); } double operator()(const DataLookup1D& a1, const DataLookup1D& a2) const; /// /// @return If order is larger than one: \f$(1+x \cdot y)^{order} /// \f$ \n If order is one (linear): \f$\frac{\sum w_yxy} \f$ /// /// double operator()(const DataLookup1D& x, const DataLookupWeighted1D& y) const; /// /// returning the scalar product of two vectors in feature space /// using the polynomial kernel with weights. Having all weights /// equal to unity yields the same as non-weighted version. /// /// @return If order is larger than one: \f$(1+x \cdot y)^{order} /// \f$ \n If order is one (linear): \f$\sum w_xw_yxy} \f$ /// double operator()(const DataLookupWeighted1D& x, const DataLookupWeighted1D& y) const; /// /// @return If order is larger than one: \f$(1+x \cdot y)^{order} /// \f$ \n If order is one (linear): \f$N\frac{\sum /// w_xw_yxy}{\sum w_xw_y} \f$ /// \f$\n If order is one (linear): \f$ \frac{\sum w_xw_yxy} \f$/// /// • ## trunk/c++_tools/statistics/AveragerPairWeighted.cc  r582 //$Id$#include #include #include #include "c++_tools/statistics/AveragerPairWeighted.h" #include "c++_tools/statistics/AveragerPair.h" #include "c++_tools/statistics/Averager.h" #include "c++_tools/classifier/DataLookup1D.h" #include "c++_tools/classifier/DataLookupWeighted1D.h" #include } void AveragerPairWeighted::add(const classifier::DataLookup1D& x, const classifier::DataLookupWeighted1D& y) { assert(x.size()==y.size()); for (size_t i=0; i • ## trunk/c++_tools/statistics/AveragerPairWeighted.h  r616 namespace theplu{ namespace classifier{ class DataLookup1D; class DataLookupWeighted1D; } namespace statistics{ /// void add(const double x, const double y, const double wx, const double wy); /// /// /// void add(const classifier::DataLookup1D& x, const classifier::DataLookupWeighted1D& y); /// /// /// inline void add(const classifier::DataLookupWeighted1D& x, const classifier::DataLookup1D& y){ add(y,x); } /// /// /// void add(const classifier::DataLookupWeighted1D& x, const classifier::DataLookupWeighted1D& y); /// • ## trunk/doc/Statistics.tex  r586 \subsection{Polynomial Kernel} The polynomial kernel of degree$N$is defined as$(1+)^N$, where $$is the linear kenrel (usual scalar product). For weights we define the linear kernel to be =\frac{\sum w_xw_yxy}{\sum w_xw_y} and the polynomial kernel can be calculated as before$$ is the linear kernel (usual scalar product). For the weighted case we define the linear kernel to be$=\sum w_xw_yxy}$and the polynomial kernel can be calculated as before$(1+)^N$. Is this kernel a proper kernel (always being semi positive definite). Yes, because$\$ is obviously a proper kernel
Note: See TracChangeset for help on using the changeset viewer.