MCPcopy Create free account
hub / github.com/Xtra-Computing/thundersvm / get_cpu_kernel

Function get_cpu_kernel

src/test/test_kernelmatrix.cpp:26–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24}
25
26kernel_type get_cpu_kernel(const DataSet::node2d &instances, int x, int y, const SvmParam &param) {
27 kernel_type r;
28 switch (param.kernel_type) {
29 case SvmParam::RBF: {
30 float_type sum = 0;
31 auto i = instances[x].begin();
32 auto j = instances[y].begin();
33 while (i != instances[x].end() && j != instances[y].end()) {
34 if (i->index < j->index) {
35 sum += i->value * i->value;
36 i++;
37 } else if (i->index > j->index) {
38 sum += j->value * j->value;
39 j++;
40 } else {
41 sum += (i->value - j->value) * (i->value - j->value);
42 i++;
43 j++;
44 }
45 }
46 while (i != instances[x].end()) {
47 sum += i->value * i->value;
48 i++;
49 }
50 while (j != instances[y].end()) {
51 sum += j->value * j->value;
52 j++;
53 }
54 r = expf(-param.gamma * sum);
55 break;
56 }
57 case SvmParam::POLY:
58 r = powf(param.gamma * dot_product(instances, x, y) + param.coef0, param.degree);
59 break;
60 case SvmParam::LINEAR:
61 r = dot_product(instances, x, y);
62 break;
63 case SvmParam::SIGMOID:
64 r = tanhf(param.gamma * dot_product(instances, x, y) + param.coef0);
65 }
66 return r;
67}
68
69class KernelMatrixTest : public ::testing::Test {
70 DataSet dataSet;

Callers 1

TearDownMethod · 0.85

Calls 3

dot_productFunction · 0.85
endMethod · 0.80
beginMethod · 0.45

Tested by

no test coverage detected