SHOGUN
v3.2.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 SG_ADD(°ree, "degree", "Kernel degree.", MS_AVAILABLE); 00020 SG_ADD((CSGObject**) &distance, "distance", "Distance to be used.", 00021 MS_AVAILABLE); 00022 } 00023 00024 CTStudentKernel::CTStudentKernel(): CKernel(0), distance(NULL), degree(1.0) 00025 { 00026 init(); 00027 } 00028 00029 CTStudentKernel::CTStudentKernel(int32_t cache, float64_t d, CDistance* dist) 00030 : CKernel(cache), distance(dist), degree(d) 00031 { 00032 init(); 00033 ASSERT(distance) 00034 SG_REF(distance); 00035 } 00036 00037 CTStudentKernel::CTStudentKernel(CFeatures *l, CFeatures *r, float64_t d, CDistance* dist) 00038 : CKernel(10), distance(dist), degree(d) 00039 { 00040 init(); 00041 ASSERT(distance) 00042 SG_REF(distance); 00043 init(l, r); 00044 } 00045 00046 CTStudentKernel::~CTStudentKernel() 00047 { 00048 cleanup(); 00049 SG_UNREF(distance); 00050 } 00051 00052 bool CTStudentKernel::init(CFeatures* l, CFeatures* r) 00053 { 00054 ASSERT(distance) 00055 CKernel::init(l,r); 00056 distance->init(l,r); 00057 return init_normalizer(); 00058 } 00059 00060 float64_t CTStudentKernel::compute(int32_t idx_a, int32_t idx_b) 00061 { 00062 float64_t dist = distance->distance(idx_a, idx_b); 00063 return 1.0/(1.0+CMath::pow(dist, this->degree)); 00064 }