SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
kernel
SphericalKernel.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
* Based on GaussianKernel, Written (W) 1999-2010 Soeren Sonnenburg
8
* Written (W) 2011 Shashwat Lal Das
9
* Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
10
*/
11
12
#include <
shogun/kernel/SphericalKernel.h
>
13
#include <
shogun/mathematics/Math.h
>
14
15
using namespace
shogun;
16
17
CSphericalKernel::CSphericalKernel
():
CKernel
(0),
distance
(NULL)
18
{
19
register_params();
20
set_sigma
(1.0);
21
}
22
23
CSphericalKernel::CSphericalKernel
(int32_t size,
float64_t
sig,
CDistance
* dist)
24
:
CKernel
(size),
distance
(dist)
25
{
26
ASSERT
(
distance
)
27
SG_REF
(
distance
);
28
register_params();
29
set_sigma
(sig);
30
}
31
32
CSphericalKernel::CSphericalKernel
(
33
CFeatures
*l,
CFeatures
*r,
float64_t
sig,
CDistance
* dist)
34
:
CKernel
(10),
distance
(dist)
35
{
36
ASSERT
(
distance
)
37
SG_REF
(
distance
);
38
register_params();
39
set_sigma
(sig);
40
init
(l, r);
41
}
42
43
CSphericalKernel::~CSphericalKernel
()
44
{
45
cleanup
();
46
SG_UNREF
(
distance
);
47
}
48
49
bool
CSphericalKernel::init(
CFeatures
* l,
CFeatures
* r)
50
{
51
ASSERT
(
distance
)
52
CKernel::init(l,r);
53
distance
->
init
(l,r);
54
return
init_normalizer
();
55
}
56
57
void
CSphericalKernel::register_params()
58
{
59
SG_ADD
((
CSGObject
**) &
distance
,
"distance"
,
"Distance to be used."
,
60
MS_AVAILABLE
);
61
SG_ADD
(&
sigma
,
"sigma"
,
"Sigma kernel parameter."
,
MS_AVAILABLE
);
62
}
63
64
float64_t
CSphericalKernel::compute
(int32_t idx_a, int32_t idx_b)
65
{
66
float64_t
dist=
distance
->
distance
(idx_a, idx_b);
67
float64_t
ds_ratio=dist/
sigma
;
68
69
if
(dist <
sigma
)
70
return
1.0-1.5*(ds_ratio)+0.5*(ds_ratio*ds_ratio*ds_ratio);
71
else
72
return
0;
73
}
SHOGUN
机器学习工具包 - 项目文档