SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
PolyKernel.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) 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 <shogun/lib/config.h>
00013 #include <shogun/lib/common.h>
00014 #include <shogun/io/SGIO.h>
00015 #include <shogun/kernel/PolyKernel.h>
00016 #include <shogun/kernel/normalizer/SqrtDiagKernelNormalizer.h>
00017 #include <shogun/features/DotFeatures.h>
00018 
00019 using namespace shogun;
00020 
00021 CPolyKernel::CPolyKernel()
00022 : CDotKernel(0), degree(0), inhomogene(false)
00023 {
00024     init();
00025 
00026 }
00027 
00028 CPolyKernel::CPolyKernel(int32_t size, int32_t d, bool i)
00029 : CDotKernel(size), degree(d), inhomogene(i)
00030 {
00031     init();
00032 }
00033 
00034 CPolyKernel::CPolyKernel(
00035     CDotFeatures* l, CDotFeatures* r, int32_t d, bool i, int32_t size)
00036 : CDotKernel(size), degree(d), inhomogene(i)
00037 {
00038     init();
00039     init(l,r);
00040 }
00041 
00042 CPolyKernel::~CPolyKernel()
00043 {
00044     cleanup();
00045 }
00046 
00047 bool CPolyKernel::init(CFeatures* l, CFeatures* r)
00048 {
00049     CDotKernel::init(l,r);
00050     return init_normalizer();
00051 }
00052 
00053 void CPolyKernel::cleanup()
00054 {
00055     CKernel::cleanup();
00056 }
00057 
00058 float64_t CPolyKernel::compute(int32_t idx_a, int32_t idx_b)
00059 {
00060     float64_t result=CDotKernel::compute(idx_a, idx_b);
00061 
00062     if (inhomogene)
00063         result+=1;
00064 
00065     return CMath::pow(result, degree);
00066 }
00067 
00068 void CPolyKernel::init()
00069 {
00070     set_normalizer(new CSqrtDiagKernelNormalizer());
00071     SG_ADD(&degree, "degree", "Degree of polynomial kernel", MS_AVAILABLE);
00072     SG_ADD(&inhomogene, "inhomogene", "If kernel is inhomogeneous.",
00073             MS_NOT_AVAILABLE);
00074 }
00075 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation