SHOGUN v0.9.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) 1999-2010 Soeren Sonnenburg 00008 * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society 00009 * Copyright (C) 2010 Berlin Institute of Technology 00010 */ 00011 00012 #include "lib/config.h" 00013 #include "lib/common.h" 00014 #include "lib/io.h" 00015 #include "kernel/PolyKernel.h" 00016 #include "kernel/SqrtDiagKernelNormalizer.h" 00017 #include "features/DotFeatures.h" 00018 00019 using namespace shogun; 00020 00021 void 00022 CPolyKernel::init(void) 00023 { 00024 m_parameters->add(°ree, "degree"); 00025 m_parameters->add(&inhomogene, "inhomogene", 00026 "If kernel is inhomogeneous."); 00027 } 00028 00029 CPolyKernel::CPolyKernel(void) 00030 : CDotKernel(0), degree(0), inhomogene(false) 00031 { 00032 init(); 00033 00034 set_normalizer(new CSqrtDiagKernelNormalizer()); 00035 } 00036 00037 CPolyKernel::CPolyKernel(int32_t size, int32_t d, bool i) 00038 : CDotKernel(size), degree(d), inhomogene(i) 00039 { 00040 init(); 00041 00042 set_normalizer(new CSqrtDiagKernelNormalizer()); 00043 } 00044 00045 CPolyKernel::CPolyKernel( 00046 CDotFeatures* l, CDotFeatures* r, int32_t d, bool i, int32_t size) 00047 : CDotKernel(size), degree(d), inhomogene(i) 00048 { 00049 init(); 00050 00051 set_normalizer(new CSqrtDiagKernelNormalizer()); 00052 init(l,r); 00053 } 00054 00055 CPolyKernel::~CPolyKernel() 00056 { 00057 cleanup(); 00058 } 00059 00060 bool CPolyKernel::init(CFeatures* l, CFeatures* r) 00061 { 00062 CDotKernel::init(l,r); 00063 return init_normalizer(); 00064 } 00065 00066 void CPolyKernel::cleanup() 00067 { 00068 CKernel::cleanup(); 00069 } 00070 00071 float64_t CPolyKernel::compute(int32_t idx_a, int32_t idx_b) 00072 { 00073 float64_t result=CDotKernel::compute(idx_a, idx_b); 00074 00075 if (inhomogene) 00076 result+=1; 00077 00078 return CMath::pow(result, degree); 00079 }