Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <shogun/kernel/WaveKernel.h>
00012 #include <shogun/mathematics/Math.h>
00013
00014 using namespace shogun;
00015
00016 CWaveKernel::CWaveKernel(): CKernel(0), m_distance(NULL), m_theta(1.0)
00017 {
00018 init();
00019 }
00020
00021 CWaveKernel::CWaveKernel(int32_t cache, float64_t theta, CDistance* dist)
00022 : CKernel(cache), m_distance(dist), m_theta(theta)
00023 {
00024 init();
00025 ASSERT(m_distance);
00026 SG_REF(m_distance);
00027 }
00028
00029 CWaveKernel::CWaveKernel(CFeatures *l, CFeatures *r, float64_t theta, CDistance* dist)
00030 : CKernel(10), m_distance(dist), m_theta(theta)
00031 {
00032 init();
00033 ASSERT(m_distance);
00034 SG_REF(m_distance);
00035 init(l, r);
00036 }
00037
00038 CWaveKernel::~CWaveKernel()
00039 {
00040 cleanup();
00041 SG_UNREF(m_distance);
00042 }
00043
00044 bool CWaveKernel::init(CFeatures* l, CFeatures* r)
00045 {
00046 ASSERT(m_distance);
00047 CKernel::init(l,r);
00048 m_distance->init(l,r);
00049 return init_normalizer();
00050 }
00051
00052 void CWaveKernel::init()
00053 {
00054 SG_ADD(&m_theta, "theta", "Theta kernel parameter.", MS_AVAILABLE);
00055 SG_ADD((CSGObject**) &m_distance, "distance", "Distance to be used.",
00056 MS_AVAILABLE);
00057 }
00058
00059 float64_t CWaveKernel::compute(int32_t idx_a, int32_t idx_b)
00060 {
00061 float64_t dist = m_distance->distance(idx_a, idx_b);
00062
00063 if (dist==0.0)
00064 return 1.0;
00065
00066 return (m_theta/dist)*sin(dist/m_theta);
00067 }