# Changeset 67

Ignore:
Timestamp:
Apr 27, 2004, 5:04:31 PM (19 years ago)
Message:

added choice to use weights for the calculation of kernel matrix

Location:
trunk/src
Files:
7 edited

Unmodified
Removed
• ## trunk/src/GaussianKernelFunction.cc

 r42 } double GaussianKernelFunction::operator()(const gslapi::vector& a, const gslapi::vector& b) const double GaussianKernelFunction::operator()(const gslapi::vector& a1, const gslapi::vector& a2, const gslapi::vector& w1, const gslapi::vector& w2) const { u_int nof_valid_datapairs = 0; double tmp = 0; // check that a size == b size ! if(a.size() != b.size()) std::cerr << "vectors must have same length\n"; for(u_int k=0; k
• ## trunk/src/GaussianKernelFunction.h

 r42 #include "KernelFunction.h" #include "vector.h" namespace theplu { 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); /** Destructor */ ///Destructor /// virtual ~GaussianKernelFunction(void) {}; /** returning the scalar product of two vectors in feature space using the Gaussian kernel. @return \f$exp((x - y)^{2}/\sigma^2) \f$ \n */ double operator()(const gslapi::vector&, const gslapi::vector&) const; ///returning the scalar product of two vectors in feature space using the ///Gaussian kernel. @return \f$exp((x - y)^{2}/\sigma^2) \f$ \n /// inline double operator()(const gslapi::vector& a1, const gslapi::vector& a2) {return exp(-(a1-a2)*(a1-a2)/pow(sigma_,2));} ///returning the scalar product of two vectors in feature space using the ///Gaussian kernel with weights. /// double operator()(const gslapi::vector& a1, const gslapi::vector& a2, const gslapi::vector& w1, const gslapi::vector& w2) const; private: double sigma_;
• ## trunk/src/Kernel.cc

 r51 : k_(data.rows(),data.rows()) { for(u_int i=0;i
• ## trunk/src/Kernel.h

 r51 public: /// ///   Constructor taking the data matrix and KernelFunction as input. ///   Constructor taking the data matrix and KernelFunction as ///   input. Note: can not handle NaNs. When dealing with missing values, ///   use constructor taking a weight matrix. Kernel(const gslapi::matrix&, const KernelFunction&); /// Kernel(const gslapi::matrix&, const KernelFunction&); ///   Constructor taking the data matrix, the KernelFunction and a weight ///   matrix as input. Kernel(const gslapi::matrix&, const KernelFunction&, const gslapi::matrix&); /// ///   Destructor /// virtual ~Kernel(void); /// ///   @return Kernel matrix ///
• ## trunk/src/KernelFunction.h

 r42 const gslapi::vector&) const = 0; virtual double operator()(const gslapi::vector&, const gslapi::vector&, const gslapi::vector&, const gslapi::vector&) const = 0; }; // class KernelFunction
• ## trunk/src/PolynomialKernelFunction.cc

 r42 } double PolynomialKernelFunction::operator()(const gslapi::vector& a, const gslapi::vector& b) const double PolynomialKernelFunction::operator()(const gslapi::vector& a1, const gslapi::vector& a2) const { using namespace std; if(order_>1) return pow(a1*a2,order_); return a1*a2; } u_int nof_valid_datapairs = 0; double tmp = 0; // check that a size == b size ! if(a.size() != b.size()) cerr << "vectors must have same length\n"; for(u_int k=0; k1) return pow(1+tmp,order_); return tmp; double PolynomialKernelFunction::operator()(const gslapi::vector& a1, const gslapi::vector& a2, const gslapi::vector& w1, const gslapi::vector& w2) const { double scalar = 0; double normalization_factor = 0; for (size_t i=0; i1) return pow(scalar/normalization_factor,order_); return scalar/normalization_factor; }
• ## trunk/src/PolynomialKernelFunction.h

 r42 namespace cpptools { /** Class calculating one element in the kernel matrix using the polynomial kernel. */ ///Class calculating one element in the kernel matrix using the polynomial ///kernel. /// public: /** Constructor taking the order of the polynomial as input. Default is order=1 yielding the linear kernel function. */ ///Constructor taking the order of the polynomial as input. Default is ///order=1 yielding the linear kernel function. /// PolynomialKernelFunction(int = 1); /** Destructor */ ///Destructor /// virtual ~PolynomialKernelFunction(void) {}; /** 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$ /// double operator()(const gslapi::vector&, const gslapi::vector&) const; ///returning the scalar product of two vectors in feature space using the ///polynomial kernel with weights. /// double operator()(const gslapi::vector&, const gslapi::vector&, const gslapi::vector&, const gslapi::vector&) const; private:
Note: See TracChangeset for help on using the changeset viewer.