SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
kernel
ExponentialKernel.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
* Gaussian Kernel used as template, attribution:
8
* Written (W) 1999-2010 Soeren Sonnenburg
9
* Exponential Kernel
10
* Written (W) 2011 Justin Patera
11
* Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
12
*/
13
14
#include <
shogun/lib/common.h
>
15
#include <
shogun/base/Parameter.h
>
16
#include <
shogun/kernel/ExponentialKernel.h
>
17
#include <
shogun/features/DotFeatures.h
>
18
#include <
shogun/io/SGIO.h
>
19
20
using namespace
shogun;
21
22
CExponentialKernel::CExponentialKernel
()
23
:
CDotKernel
(), m_distance(NULL), m_width(1)
24
{
25
init
();
26
}
27
28
CExponentialKernel::CExponentialKernel
(
29
CDotFeatures
* l,
CDotFeatures
* r,
float64_t
width,
CDistance
*
distance
, int32_t size)
30
:
CDotKernel
(size), m_distance(distance), m_width(width)
31
{
32
init
();
33
ASSERT
(distance)
34
SG_REF
(distance);
35
init
(l,r);
36
}
37
38
CExponentialKernel::~CExponentialKernel
()
39
{
40
cleanup
();
41
SG_UNREF
(
m_distance
);
42
}
43
44
void
CExponentialKernel::cleanup
()
45
{
46
CKernel::cleanup
();
47
}
48
49
bool
CExponentialKernel::init(
CFeatures
* l,
CFeatures
* r)
50
{
51
ASSERT
(
m_distance
)
52
CDotKernel::init(l, r);
53
m_distance
->
init
(l, r);
54
return
init_normalizer
();
55
}
56
57
float64_t
CExponentialKernel::compute
(int32_t idx_a, int32_t idx_b)
58
{
59
ASSERT
(
m_distance
)
60
float64_t
dist=
m_distance
->
distance
(idx_a, idx_b);
61
return
exp(-dist/
m_width
);
62
}
63
64
void
CExponentialKernel::load_serializable_post
() throw (
ShogunException
)
65
{
66
CKernel::load_serializable_post
();
67
}
68
69
70
void
CExponentialKernel::init()
71
{
72
SG_ADD
(&
m_width
,
"width"
,
"Kernel width."
,
MS_AVAILABLE
);
73
SG_ADD
((
CSGObject
**) &
m_distance
,
"distance"
,
"Distance to be used."
,
74
MS_AVAILABLE
);
75
}
SHOGUN
机器学习工具包 - 项目文档