[25] | 1 | // $Id$ |
---|

| 2 | |
---|

[450] | 3 | #include <c++_tools/classifier/PolynomialKernelFunction.h> |
---|

[527] | 4 | #include <c++_tools/classifier/DataLookup1D.h> |
---|

[627] | 5 | #include <c++_tools/classifier/DataLookupWeighted1D.h> |
---|

[295] | 6 | |
---|

[524] | 7 | #include <c++_tools/statistics/AveragerPairWeighted.h> |
---|

[295] | 8 | |
---|

[345] | 9 | #include <cmath> |
---|

[25] | 10 | |
---|

| 11 | |
---|

[42] | 12 | namespace theplu { |
---|

[450] | 13 | namespace classifier { |
---|

[42] | 14 | |
---|

[25] | 15 | PolynomialKernelFunction::PolynomialKernelFunction(int order) |
---|

| 16 | : KernelFunction(), order_(order) |
---|

| 17 | { |
---|

| 18 | } |
---|

| 19 | |
---|

[627] | 20 | |
---|

| 21 | double 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 | |
---|

| 29 | double 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 | |
---|

| 41 | double 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 | |
---|

[527] | 53 | double PolynomialKernelFunction::operator()(const DataLookup1D& a1, |
---|

| 54 | const DataLookup1D& a2, |
---|

| 55 | const DataLookup1D& w1, |
---|

| 56 | const DataLookup1D& w2) const |
---|

[67] | 57 | { |
---|

[524] | 58 | statistics::AveragerPairWeighted averager; |
---|

[527] | 59 | for (size_t i=0; i<a1.size(); i++) |
---|

| 60 | averager.add(a1(i),a2(i),w1(i),w2(i)); |
---|

[524] | 61 | |
---|

[67] | 62 | if(order_>1) |
---|

[627] | 63 | return pow(1+averager.sum_xy(),order_); |
---|

| 64 | return averager.sum_xy(); |
---|

[67] | 65 | } |
---|

| 66 | |
---|

[42] | 67 | }} // of namespace cpptools and namespace theplu |
---|