# source:trunk/lib/svm/PolynomialKernelFunction.cc@353

Last change on this file since 353 was 353, checked in by Peter, 17 years ago

removed function returning the whole matrix. It is not needed anymore and should not be there for simplistic reasons.

• Property svn:eol-style set to `native`
• Property svn:keywords set to `Author Date Id Revision`
File size: 942 bytes
Line
1// \$Id: PolynomialKernelFunction.cc 353 2005-06-08 23:28:35Z peter \$
2
3
4#include <c++_tools/svm/PolynomialKernelFunction.h>
5
6#include <c++_tools/gslapi/matrix.h>
7#include <c++_tools/gslapi/vector.h>
8
9#include <cmath>
10
11
12namespace theplu {
13namespace svm {
14
15PolynomialKernelFunction::PolynomialKernelFunction(int order)
16  : KernelFunction(), order_(order)
17{
18}
19
20double PolynomialKernelFunction::operator()(const gslapi::vector& a1,
21                                            const gslapi::vector& a2,
22                                            const gslapi::vector& w1,
23                                            const gslapi::vector& w2) const
24{
25  double scalar = 0;
26  double normalization_factor = 0;
27  for (size_t i=0; i<a1.size(); i++) {
28    scalar += w1(i) * w2(i) * a1(i) * a2(i);
29    normalization_factor += w1(i) * w2(i);
30  }
31// to make it coherent with no weight case
32  normalization_factor /= a1.size();
33  if(order_>1)
34    return pow(scalar/normalization_factor,order_);
35  return scalar/normalization_factor;
36}
37
38}} // of namespace cpptools and namespace theplu
Note: See TracBrowser for help on using the repository browser.