SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
virtual void cleanup()
Definition: Kernel.cpp:173
virtual bool init(CFeatures *l, CFeatures *r)
Definition: PolyKernel.cpp:47
virtual bool set_normalizer(CKernelNormalizer *normalizer)
Definition: Kernel.cpp:150
virtual float64_t compute(int32_t idx_a, int32_t idx_b)
Definition: DotKernel.h:134
Features that support dot products among other operations.
Definition: DotFeatures.h:44
Template class DotKernel is the base class for kernels working on DotFeatures.
Definition: DotKernel.h:31
virtual float64_t compute(int32_t idx_a, int32_t idx_b)
Definition: PolyKernel.cpp:58
double float64_t
Definition: common.h:50
virtual bool init_normalizer()
Definition: Kernel.cpp:168
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
The class Features is the base class of all feature objects.
Definition: Features.h:68
virtual void cleanup()
Definition: PolyKernel.cpp:53
#define SG_ADD(...)
Definition: SGObject.h:84
friend class CSqrtDiagKernelNormalizer
Definition: Kernel.h:162
static int32_t pow(bool x, int32_t n)
Definition: Math.h:535
virtual ~CPolyKernel()
Definition: PolyKernel.cpp:42

SHOGUN Machine Learning Toolbox - Documentation