source: trunk/yat/classifier/PolynomialKernelFunction.cc @ 1221

Last change on this file since 1221 was 1043, checked in by Peter, 13 years ago

fixing #128 - iterators in Averger classes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 2.2 KB
Line 
1// $Id$
2
3/*
4  Copyright (C) 2003 Peter Johansson
5  Copyright (C) 2004, 2005, 2006 Jari Häkkinen, Peter Johansson
6  Copyright (C) 2007 Peter Johansson
7
8  This file is part of the yat library, http://trac.thep.lu.se/yat
9
10  The yat library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License as
12  published by the Free Software Foundation; either version 2 of the
13  License, or (at your option) any later version.
14
15  The yat library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23  02111-1307, USA.
24*/
25
26#include "PolynomialKernelFunction.h"
27#include "DataLookup1D.h"
28#include "DataLookupWeighted1D.h"
29#include "yat/statistics/AveragerPairWeighted.h"
30
31#include <cassert>
32#include <cmath>
33
34namespace theplu {
35namespace yat {
36namespace classifier { 
37
38PolynomialKernelFunction::PolynomialKernelFunction(int order) 
39  : KernelFunction(), order_(order)
40{
41}
42
43
44double PolynomialKernelFunction::operator()(const DataLookup1D& x,
45                                            const DataLookup1D& y) const   
46{ 
47  assert(x.size()==y.size());
48  return ((order_>1) ? pow(1+x*y,order_) : x*y); 
49}
50
51
52double PolynomialKernelFunction::operator()(const DataLookup1D& x,
53                                            const DataLookupWeighted1D& y) const
54{ 
55  assert(x.size()==y.size());
56  statistics::AveragerPairWeighted averager;
57  add(averager, x.begin(),x.end(), y.begin());
58  if(order_>1) 
59    return pow(1+averager.sum_xy(),order_);
60  return averager.sum_xy();
61}
62
63
64double PolynomialKernelFunction::operator()(const DataLookupWeighted1D& x,
65                                            const DataLookupWeighted1D& y) const
66{ 
67  assert(x.size()==y.size());
68  statistics::AveragerPairWeighted averager;
69  add(averager, x.begin(), x.end(),y.begin());
70  if(order_>1) 
71    return pow(1+averager.sum_xy(),order_);
72  return averager.sum_xy();
73}
74
75
76}}} // of namespace cpptools, yat, and theplu
Note: See TracBrowser for help on using the repository browser.