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

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

fixes #125 removing obsolete function and cleaning in Kernel classes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 1.3 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
53}} // of namespace cpptools and namespace theplu
Note: See TracBrowser for help on using the repository browser.