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

Last change on this file since 616 was 616, checked in by Jari Häkkinen, 15 years ago

Removed gslapi namespace and put the code into utility namespace.
Move #ifndef _header_ idiom to top of touched header files.
Removed unneccesary #includes, and added needed #includes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 932 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/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
20double PolynomialKernelFunction::operator()(const DataLookup1D& a1,
21                                            const DataLookup1D& a2,
22                                            const DataLookup1D& w1,
23                                            const DataLookup1D& w2) const   
24{
25  statistics::AveragerPairWeighted averager;
26  for (size_t i=0; i<a1.size(); i++)
27    averager.add(a1(i),a2(i),w1(i),w2(i));
28
29  // a1.size() term to make it coherent with no weight case
30  if(order_>1) 
31    return pow(1+averager.sum_xy()/averager.sum_w()*a1.size(),order_);
32  return averager.sum_xy()/averager.sum_w()*a1.size();
33}
34
35}} // of namespace cpptools and namespace theplu
Note: See TracBrowser for help on using the repository browser.