SHOGUN  5.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
MMDKernelSelectionCombMaxL2.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) 2013 Heiko Strathmann
8  */
9 
10 #include <shogun/lib/config.h>
11 #ifdef USE_GPL_SHOGUN
12 
17 
18 
19 using namespace shogun;
20 
21 CMMDKernelSelectionCombMaxL2::CMMDKernelSelectionCombMaxL2() :
22  CMMDKernelSelectionComb()
23 {
24 }
25 
26 CMMDKernelSelectionCombMaxL2::CMMDKernelSelectionCombMaxL2(
27  CKernelTwoSampleTest* mmd) : CMMDKernelSelectionComb(mmd)
28 {
29  /* currently, this method is only developed for the linear time MMD */
31  mmd->get_statistic_type()==S_LINEAR_TIME_MMD, "%s::%s(): Only "
32  "CLinearTimeMMD is currently supported! Provided instance is "
33  "\"%s\"\n", get_name(), get_name(), mmd->get_name());
34 }
35 
36 CMMDKernelSelectionCombMaxL2::~CMMDKernelSelectionCombMaxL2()
37 {
38 }
39 
40 SGVector<float64_t> CMMDKernelSelectionCombMaxL2::compute_measures()
41 {
42  /* cast is safe due to assertion in constructor */
43  CCombinedKernel* kernel=(CCombinedKernel*)m_estimator->get_kernel();
44  index_t num_kernels=kernel->get_num_subkernels();
45  SG_UNREF(kernel);
46 
47  /* compute mmds for all underlying kernels and create identity matrix Q
48  * (see NIPS paper) */
49  SGVector<float64_t> mmds=m_estimator->compute_statistic(true);
50 
51  /* free matrix by hand since it is static */
52  SG_FREE(m_Q.matrix);
53  m_Q.matrix=NULL;
54  m_Q.num_rows=0;
55  m_Q.num_cols=0;
56  m_Q=SGMatrix<float64_t>(num_kernels, num_kernels, false);
57  for (index_t i=0; i<num_kernels; ++i)
58  {
59  for (index_t j=0; j<num_kernels; ++j)
60  m_Q(i, j)=i==j ? 1 : 0;
61  }
62 
63  /* solve the generated problem */
64  SGVector<float64_t> result=CMMDKernelSelectionComb::solve_optimization(mmds);
65 
66  /* free matrix by hand since it is static (again) */
67  SG_FREE(m_Q.matrix);
68  m_Q.matrix=NULL;
69  m_Q.num_rows=0;
70  m_Q.num_cols=0;
71 
72  return result;
73 }
74 #endif //USE_GPL_SHOGUN
int32_t index_t
Definition: common.h:62
#define REQUIRE(x,...)
Definition: SGIO.h:206
Kernel two sample test base class. Provides an interface for performing a two-sample test using a ker...
CKernel * get_kernel(int32_t idx)
The Combined kernel is used to combine a number of kernels into a single CombinedKernel object by lin...
virtual const char * get_name() const =0
#define SG_UNREF(x)
Definition: SGObject.h:55
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual EStatisticType get_statistic_type() const =0
virtual const char * get_name() const

SHOGUN Machine Learning Toolbox - Documentation