SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TStudentKernel.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 Andrew Tereskin
8  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
9  */
10 
11 #include <math.h>
14 
15 using namespace shogun;
16 
17 void CTStudentKernel::init()
18 {
19  SG_ADD(&degree, "degree", "Kernel degree.", MS_AVAILABLE);
20  SG_ADD((CSGObject**) &distance, "distance", "Distance to be used.",
21  MS_AVAILABLE);
22 }
23 
25 {
26  init();
27 }
28 
30 : CKernel(cache), distance(dist), degree(d)
31 {
32  init();
35 }
36 
38 : CKernel(10), distance(dist), degree(d)
39 {
40  init();
43  init(l, r);
44 }
45 
47 {
48  cleanup();
50 }
51 
52 bool CTStudentKernel::init(CFeatures* l, CFeatures* r)
53 {
55  CKernel::init(l,r);
56  distance->init(l,r);
57  return init_normalizer();
58 }
59 
60 float64_t CTStudentKernel::compute(int32_t idx_a, int32_t idx_b)
61 {
62  float64_t dist = distance->distance(idx_a, idx_b);
63  return 1.0/(1.0+CMath::pow(dist, this->degree));
64 }

SHOGUN Machine Learning Toolbox - Documentation