SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
statistics
MMDKernelSelection.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) 2012-2013 Heiko Strathmann
8
*/
9
10
#include <
shogun/statistics/MMDKernelSelection.h
>
11
#include <
shogun/kernel/CombinedKernel.h
>
12
#include <
shogun/statistics/KernelTwoSampleTest.h
>
13
#include <
shogun/statistics/LinearTimeMMD.h
>
14
#include <
shogun/statistics/QuadraticTimeMMD.h
>
15
16
17
using namespace
shogun;
18
19
CMMDKernelSelection::CMMDKernelSelection
()
20
{
21
init();
22
}
23
24
CMMDKernelSelection::CMMDKernelSelection
(
25
CKernelTwoSampleTest
* mmd)
26
{
27
init();
28
29
/* ensure that mmd contains an instance of a MMD related class */
30
REQUIRE
(mmd,
"CMMDKernelSelection::CMMDKernelSelection(): No MMD instance "
31
"provided!\n"
);
32
REQUIRE
(mmd->
get_statistic_type
()==
S_LINEAR_TIME_MMD
||
33
mmd->
get_statistic_type
()==
S_QUADRATIC_TIME_MMD
,
34
"CMMDKernelSelection::CMMDKernelSelection(): provided instance "
35
"for kernel two sample testing has to be a MMD-based class! The "
36
"provided is of class \"%s\"\n"
, mmd->
get_name
());
37
38
/* ensure that there is a combined kernel */
39
CKernel
* kernel=mmd->
get_kernel
();
40
REQUIRE
(kernel,
"CMMDKernelSelection::CMMDKernelSelection(): underlying "
41
"\"%s\" has no kernel set!\n"
, mmd->
get_name
());
42
REQUIRE
(kernel->get_kernel_type()==
K_COMBINED
,
"CMMDKernelSelection::"
43
"CMMDKernelSelection(): kernel of underlying \"%s\" is of type \"%s\""
44
" but is has to be CCombinedKernel\n"
, mmd->
get_name
(),
45
kernel->get_name());
46
SG_UNREF
(kernel);
47
48
m_mmd
=mmd;
49
SG_REF
(
m_mmd
);
50
}
51
52
53
CMMDKernelSelection::~CMMDKernelSelection
()
54
{
55
SG_UNREF
(
m_mmd
);
56
}
57
58
void
CMMDKernelSelection::init()
59
{
60
m_mmd
=NULL;
61
62
SG_ADD
((
CSGObject
**)&
m_mmd
,
"mmd"
,
"Underlying MMD instance"
,
63
MS_NOT_AVAILABLE
);
64
}
65
66
CKernel
*
CMMDKernelSelection::select_kernel
()
67
{
68
SG_DEBUG
(
"entering CMMDKernelSelection::select_kernel()\n"
)
69
70
/* compute measures and return single kernel with maximum measure */
71
SGVector<float64_t>
measures=
compute_measures
();
72
73
/* find maximum and return corresponding kernel */
74
float64_t
max=measures[0];
75
index_t
max_idx=0;
76
for
(
index_t
i=1; i<measures.
vlen
; ++i)
77
{
78
if
(measures[i]>max)
79
{
80
max=measures[i];
81
max_idx=i;
82
}
83
}
84
85
/* find kernel with corresponding index */
86
CCombinedKernel
* combined=(
CCombinedKernel
*)
m_mmd
->
get_kernel
();
87
CKernel
* current=combined->
get_kernel
(max_idx);
88
89
SG_UNREF
(combined);
90
SG_DEBUG
(
"leaving CMMDKernelSelection::select_kernel()\n"
);
91
92
/* current is not SG_UNREF'ed nor SG_REF'ed since the counter needs to be
93
* incremented exactly by one */
94
return
current;
95
}
96
SHOGUN
机器学习工具包 - 项目文档