SHOGUN
v1.1.0
|
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 Andrew Tereskin 00008 * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society 00009 */ 00010 00011 #include <math.h> 00012 #include <shogun/kernel/TStudentKernel.h> 00013 #include <shogun/mathematics/Math.h> 00014 00015 using namespace shogun; 00016 00017 void CTStudentKernel::init() 00018 { 00019 m_parameters->add(°ree, "degree", "Kernel degree."); 00020 m_parameters->add((CSGObject**) &distance, "distance", "Distance to be used."); 00021 } 00022 00023 CTStudentKernel::CTStudentKernel(): CKernel(0), distance(NULL), degree(1.0) 00024 { 00025 init(); 00026 } 00027 00028 CTStudentKernel::CTStudentKernel(int32_t cache, float64_t d, CDistance* dist) 00029 : CKernel(cache), distance(dist), degree(d) 00030 { 00031 init(); 00032 ASSERT(distance); 00033 SG_REF(distance); 00034 } 00035 00036 CTStudentKernel::CTStudentKernel(CFeatures *l, CFeatures *r, float64_t d, CDistance* dist) 00037 : CKernel(10), distance(dist), degree(d) 00038 { 00039 init(); 00040 ASSERT(distance); 00041 SG_REF(distance); 00042 init(l, r); 00043 } 00044 00045 CTStudentKernel::~CTStudentKernel() 00046 { 00047 cleanup(); 00048 SG_UNREF(distance); 00049 } 00050 00051 bool CTStudentKernel::init(CFeatures* l, CFeatures* r) 00052 { 00053 ASSERT(distance); 00054 CKernel::init(l,r); 00055 distance->init(l,r); 00056 return init_normalizer(); 00057 } 00058 00059 float64_t CTStudentKernel::compute(int32_t idx_a, int32_t idx_b) 00060 { 00061 float64_t dist = distance->distance(idx_a, idx_b); 00062 return 1.0/(1.0+CMath::pow(dist, this->degree)); 00063 }