Ignore:
Timestamp:
Apr 27, 2004, 5:04:31 PM (18 years ago)
Author:
Peter
Message:

added choice to use weights for the calculation of kernel matrix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/PolynomialKernelFunction.cc

    r42 r67  
    1717}
    1818
    19 double PolynomialKernelFunction::operator()(const gslapi::vector& a,
    20                                             const gslapi::vector& b) const   
     19double PolynomialKernelFunction::operator()(const gslapi::vector& a1,
     20                                            const gslapi::vector& a2) const   
    2121{
    22   using namespace std;
     22  if(order_>1)
     23    return pow(a1*a2,order_);
     24  return a1*a2;
     25}
    2326
    24   u_int nof_valid_datapairs = 0;
    25   double tmp = 0;
    26   // check that a size == b size !
    27   if(a.size() != b.size())
    28     cerr << "vectors must have same length\n";
    29   for(u_int k=0; k<a.size(); k++)
    30     // Check that both a and b are Numbers (NaN is NOT equal to NaN)
    31     if (a(k) == a(k) & b(k) == b(k)) {
    32      tmp += a(k)*b(k);
    33      nof_valid_datapairs++;
    34     }
    35   //cout << nof_valid_datapairs << endl;
    36   if (nof_valid_datapairs == 0)
    37     cerr << "data file error: two columns "
    38    << " have no pair of valid data\n";
    39  
    40   tmp/=nof_valid_datapairs / a.size(); //correcting for missing values
    41  
    42   if(order_>1)
    43     return pow(1+tmp,order_);
    44   return tmp;
     27double PolynomialKernelFunction::operator()(const gslapi::vector& a1,
     28                                            const gslapi::vector& a2,
     29                                            const gslapi::vector& w1,
     30                                            const gslapi::vector& w2) const   
     31{
     32  double scalar = 0;
     33  double normalization_factor = 0;
     34  for (size_t i=0; i<a1.size(); i++) {
     35    scalar += w1(i) * w2(i) * a1(i) * a2(i);
     36    normalization_factor += w1(i) * w2(i);
     37  }
     38// to make it coherent with no weight case
     39  normalization_factor /= a1.size();
     40  if(order_>1)
     41    return pow(scalar/normalization_factor,order_);
     42  return scalar/normalization_factor;
    4543}
    4644
Note: See TracChangeset for help on using the changeset viewer.