Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <shogun/lib/common.h>
00015 #include <shogun/base/Parameter.h>
00016 #include <shogun/kernel/ExponentialKernel.h>
00017 #include <shogun/features/DotFeatures.h>
00018 #include <shogun/io/SGIO.h>
00019
00020 using namespace shogun;
00021
00022 CExponentialKernel::CExponentialKernel()
00023 : CDotKernel(), m_distance(NULL), m_width(1)
00024 {
00025 init();
00026 }
00027
00028 CExponentialKernel::CExponentialKernel(
00029 CDotFeatures* l, CDotFeatures* r, float64_t width, CDistance* distance, int32_t size)
00030 : CDotKernel(size), m_distance(distance), m_width(width)
00031 {
00032 init();
00033 ASSERT(distance);
00034 SG_REF(distance);
00035 init(l,r);
00036 }
00037
00038 CExponentialKernel::~CExponentialKernel()
00039 {
00040 cleanup();
00041 SG_UNREF(m_distance);
00042 }
00043
00044 void CExponentialKernel::cleanup()
00045 {
00046 CKernel::cleanup();
00047 }
00048
00049 bool CExponentialKernel::init(CFeatures* l, CFeatures* r)
00050 {
00051 ASSERT(m_distance);
00052 CDotKernel::init(l, r);
00053 m_distance->init(l, r);
00054 return init_normalizer();
00055 }
00056
00057 float64_t CExponentialKernel::compute(int32_t idx_a, int32_t idx_b)
00058 {
00059 ASSERT(m_distance);
00060 float64_t dist=m_distance->distance(idx_a, idx_b);
00061 return exp(-dist/m_width);
00062 }
00063
00064 void CExponentialKernel::load_serializable_post() throw (ShogunException)
00065 {
00066 CKernel::load_serializable_post();
00067 }
00068
00069
00070 void CExponentialKernel::init()
00071 {
00072 m_parameters->add(&m_width, "width", "Kernel width.");
00073 m_parameters->add((CSGObject**) &m_distance, "distance", "Distance to be used.");
00074 }