DistanceKernel.cpp
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 CDistanceKernel::CDistanceKernel(int32_t size, float64_t w, CDistance* d)
00019 : CKernel(size), distance(d), width(w)
00020 {
00021 ASSERT(distance);
00022 SG_REF(distance);
00023 }
00024
00025 CDistanceKernel::CDistanceKernel(
00026 CFeatures *l, CFeatures *r, float64_t w , CDistance* d)
00027 : CKernel(10), distance(d), width(w)
00028 {
00029 ASSERT(distance);
00030 SG_REF(distance);
00031 init(l, r);
00032 }
00033
00034 CDistanceKernel::~CDistanceKernel()
00035 {
00036
00037
00038 cleanup();
00039 SG_UNREF(distance);
00040 }
00041
00042 bool CDistanceKernel::init(CFeatures* l, CFeatures* r)
00043 {
00044 ASSERT(distance);
00045 CKernel::init(l,r);
00046 distance->init(l,r);
00047 return init_normalizer();
00048 }
00049
00050 float64_t CDistanceKernel::compute(int32_t idx_a, int32_t idx_b)
00051 {
00052 float64_t result=distance->distance(idx_a, idx_b);
00053 return exp(-result/width);
00054 }
00055
00056 bool CDistanceKernel::load_init(FILE* src)
00057 {
00058 return false;
00059 }
00060
00061 bool CDistanceKernel::save_init(FILE* dest)
00062 {
00063 return false;
00064 }