SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
kernel
TStudentKernel.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) 2011 Andrew Tereskin
8
* Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
9
*/
10
11
#include <math.h>
12
#include <
shogun/kernel/TStudentKernel.h
>
13
#include <
shogun/mathematics/Math.h
>
14
15
using namespace
shogun;
16
17
void
CTStudentKernel::init()
18
{
19
SG_ADD
(&
degree
,
"degree"
,
"Kernel degree."
,
MS_AVAILABLE
);
20
SG_ADD
((
CSGObject
**) &
distance
,
"distance"
,
"Distance to be used."
,
21
MS_AVAILABLE
);
22
}
23
24
CTStudentKernel::CTStudentKernel
():
CKernel
(0),
distance
(NULL), degree(1.0)
25
{
26
init
();
27
}
28
29
CTStudentKernel::CTStudentKernel
(int32_t cache,
float64_t
d,
CDistance
* dist)
30
:
CKernel
(cache),
distance
(dist), degree(d)
31
{
32
init
();
33
ASSERT
(
distance
)
34
SG_REF
(
distance
);
35
}
36
37
CTStudentKernel::CTStudentKernel
(
CFeatures
*l,
CFeatures
*r,
float64_t
d,
CDistance
* dist)
38
:
CKernel
(10),
distance
(dist), degree(d)
39
{
40
init
();
41
ASSERT
(
distance
)
42
SG_REF
(
distance
);
43
init
(l, r);
44
}
45
46
CTStudentKernel::~CTStudentKernel
()
47
{
48
cleanup
();
49
SG_UNREF
(
distance
);
50
}
51
52
bool
CTStudentKernel::init(
CFeatures
* l,
CFeatures
* r)
53
{
54
ASSERT
(
distance
)
55
CKernel::init(l,r);
56
distance
->
init
(l,r);
57
return
init_normalizer
();
58
}
59
60
float64_t
CTStudentKernel::compute
(int32_t idx_a, int32_t idx_b)
61
{
62
float64_t
dist =
distance
->
distance
(idx_a, idx_b);
63
return
1.0/(1.0+
CMath::pow
(dist, this->
degree
));
64
}
SHOGUN
机器学习工具包 - 项目文档