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