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

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

fixes #124 also extended interface of AveragerPairWeighted? supporting DataLookupWeighted1D

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 1.7 KB
Line 
1// $Id$
2
3#include <c++_tools/classifier/PolynomialKernelFunction.h>
4#include <c++_tools/classifier/DataLookup1D.h>
5#include <c++_tools/classifier/DataLookupWeighted1D.h>
6
7#include <c++_tools/statistics/AveragerPairWeighted.h>
8
9#include <cmath>
10
11
12namespace theplu {
13namespace classifier { 
14
15PolynomialKernelFunction::PolynomialKernelFunction(int order) 
16  : KernelFunction(), order_(order)
17{
18}
19
20
21double PolynomialKernelFunction::operator()(const DataLookup1D& x,
22                                            const DataLookup1D& y) const   
23{ 
24  assert(x.size()==y.size());
25  return ((order_>1) ? pow(1+x*y,order_) : x*y); 
26}
27
28
29double PolynomialKernelFunction::operator()(const DataLookup1D& x,
30                                            const DataLookupWeighted1D& y) const
31{ 
32  assert(x.size()==y.size());
33  statistics::AveragerPairWeighted averager;
34  averager.add(x,y);
35  if(order_>1) 
36    return pow(1+averager.sum_xy(),order_);
37  return averager.sum_xy();
38}
39
40
41double PolynomialKernelFunction::operator()(const DataLookupWeighted1D& x,
42                                            const DataLookupWeighted1D& y) const
43{ 
44  assert(x.size()==y.size());
45  statistics::AveragerPairWeighted averager;
46  averager.add(x,y);
47  if(order_>1) 
48    return pow(1+averager.sum_xy(),order_);
49  return averager.sum_xy();
50}
51
52
53double PolynomialKernelFunction::operator()(const DataLookup1D& a1,
54                                            const DataLookup1D& a2,
55                                            const DataLookup1D& w1,
56                                            const DataLookup1D& w2) const   
57{
58  statistics::AveragerPairWeighted averager;
59  for (size_t i=0; i<a1.size(); i++)
60    averager.add(a1(i),a2(i),w1(i),w2(i));
61
62  if(order_>1) 
63    return pow(1+averager.sum_xy(),order_);
64  return averager.sum_xy();
65}
66
67}} // of namespace cpptools and namespace theplu
Note: See TracBrowser for help on using the repository browser.