SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
kernel
PolyKernel.cpp
浏览该文件的文档.
1
/*
2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 3 of the License, or
5
* (at your option) any later version.
6
*
7
* Written (W) 1999-2010 Soeren Sonnenburg
8
* Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9
* Copyright (C) 2010 Berlin Institute of Technology
10
*/
11
12
#include <
shogun/lib/config.h
>
13
#include <
shogun/lib/common.h
>
14
#include <
shogun/io/SGIO.h
>
15
#include <
shogun/kernel/PolyKernel.h
>
16
#include <
shogun/kernel/normalizer/SqrtDiagKernelNormalizer.h
>
17
#include <
shogun/features/DotFeatures.h
>
18
19
using namespace
shogun;
20
21
CPolyKernel::CPolyKernel
()
22
:
CDotKernel
(0), degree(0), inhomogene(false)
23
{
24
init
();
25
26
}
27
28
CPolyKernel::CPolyKernel
(int32_t size, int32_t d,
bool
i)
29
:
CDotKernel
(size), degree(d), inhomogene(i)
30
{
31
init
();
32
}
33
34
CPolyKernel::CPolyKernel
(
35
CDotFeatures
* l,
CDotFeatures
* r, int32_t d,
bool
i, int32_t size)
36
:
CDotKernel
(size), degree(d), inhomogene(i)
37
{
38
init
();
39
init
(l,r);
40
}
41
42
CPolyKernel::~CPolyKernel
()
43
{
44
cleanup
();
45
}
46
47
bool
CPolyKernel::init(
CFeatures
* l,
CFeatures
* r)
48
{
49
CDotKernel::init(l,r);
50
return
init_normalizer
();
51
}
52
53
void
CPolyKernel::cleanup
()
54
{
55
CKernel::cleanup
();
56
}
57
58
float64_t
CPolyKernel::compute
(int32_t idx_a, int32_t idx_b)
59
{
60
float64_t
result=
CDotKernel::compute
(idx_a, idx_b);
61
62
if
(
inhomogene
)
63
result+=1;
64
65
return
CMath::pow
(result,
degree
);
66
}
67
68
void
CPolyKernel::init()
69
{
70
set_normalizer
(
new
CSqrtDiagKernelNormalizer
());
71
SG_ADD
(&
degree
,
"degree"
,
"Degree of polynomial kernel"
,
MS_AVAILABLE
);
72
SG_ADD
(&
inhomogene
,
"inhomogene"
,
"If kernel is inhomogeneous."
,
73
MS_NOT_AVAILABLE
);
74
}
75
SHOGUN
机器学习工具包 - 项目文档