PowerKernel.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) 2011 Jakub Jirku
00008  * Copyright (C) 2007-2011 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 
00011 #include <shogun/kernel/PowerKernel.h>
00012 #include <shogun/mathematics/Math.h>
00013 
00014 using namespace shogun;
00015 
00016 CPowerKernel::CPowerKernel(): CKernel(0), distance(NULL), m_degree(1.8)
00017 {
00018     init();
00019 }
00020 
00021 CPowerKernel::CPowerKernel(int32_t cache, float64_t degree, CDistance* dist)
00022 : CKernel(cache), distance(dist), m_degree(degree)
00023 {
00024     init();
00025     ASSERT(distance);
00026     SG_REF(distance);
00027 }
00028 
00029 CPowerKernel::CPowerKernel(CFeatures *l, CFeatures *r, float64_t degree, CDistance* dist)
00030 : CKernel(10), distance(dist), m_degree(degree)
00031 {
00032     init();
00033     ASSERT(distance);
00034     SG_REF(distance);
00035     init(l, r);
00036 }
00037 
00038 CPowerKernel::~CPowerKernel()
00039 {
00040     cleanup();
00041     SG_UNREF(distance);
00042 }
00043 
00044 bool CPowerKernel::init(CFeatures* l, CFeatures* r)
00045 {
00046     ASSERT(distance);
00047     CKernel::init(l,r);
00048     distance->init(l,r);
00049     return init_normalizer();
00050 }
00051 
00052 void CPowerKernel::init()
00053 {
00054     SG_ADD(&m_degree, "degree", "Degree kernel parameter.", MS_AVAILABLE);
00055     SG_ADD((CSGObject**) &distance, "distance", "Distance to be used.",
00056             MS_AVAILABLE);
00057 }
00058 
00059 float64_t CPowerKernel::compute(int32_t idx_a, int32_t idx_b)
00060 {
00061     float64_t dist = distance->distance(idx_a, idx_b);  
00062     float64_t temp = pow(dist, m_degree);
00063     return -temp;
00064 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation