Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <shogun/lib/common.h>
00012 #include <shogun/kernel/WaveletKernel.h>
00013 #include <shogun/features/SimpleFeatures.h>
00014
00015 using namespace shogun;
00016
00017 CWaveletKernel::CWaveletKernel() : CDotKernel(), Wdilation(0.0), Wtranslation(0.0)
00018 {
00019 init();
00020 }
00021
00022 CWaveletKernel::CWaveletKernel(int32_t size, float64_t a, float64_t c)
00023 : CDotKernel(size), Wdilation(a), Wtranslation(c)
00024 {
00025 init();
00026 }
00027
00028 CWaveletKernel::CWaveletKernel(
00029 CDotFeatures* l, CDotFeatures* r, int32_t size, float64_t a, float64_t c)
00030 : CDotKernel(size), Wdilation(a), Wtranslation(c)
00031 {
00032 init();
00033 init(l,r);
00034 }
00035
00036 CWaveletKernel::~CWaveletKernel()
00037 {
00038 cleanup();
00039 }
00040
00041 void CWaveletKernel::cleanup()
00042 {
00043 }
00044
00045 bool CWaveletKernel::init(CFeatures* l, CFeatures* r)
00046 {
00047 CDotKernel::init(l, r);
00048 return init_normalizer();
00049 }
00050
00051 void CWaveletKernel::init()
00052 {
00053 m_parameters->add(&Wdilation, "Wdilation", "Dilation coefficient");
00054 m_parameters->add(&Wtranslation, "Wtranslaton", "Translation coefficient");
00055 }
00056
00057 float64_t CWaveletKernel::compute(int32_t idx_a, int32_t idx_b)
00058 {
00059 int32_t alen, blen;
00060 bool afree, bfree;
00061
00062 float64_t* avec=
00063 ((CSimpleFeatures<float64_t>*) lhs)->get_feature_vector(idx_a, alen, afree);
00064 float64_t* bvec=
00065 ((CSimpleFeatures<float64_t>*) rhs)->get_feature_vector(idx_b, blen, bfree);
00066 ASSERT(alen==blen);
00067
00068 float64_t result=1;
00069
00070 for (int32_t i=0; i<alen; i++)
00071 {
00072 if (Wtranslation !=0)
00073 {
00074 float64_t h1=(avec[i]-Wdilation)/Wtranslation;
00075 float64_t h2=(bvec[i]-Wdilation)/Wtranslation;
00076 float64_t res1=MotherWavelet(h1);
00077 float64_t res2=MotherWavelet(h2);
00078 result=result*res1*res2;
00079 }
00080 }
00081
00082 ((CSimpleFeatures<float64_t>*) lhs)->free_feature_vector(avec, idx_a, afree);
00083 ((CSimpleFeatures<float64_t>*) rhs)->free_feature_vector(bvec, idx_b, bfree);
00084
00085 return result;
00086 }