SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PolyKernel.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 1999-2010 Soeren Sonnenburg
8  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9  * Copyright (C) 2010 Berlin Institute of Technology
10  */
11 
12 #include <shogun/lib/config.h>
13 #include <shogun/lib/common.h>
14 #include <shogun/io/SGIO.h>
18 
19 using namespace shogun;
20 
22 : CDotKernel(0), degree(0), inhomogene(false)
23 {
24  init();
25 
27 }
28 
29 CPolyKernel::CPolyKernel(int32_t size, int32_t d, bool i)
30 : CDotKernel(size), degree(d), inhomogene(i)
31 {
32  init();
33 
35 }
36 
38  CDotFeatures* l, CDotFeatures* r, int32_t d, bool i, int32_t size)
39 : CDotKernel(size), degree(d), inhomogene(i)
40 {
41  init();
42 
44  init(l,r);
45 }
46 
48 {
49  cleanup();
50 }
51 
52 bool CPolyKernel::init(CFeatures* l, CFeatures* r)
53 {
54  CDotKernel::init(l,r);
55  return init_normalizer();
56 }
57 
59 {
61 }
62 
63 float64_t CPolyKernel::compute(int32_t idx_a, int32_t idx_b)
64 {
65  float64_t result=CDotKernel::compute(idx_a, idx_b);
66 
67  if (inhomogene)
68  result+=1;
69 
70  return CMath::pow(result, degree);
71 }
72 
73 void CPolyKernel::init()
74 {
75  SG_ADD(&degree, "degree", "Degree of polynomial kernel", MS_AVAILABLE);
76  SG_ADD(&inhomogene, "inhomogene", "If kernel is inhomogeneous.",
78 }
79 

SHOGUN Machine Learning Toolbox - Documentation