SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PowerKernel.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) 2011 Jakub Jirku
8  * Copyright (C) 2007-2011 Fraunhofer Institute FIRST and Max-Planck-Society
9  */
10 
13 
14 using namespace shogun;
15 
16 CPowerKernel::CPowerKernel(): CKernel(0), distance(NULL), m_degree(1.8)
17 {
18  init();
19 }
20 
21 CPowerKernel::CPowerKernel(int32_t cache, float64_t degree, CDistance* dist)
22 : CKernel(cache), distance(dist), m_degree(degree)
23 {
24  init();
27 }
28 
30 : CKernel(10), distance(dist), m_degree(degree)
31 {
32  init();
35  init(l, r);
36 }
37 
39 {
40  cleanup();
42 }
43 
44 bool CPowerKernel::init(CFeatures* l, CFeatures* r)
45 {
47  CKernel::init(l,r);
48  distance->init(l,r);
49  return init_normalizer();
50 }
51 
52 void CPowerKernel::init()
53 {
54  SG_ADD(&m_degree, "degree", "Degree kernel parameter.", MS_AVAILABLE);
55  SG_ADD((CSGObject**) &distance, "distance", "Distance to be used.",
56  MS_AVAILABLE);
57 }
58 
59 float64_t CPowerKernel::compute(int32_t idx_a, int32_t idx_b)
60 {
61  float64_t dist = distance->distance(idx_a, idx_b);
62  float64_t temp = pow(dist, m_degree);
63  return -temp;
64 }
float distance(CJLCoverTreePoint p1, CJLCoverTreePoint p2, float64_t upper_bound)
virtual void cleanup()
Definition: Kernel.cpp:162
Class Distance, a base class for all the distances used in the Shogun toolbox.
Definition: Distance.h:81
CDistance * distance
distance to be used
Definition: PowerKernel.h:101
virtual bool init(CFeatures *l, CFeatures *r)
Definition: PowerKernel.cpp:44
#define SG_REF(x)
Definition: SGObject.h:51
#define ASSERT(x)
Definition: SGIO.h:201
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:112
double float64_t
Definition: common.h:50
float64_t m_degree
degree parameter of kernel
Definition: PowerKernel.h:104
virtual bool init_normalizer()
Definition: Kernel.cpp:157
virtual float64_t distance(int32_t idx_a, int32_t idx_b)
Definition: Distance.cpp:189
#define SG_UNREF(x)
Definition: SGObject.h:52
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual float64_t compute(int32_t idx_a, int32_t idx_b)
Definition: PowerKernel.cpp:59
The class Features is the base class of all feature objects.
Definition: Features.h:68
The Kernel base class.
Definition: Kernel.h:158
#define SG_ADD(...)
Definition: SGObject.h:81
virtual bool init(CFeatures *lhs, CFeatures *rhs)
Definition: Distance.cpp:78

SHOGUN Machine Learning Toolbox - Documentation