25 |
06 Aug 03 |
peter |
// $Id$ |
25 |
06 Aug 03 |
peter |
2 |
|
675 |
10 Oct 06 |
jari |
3 |
/* |
831 |
27 Mar 07 |
peter |
Copyright (C) 2003 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2004, 2005, 2006 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2012 Peter Johansson |
295 |
29 Apr 05 |
peter |
9 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
295 |
29 Apr 05 |
peter |
11 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
675 |
10 Oct 06 |
jari |
16 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 |
10 Oct 06 |
jari |
General Public License for more details. |
675 |
10 Oct 06 |
jari |
21 |
|
675 |
10 Oct 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
675 |
10 Oct 06 |
jari |
24 |
*/ |
675 |
10 Oct 06 |
jari |
25 |
|
2881 |
18 Nov 12 |
peter |
26 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
27 |
|
680 |
11 Oct 06 |
jari |
28 |
#include "PolynomialKernelFunction.h" |
680 |
11 Oct 06 |
jari |
29 |
#include "DataLookup1D.h" |
680 |
11 Oct 06 |
jari |
30 |
#include "DataLookupWeighted1D.h" |
675 |
10 Oct 06 |
jari |
31 |
#include "yat/statistics/AveragerPairWeighted.h" |
675 |
10 Oct 06 |
jari |
32 |
|
781 |
05 Mar 07 |
peter |
33 |
#include <cassert> |
345 |
08 Jun 05 |
jari |
34 |
#include <cmath> |
25 |
06 Aug 03 |
peter |
35 |
|
42 |
26 Feb 04 |
jari |
36 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
37 |
namespace yat { |
4200 |
19 Aug 22 |
peter |
38 |
namespace classifier { |
42 |
26 Feb 04 |
jari |
39 |
|
4200 |
19 Aug 22 |
peter |
40 |
PolynomialKernelFunction::PolynomialKernelFunction(int order) |
25 |
06 Aug 03 |
peter |
41 |
: KernelFunction(), order_(order) |
25 |
06 Aug 03 |
peter |
42 |
{ |
25 |
06 Aug 03 |
peter |
43 |
} |
25 |
06 Aug 03 |
peter |
44 |
|
627 |
05 Sep 06 |
peter |
45 |
|
627 |
05 Sep 06 |
peter |
46 |
double PolynomialKernelFunction::operator()(const DataLookup1D& x, |
4200 |
19 Aug 22 |
peter |
47 |
const DataLookup1D& y) const |
4200 |
19 Aug 22 |
peter |
48 |
{ |
627 |
05 Sep 06 |
peter |
49 |
assert(x.size()==y.size()); |
4200 |
19 Aug 22 |
peter |
50 |
return ((order_>1) ? pow(1+x*y,order_) : x*y); |
627 |
05 Sep 06 |
peter |
51 |
} |
627 |
05 Sep 06 |
peter |
52 |
|
627 |
05 Sep 06 |
peter |
53 |
|
627 |
05 Sep 06 |
peter |
54 |
double PolynomialKernelFunction::operator()(const DataLookup1D& x, |
627 |
05 Sep 06 |
peter |
55 |
const DataLookupWeighted1D& y) const |
4200 |
19 Aug 22 |
peter |
56 |
{ |
627 |
05 Sep 06 |
peter |
57 |
assert(x.size()==y.size()); |
627 |
05 Sep 06 |
peter |
58 |
statistics::AveragerPairWeighted averager; |
1043 |
06 Feb 08 |
peter |
59 |
add(averager, x.begin(),x.end(), y.begin()); |
4200 |
19 Aug 22 |
peter |
60 |
if(order_>1) |
627 |
05 Sep 06 |
peter |
61 |
return pow(1+averager.sum_xy(),order_); |
627 |
05 Sep 06 |
peter |
62 |
return averager.sum_xy(); |
627 |
05 Sep 06 |
peter |
63 |
} |
627 |
05 Sep 06 |
peter |
64 |
|
627 |
05 Sep 06 |
peter |
65 |
|
627 |
05 Sep 06 |
peter |
66 |
double PolynomialKernelFunction::operator()(const DataLookupWeighted1D& x, |
627 |
05 Sep 06 |
peter |
67 |
const DataLookupWeighted1D& y) const |
4200 |
19 Aug 22 |
peter |
68 |
{ |
627 |
05 Sep 06 |
peter |
69 |
assert(x.size()==y.size()); |
627 |
05 Sep 06 |
peter |
70 |
statistics::AveragerPairWeighted averager; |
1043 |
06 Feb 08 |
peter |
71 |
add(averager, x.begin(), x.end(),y.begin()); |
4200 |
19 Aug 22 |
peter |
72 |
if(order_>1) |
627 |
05 Sep 06 |
peter |
73 |
return pow(1+averager.sum_xy(),order_); |
627 |
05 Sep 06 |
peter |
74 |
return averager.sum_xy(); |
627 |
05 Sep 06 |
peter |
75 |
} |
627 |
05 Sep 06 |
peter |
76 |
|
627 |
05 Sep 06 |
peter |
77 |
|
680 |
11 Oct 06 |
jari |
78 |
}}} // of namespace cpptools, yat, and theplu |