SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
statistics
MMDKernelSelectionCombMaxL2.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) 2013 Heiko Strathmann
8
*/
9
10
#include <
shogun/statistics/MMDKernelSelectionCombMaxL2.h
>
11
#include <
shogun/statistics/LinearTimeMMD.h
>
12
#include <
shogun/kernel/CombinedKernel.h
>
13
#include <
shogun/mathematics/Statistics.h
>
14
15
16
using namespace
shogun;
17
18
CMMDKernelSelectionCombMaxL2::CMMDKernelSelectionCombMaxL2
() :
19
CMMDKernelSelectionComb
()
20
{
21
}
22
23
CMMDKernelSelectionCombMaxL2::CMMDKernelSelectionCombMaxL2
(
24
CKernelTwoSampleTest
* mmd) :
CMMDKernelSelectionComb
(mmd)
25
{
26
/* currently, this method is only developed for the linear time MMD */
27
REQUIRE
(mmd->
get_statistic_type
()==
S_QUADRATIC_TIME_MMD
||
28
mmd->
get_statistic_type
()==
S_LINEAR_TIME_MMD
,
"%s::%s(): Only "
29
"CLinearTimeMMD is currently supported! Provided instance is "
30
"\"%s\"\n"
,
get_name
(),
get_name
(), mmd->
get_name
());
31
}
32
33
CMMDKernelSelectionCombMaxL2::~CMMDKernelSelectionCombMaxL2
()
34
{
35
}
36
37
#ifdef HAVE_LAPACK
38
SGVector<float64_t>
CMMDKernelSelectionCombMaxL2::compute_measures
()
39
{
40
/* cast is safe due to assertion in constructor */
41
CCombinedKernel
* kernel=(
CCombinedKernel
*)
m_mmd
->
get_kernel
();
42
index_t
num_kernels=kernel->
get_num_subkernels
();
43
SG_UNREF
(kernel);
44
45
/* compute mmds for all underlying kernels and create identity matrix Q
46
* (see NIPS paper) */
47
SGVector<float64_t>
mmds=
m_mmd
->
compute_statistic
(
true
);
48
49
/* free matrix by hand since it is static */
50
SG_FREE(
m_Q
.
matrix
);
51
m_Q
.
matrix
=NULL;
52
m_Q
.
num_rows
=0;
53
m_Q
.
num_cols
=0;
54
m_Q
=
SGMatrix<float64_t>
(num_kernels, num_kernels,
false
);
55
for
(
index_t
i=0; i<num_kernels; ++i)
56
{
57
for
(
index_t
j=0; j<num_kernels; ++j)
58
m_Q
(i, j)=i==j ? 1 : 0;
59
}
60
61
/* solve the generated problem */
62
SGVector<float64_t>
result=
CMMDKernelSelectionComb::solve_optimization
(mmds);
63
64
/* free matrix by hand since it is static (again) */
65
SG_FREE(
m_Q
.
matrix
);
66
m_Q
.
matrix
=NULL;
67
m_Q
.
num_rows
=0;
68
m_Q
.
num_cols
=0;
69
70
return
result;
71
}
72
#endif
SHOGUN
机器学习工具包 - 项目文档