ExponentialKernel.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  * Gaussian Kernel used as template, attribution:
00008  * Written (W) 1999-2010 Soeren Sonnenburg
00009  * Exponential Kernel
00010  * Written (W) 2011 Justin Patera
00011  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
00012  */
00013 
00014 #include <shogun/lib/common.h>
00015 #include <shogun/base/Parameter.h>
00016 #include <shogun/kernel/ExponentialKernel.h>
00017 #include <shogun/features/DotFeatures.h>
00018 #include <shogun/io/SGIO.h>
00019 
00020 using namespace shogun;
00021 
00022 CExponentialKernel::CExponentialKernel()
00023     : CDotKernel(), m_distance(NULL), m_width(1)
00024 {
00025     init();
00026 }
00027 
00028 CExponentialKernel::CExponentialKernel(
00029     CDotFeatures* l, CDotFeatures* r, float64_t width, CDistance* distance, int32_t size)
00030 : CDotKernel(size), m_distance(distance), m_width(width)
00031 {
00032     init();
00033     ASSERT(distance);
00034     SG_REF(distance);
00035     init(l,r);
00036 }
00037 
00038 CExponentialKernel::~CExponentialKernel()
00039 {
00040     cleanup();
00041     SG_UNREF(m_distance);
00042 }
00043 
00044 void CExponentialKernel::cleanup()
00045 {
00046     CKernel::cleanup();
00047 }
00048 
00049 bool CExponentialKernel::init(CFeatures* l, CFeatures* r)
00050 {
00051     ASSERT(m_distance);
00052     CDotKernel::init(l, r);
00053     m_distance->init(l, r);
00054     return init_normalizer();
00055 }
00056 
00057 float64_t CExponentialKernel::compute(int32_t idx_a, int32_t idx_b)
00058 {
00059     ASSERT(m_distance);
00060     float64_t dist=m_distance->distance(idx_a, idx_b);
00061     return exp(-dist/m_width);
00062 }
00063 
00064 void CExponentialKernel::load_serializable_post() throw (ShogunException)
00065 {
00066     CKernel::load_serializable_post();
00067 }
00068 
00069 
00070 void CExponentialKernel::init()
00071 {
00072     m_parameters->add(&m_width, "width", "Kernel width.");
00073     m_parameters->add((CSGObject**) &m_distance, "distance", "Distance to be used.");
00074 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation