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