SHOGUN
v2.0.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 Abhinav Maurya 00008 * Copyright (C) 2007-2011 Fraunhofer Institute FIRST and Max-Planck-Society 00009 * Copyright (C) 2011 Indian Institute of Technology Bombay 00010 */ 00011 00012 #include <shogun/kernel/InverseMultiQuadricKernel.h> 00013 #include <shogun/mathematics/Math.h> 00014 00015 using namespace shogun; 00016 00017 CInverseMultiQuadricKernel::CInverseMultiQuadricKernel(): CKernel(0), distance(NULL), coef(0.0001) 00018 { 00019 init(); 00020 } 00021 00022 CInverseMultiQuadricKernel::CInverseMultiQuadricKernel(int32_t cache, float64_t coefficient, CDistance* dist) 00023 : CKernel(cache), distance(dist), coef(coefficient) 00024 { 00025 SG_REF(distance); 00026 init(); 00027 } 00028 00029 CInverseMultiQuadricKernel::CInverseMultiQuadricKernel(CFeatures *l, CFeatures *r, float64_t coefficient, CDistance* dist) 00030 : CKernel(10), distance(dist), coef(coefficient) 00031 { 00032 SG_REF(distance); 00033 init(); 00034 init(l, r); 00035 } 00036 00037 CInverseMultiQuadricKernel::~CInverseMultiQuadricKernel() 00038 { 00039 cleanup(); 00040 SG_UNREF(distance); 00041 } 00042 00043 bool CInverseMultiQuadricKernel::init(CFeatures* l, CFeatures* r) 00044 { 00045 CKernel::init(l,r); 00046 distance->init(l,r); 00047 return init_normalizer(); 00048 } 00049 00050 void CInverseMultiQuadricKernel::load_serializable_post() throw (ShogunException) 00051 { 00052 CKernel::load_serializable_post(); 00053 } 00054 00055 void CInverseMultiQuadricKernel::init() 00056 { 00057 SG_ADD(&coef, "coef", "Kernel Coefficient.", MS_AVAILABLE); 00058 SG_ADD((CSGObject**) &distance, "distance", "Distance to be used.", 00059 MS_AVAILABLE); 00060 } 00061 00062 float64_t CInverseMultiQuadricKernel::compute(int32_t idx_a, int32_t idx_b) 00063 { 00064 float64_t dist = distance->distance(idx_a, idx_b); 00065 return 1/sqrt(dist*dist + coef*coef); 00066 }