Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
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 set_normalizer(new CSqrtDiagKernelNormalizer());
00027 }
00028
00029 CPolyKernel::CPolyKernel(int32_t size, int32_t d, bool i)
00030 : CDotKernel(size), degree(d), inhomogene(i)
00031 {
00032 init();
00033
00034 set_normalizer(new CSqrtDiagKernelNormalizer());
00035 }
00036
00037 CPolyKernel::CPolyKernel(
00038 CDotFeatures* l, CDotFeatures* r, int32_t d, bool i, int32_t size)
00039 : CDotKernel(size), degree(d), inhomogene(i)
00040 {
00041 init();
00042
00043 set_normalizer(new CSqrtDiagKernelNormalizer());
00044 init(l,r);
00045 }
00046
00047 CPolyKernel::~CPolyKernel()
00048 {
00049 cleanup();
00050 }
00051
00052 bool CPolyKernel::init(CFeatures* l, CFeatures* r)
00053 {
00054 CDotKernel::init(l,r);
00055 return init_normalizer();
00056 }
00057
00058 void CPolyKernel::cleanup()
00059 {
00060 CKernel::cleanup();
00061 }
00062
00063 float64_t CPolyKernel::compute(int32_t idx_a, int32_t idx_b)
00064 {
00065 float64_t result=CDotKernel::compute(idx_a, idx_b);
00066
00067 if (inhomogene)
00068 result+=1;
00069
00070 return CMath::pow(result, degree);
00071 }
00072
00073 void CPolyKernel::init()
00074 {
00075 SG_ADD(°ree, "degree", "Degree of polynomial kernel", MS_AVAILABLE);
00076 SG_ADD(&inhomogene, "inhomogene", "If kernel is inhomogeneous.",
00077 MS_NOT_AVAILABLE);
00078 }
00079