Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "lib/config.h"
00012
00013 #include "lib/common.h"
00014 #include "lib/io.h"
00015 #include "kernel/DistanceKernel.h"
00016 #include "features/SimpleFeatures.h"
00017
00018 using namespace shogun;
00019
00020 CDistanceKernel::CDistanceKernel(void)
00021 : CKernel(0), distance(NULL), width(0.0)
00022 {
00023 SG_UNSTABLE("CDistanceKernel::CDistanceKernel(void)", "\n");
00024 }
00025
00026 CDistanceKernel::CDistanceKernel(int32_t size, float64_t w, CDistance* d)
00027 : CKernel(size), distance(d), width(w)
00028 {
00029 ASSERT(distance);
00030 SG_REF(distance);
00031 }
00032
00033 CDistanceKernel::CDistanceKernel(
00034 CFeatures *l, CFeatures *r, float64_t w , CDistance* d)
00035 : CKernel(10), distance(d), width(w)
00036 {
00037 ASSERT(distance);
00038 SG_REF(distance);
00039 init(l, r);
00040 }
00041
00042 CDistanceKernel::~CDistanceKernel()
00043 {
00044
00045
00046 cleanup();
00047 SG_UNREF(distance);
00048 }
00049
00050 bool CDistanceKernel::init(CFeatures* l, CFeatures* r)
00051 {
00052 ASSERT(distance);
00053 CKernel::init(l,r);
00054 distance->init(l,r);
00055 return init_normalizer();
00056 }
00057
00058 float64_t CDistanceKernel::compute(int32_t idx_a, int32_t idx_b)
00059 {
00060 float64_t result=distance->distance(idx_a, idx_b);
00061 return exp(-result/width);
00062 }