SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  m_parameters->add(&degree, "degree");
76  m_parameters->add(&inhomogene, "inhomogene",
77  "If kernel is inhomogeneous.");
78 }
79 
virtual void cleanup()
Definition: Kernel.cpp:138
virtual bool init(CFeatures *l, CFeatures *r)
Definition: PolyKernel.cpp:52
virtual bool set_normalizer(CKernelNormalizer *normalizer)
Definition: Kernel.cpp:115
Parameter * m_parameters
Definition: SGObject.h:297
virtual float64_t compute(int32_t idx_a, int32_t idx_b)
Definition: DotKernel.h:121
Features that support dot products among other operations.
Definition: DotFeatures.h:41
Template class DotKernel is the base class for kernels working on DotFeatures.
Definition: DotKernel.h:29
void add(bool *param, const char *name, const char *description="")
Definition: Parameter.cpp:23
static int32_t pow(int32_t x, int32_t n)
Definition: Math.h:339
virtual float64_t compute(int32_t idx_a, int32_t idx_b)
Definition: PolyKernel.cpp:63
double float64_t
Definition: common.h:56
virtual bool init_normalizer()
Definition: Kernel.cpp:133
The class Features is the base class of all feature objects.
Definition: Features.h:56
virtual void cleanup()
Definition: PolyKernel.cpp:58
friend class CSqrtDiagKernelNormalizer
Definition: Kernel.h:175
virtual ~CPolyKernel()
Definition: PolyKernel.cpp:47

SHOGUN Machine Learning Toolbox - Documentation