23 #ifndef _KERNEL_HAMMING_HPP_ 24 #define _KERNEL_HAMMING_HPP_ 40 void init(
size_t input_dim)
41 { n_params = 1; n_inputs = input_dim; };
43 size_t hammingDistance(
const vectori& s1,
const vectori& s2)
46 vectori::const_iterator i1;
47 vectori::const_iterator i2;
48 for( i1 = s1.begin(), i2 = s2.begin();
49 i1 < s1.end() && i2 < s2.end();
52 hdist += (*i1 == *i2) ? 0 : 1;
57 double operator()(
const vectord &x1,
const vectord &x2)
59 const size_t n = x1.size();
60 const double coef = -params(0)/2.0;
64 for(
size_t i=0; i<n; ++i)
67 s1(i) =
static_cast<int>(x1(i)+0.5);
68 s2(i) =
static_cast<int>(x2(i)+0.5);
71 const double dist =
static_cast<double>(hammingDistance(s1,s2));
72 return std::exp(coef*dist*dist);
75 double gradient(
const vectord &x1,
const vectord &x2,
Namespace of the library interface.
Kernel for categorical data.
Atomic (simple) kernel functions.
Abstract class for an atomic kernel.