SHOGUN
v3.0.0
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
statistics
MMDKernelSelectionOpt.cpp
Go to the documentation of this file.
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/MMDKernelSelectionOpt.h
>
11
#include <
shogun/statistics/LinearTimeMMD.h
>
12
#include <
shogun/kernel/CombinedKernel.h
>
13
14
using namespace
shogun;
15
16
CMMDKernelSelectionOpt::CMMDKernelSelectionOpt
() :
17
CMMDKernelSelection
()
18
{
19
init();
20
}
21
22
CMMDKernelSelectionOpt::CMMDKernelSelectionOpt
(
23
CKernelTwoSampleTestStatistic
* mmd,
float64_t
lambda) :
24
CMMDKernelSelection
(mmd)
25
{
26
init();
27
28
/* currently, this method is only developed for the linear time MMD */
29
REQUIRE
(dynamic_cast<CLinearTimeMMD*>(mmd),
"%s::%s(): Only "
30
"CLinearTimeMMD is currently supported! Provided instance is "
31
"\"%s\"\n"
,
get_name
(),
get_name
(), mmd->
get_name
());
32
33
m_lambda
=lambda;
34
}
35
36
CMMDKernelSelectionOpt::~CMMDKernelSelectionOpt
()
37
{
38
}
39
40
SGVector<float64_t>
CMMDKernelSelectionOpt::compute_measures
()
41
{
42
/* comnpute mmd on all subkernels using the same data. Note that underlying
43
* kernel was asserted to be a combined one */
44
SGVector<float64_t>
mmds;
45
SGVector<float64_t>
vars;
46
((
CLinearTimeMMD
*)
m_mmd
)->compute_statistic_and_variance(mmds, vars,
true
);
47
48
/* we know that the underlying MMD is linear time version, cast is safe */
49
SGVector<float64_t>
measures(mmds.
vlen
);
50
51
for
(
index_t
i=0; i<measures.
vlen
; ++i)
52
measures[i]=mmds[i]/(
CMath::sqrt
(vars[i])+
m_lambda
);
53
54
return
measures;
55
}
56
57
void
CMMDKernelSelectionOpt::init()
58
{
59
/* set to a sensible standard value that proved to be useful in
60
* experiments, see NIPS paper */
61
m_lambda
=1E-5;
62
}
SHOGUN
Machine Learning Toolbox - Documentation