SHOGUN  3.2.1
 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 
26 }
27 
28 CPolyKernel::CPolyKernel(int32_t size, int32_t d, bool i)
29 : CDotKernel(size), degree(d), inhomogene(i)
30 {
31  init();
32 }
33 
35  CDotFeatures* l, CDotFeatures* r, int32_t d, bool i, int32_t size)
36 : CDotKernel(size), degree(d), inhomogene(i)
37 {
38  init();
39  init(l,r);
40 }
41 
43 {
44  cleanup();
45 }
46 
47 bool CPolyKernel::init(CFeatures* l, CFeatures* r)
48 {
49  CDotKernel::init(l,r);
50  return init_normalizer();
51 }
52 
54 {
56 }
57 
58 float64_t CPolyKernel::compute(int32_t idx_a, int32_t idx_b)
59 {
60  float64_t result=CDotKernel::compute(idx_a, idx_b);
61 
62  if (inhomogene)
63  result+=1;
64 
65  return CMath::pow(result, degree);
66 }
67 
68 void CPolyKernel::init()
69 {
71  SG_ADD(&degree, "degree", "Degree of polynomial kernel", MS_AVAILABLE);
72  SG_ADD(&inhomogene, "inhomogene", "If kernel is inhomogeneous.",
74 }
75 

SHOGUN Machine Learning Toolbox - Documentation