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-2009 Christian Gehl
00008  * Copyright (C) 2007-2009 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/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     // important to have the cleanup of CKernel first, it calls get_name which
00045     // uses the distance
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 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation