DistanceKernel.cpp

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2007 Christian Gehl
00008  * Copyright (C) 1999-2008 Fraunhofer Institute FIRST and Max-Planck-Society
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     // important to have the cleanup of CKernel first, it calls get_name which
00035     // uses the distance
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 }

SHOGUN Machine Learning Toolbox - Documentation