source: trunk/c++_tools/classifier/PolynomialKernelFunction.cc @ 608

Last change on this file since 608 was 608, checked in by Peter, 15 years ago

set properties

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 1006 bytes
Line 
1// $Id$
2
3
4#include <c++_tools/classifier/PolynomialKernelFunction.h>
5#include <c++_tools/classifier/DataLookup1D.h>
6
7#include <c++_tools/gslapi/matrix.h>
8#include <c++_tools/gslapi/vector.h>
9#include <c++_tools/statistics/AveragerPairWeighted.h>
10
11#include <cmath>
12
13
14namespace theplu {
15namespace classifier { 
16
17PolynomialKernelFunction::PolynomialKernelFunction(int order) 
18  : KernelFunction(), order_(order)
19{
20}
21
22double PolynomialKernelFunction::operator()(const DataLookup1D& a1,
23                                            const DataLookup1D& a2,
24                                            const DataLookup1D& w1,
25                                            const DataLookup1D& w2) const   
26{
27  statistics::AveragerPairWeighted averager;
28  for (size_t i=0; i<a1.size(); i++)
29    averager.add(a1(i),a2(i),w1(i),w2(i));
30
31  // a1.size() term to make it coherent with no weight case
32  if(order_>1) 
33    return pow(1+averager.sum_xy()/averager.sum_w()*a1.size(),order_);
34  return averager.sum_xy()/averager.sum_w()*a1.size();
35}
36
37}} // of namespace cpptools and namespace theplu
Note: See TracBrowser for help on using the repository browser.