Changeset 345


Ignore:
Timestamp:
Jun 8, 2005, 11:02:12 AM (16 years ago)
Author:
Jari Häkkinen
Message:

Made some efficiency changes in KernelFunctions?. Added a small test in kernel_test.cc

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/svm/GaussianKernelFunction.h

    r342 r345  
    3636    /// returning the scalar product of two vectors in feature space using the
    3737    /// Gaussian kernel. @return \f$ exp((x - y)^{2}/\sigma^2) \f$ \n
    38     ///
    39     inline double operator()(const gslapi::vector& a1,
     38    ///
     39    inline double operator()(const gslapi::vector& a1,
    4040                             const gslapi::vector& a2) const
    41       { return exp(-((a1-a2)*(a1-a2))/(sigma_*sigma_)); }
     41    { gslapi::vector a(a1); return exp(-((a-=a2)*a)/(sigma_*sigma_)); }
    4242
    4343    ///
  • trunk/lib/svm/PolynomialKernelFunction.cc

    r295 r345  
    77#include <c++_tools/gslapi/vector.h>
    88
    9 #include <math.h>
     9#include <cmath>
    1010
    1111
     
    1616  : KernelFunction(), order_(order)
    1717{
    18 }
    19 
    20 double PolynomialKernelFunction::operator()(const gslapi::vector& a1,
    21                                             const gslapi::vector& a2) const   
    22 {
    23   if(order_>1)
    24     return pow(1+a1*a2,order_);
    25   return a1*a2;
    2618}
    2719
  • trunk/lib/svm/PolynomialKernelFunction.h

    r295 r345  
    55
    66#include <c++_tools/svm/KernelFunction.h>
     7#include <c++_tools/gslapi/vector.h>
     8
     9#include <cmath>
     10
    711
    812namespace theplu {
     
    3943    ///y)^{order} \f$ \n If order is one (linear): \f$ x \cdot y \f$
    4044    ///   
    41     double operator()(const gslapi::vector&, const gslapi::vector&) const;
     45    inline double operator()(const gslapi::vector& a1,
     46                             const gslapi::vector& a2) const
     47      { return ((order_>1) ? pow(1+a1*a2,order_) : a1*a2); }
     48
    4249
    4350    ///
  • trunk/test/kernel_test.cc

    r307 r345  
    77#include <c++_tools/gslapi/vector.h>
    88#include <c++_tools/svm/PolynomialKernelFunction.h>
     9#include <c++_tools/svm/GaussianKernelFunction.h>
    910#include <c++_tools/svm/Kernel_MEV.h>
    1011#include <c++_tools/svm/Kernel_SEV.h>
     
    6970  ok = (ok && test_MEV(data,kf,kernel_matlab2,error_bound)
    7071        & test_SEV(data,kf,kernel_matlab2,error_bound));
    71  
     72  delete kf;
     73
     74  // Checking that a GaussianKernelFunction object can be built at
     75  // compile time.
     76  kf = new svm::GaussianKernelFunction();
     77  delete kf;
     78
    7279  if (ok=true) 
    7380    return 0;
Note: See TracChangeset for help on using the changeset viewer.