SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WaveletKernel.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 Siddharth Kherada
8  * Copyright (C) 2007-2011 Fraunhofer Institute FIRST and Max-Planck-Society
9  */
10 
11 #include <shogun/lib/common.h>
14 
15 using namespace shogun;
16 
17 CWaveletKernel::CWaveletKernel() : CDotKernel(), Wdilation(0.0), Wtranslation(0.0)
18 {
19  init();
20 }
21 
23 : CDotKernel(size), Wdilation(a), Wtranslation(c)
24 {
25  init();
26 }
27 
29  CDotFeatures* l, CDotFeatures* r, int32_t size, float64_t a, float64_t c)
30 : CDotKernel(size), Wdilation(a), Wtranslation(c)
31 {
32  init();
33  init(l,r);
34 }
35 
37 {
38  cleanup();
39 }
40 
42 {
43 }
44 
45 bool CWaveletKernel::init(CFeatures* l, CFeatures* r)
46 {
47  CDotKernel::init(l, r);
48  return init_normalizer();
49 }
50 
51 void CWaveletKernel::init()
52 {
53  SG_ADD(&Wdilation, "Wdilation", "Dilation coefficient", MS_AVAILABLE);
54  SG_ADD(&Wtranslation, "Wtranslaton", "Translation coefficient", MS_AVAILABLE);
55 }
56 
57 float64_t CWaveletKernel::compute(int32_t idx_a, int32_t idx_b)
58 {
59  int32_t alen, blen;
60  bool afree, bfree;
61 
62  float64_t* avec=
63  ((CDenseFeatures<float64_t>*) lhs)->get_feature_vector(idx_a, alen, afree);
64  float64_t* bvec=
65  ((CDenseFeatures<float64_t>*) rhs)->get_feature_vector(idx_b, blen, bfree);
66  ASSERT(alen==blen)
67 
68  float64_t result=1;
69 
70  for (int32_t i=0; i<alen; i++)
71  {
72  if (Wtranslation !=0)
73  {
74  float64_t h1=(avec[i]-Wdilation)/Wtranslation;
75  float64_t h2=(bvec[i]-Wdilation)/Wtranslation;
76  float64_t res1=MotherWavelet(h1);
77  float64_t res2=MotherWavelet(h2);
78  result=result*res1*res2;
79  }
80  }
81 
82  ((CDenseFeatures<float64_t>*) lhs)->free_feature_vector(avec, idx_a, afree);
83  ((CDenseFeatures<float64_t>*) rhs)->free_feature_vector(bvec, idx_b, bfree);
84 
85  return result;
86 }

SHOGUN Machine Learning Toolbox - Documentation