source: trunk/src/PolynomialKernelFunction.cc @ 25

Last change on this file since 25 was 25, checked in by Peter, 19 years ago

to calculate Kernel Matrix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.0 KB
Line 
1// $Id: PolynomialKernelFunction.cc 25 2003-08-06 17:38:17Z peter $
2
3// System
4#include <math.h>
5
6
7// Thep C++ Tools
8#include "PolynomialKernelFunction.h"
9#include "vector.h"
10
11using namespace thep_cpp_tools;
12using namespace std;
13
14PolynomialKernelFunction::PolynomialKernelFunction(int order) 
15  : KernelFunction(), order_(order)
16{
17}
18
19double PolynomialKernelFunction::operator()(const thep_gsl_api::vector a,
20              const thep_gsl_api::vector b) const   
21{
22  u_int nof_valid_datapairs = 0;
23  double tmp = 0;
24  // check that a size == b size !
25  if(a.size() != b.size())
26    cerr << "vectors must have same length\n";
27  for(u_int k=0; k<a.size(); k++)
28    // Check that both a and b are Numbers (NaN is NOT equal to NaN)
29    if (a.get(k) == a.get(k) & b.get(k) == b.get(k)) {
30     tmp += a.get(k)*b.get(k);
31     nof_valid_datapairs++;
32    }
33  cout << nof_valid_datapairs << endl;
34  if (nof_valid_datapairs == 0)
35    cerr << "data file error: two columns " 
36   << " have no pair of valid data\n";
37  tmp/=nof_valid_datapairs * a.size();
38  if(order_>1) 
39    return pow(1+tmp,order_);
40  return tmp;
41}
42
Note: See TracBrowser for help on using the repository browser.