Changeset 524


Ignore:
Timestamp:
Feb 23, 2006, 4:55:33 PM (16 years ago)
Author:
Peter
Message:

fixed bug PolynimialKernelFunction? - can now handle NaNs? with weights

Location:
trunk/lib/classifier
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/classifier/PolynomialKernelFunction.cc

    r451 r524  
    66#include <c++_tools/gslapi/matrix.h>
    77#include <c++_tools/gslapi/vector.h>
     8#include <c++_tools/statistics/AveragerPairWeighted.h>
    89
    910#include <cmath>
     
    2324                                            const gslapi::vector& w2) const   
    2425{
    25   double scalar = 0;
    26   double normalization_factor = 0;
    27   for (size_t i=0; i<a1.size(); i++) {
    28     scalar += w1(i) * w2(i) * a1(i) * a2(i);
    29     normalization_factor += w1(i) * w2(i);
    30   }
    31 // to make it coherent with no weight case
    32   normalization_factor /= a1.size();
     26  statistics::AveragerPairWeighted averager;
     27  averager.add(a1,a2,w1,w2);
     28
     29  // a1.size() term to make it coherent with no weight case
    3330  if(order_>1)
    34     return pow(scalar/normalization_factor,order_);
    35   return scalar/normalization_factor;
     31    return pow(1+averager.sum_xy()/averager.sum_w()*a1.size(),order_);
     32  return averager.sum_xy()/averager.sum_w()*a1.size();
    3633}
    3734
  • trunk/lib/classifier/PolynomialKernelFunction.h

    r475 r524  
    4444
    4545    ///
    46     ///returning the scalar product of two vectors in feature space using the
    47     ///polynomial kernel with weights.
    48     ///   
    49     double operator()(const gslapi::vector&, const gslapi::vector&,
    50                       const gslapi::vector&, const gslapi::vector&) const;
     46    ///returning the scalar product of two vectors in feature space
     47    ///using the polynomial kernel with weights. Having all weights
     48    ///equal to unity yields the same as non-weighted version.
     49    ///
     50    /// @return If order is larger than one: \f$ (1+x \cdot y)^{order}
     51    /// \f$ \n If order is one (linear): \f$ N\frac{\sum
     52    /// w_xw_yxy}{\sum w_xw_y} \f$
     53    ///
     54    ///
     55    double operator()(const gslapi::vector& x, const gslapi::vector& y,
     56                      const gslapi::vector& wx, const gslapi::vector& wy) const;
    5157   
    5258  private:
Note: See TracChangeset for help on using the changeset viewer.