Changeset 524
- Timestamp:
- Feb 23, 2006, 4:55:33 PM (17 years ago)
- Location:
- trunk/lib/classifier
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/classifier/PolynomialKernelFunction.cc
r451 r524 6 6 #include <c++_tools/gslapi/matrix.h> 7 7 #include <c++_tools/gslapi/vector.h> 8 #include <c++_tools/statistics/AveragerPairWeighted.h> 8 9 9 10 #include <cmath> … … 23 24 const gslapi::vector& w2) const 24 25 { 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 33 30 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(); 36 33 } 37 34 -
trunk/lib/classifier/PolynomialKernelFunction.h
r475 r524 44 44 45 45 /// 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; 51 57 52 58 private:
Note: See TracChangeset
for help on using the changeset viewer.