SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MMDKernelSelection.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 
15 
16 
17 using namespace shogun;
18 
20 {
21  init();
22 }
23 
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");
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 
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",
64 }
65 
67 {
68  SG_DEBUG("entering CMMDKernelSelection::select_kernel()\n")
69 
70  /* compute measures and return single kernel with maximum measure */
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 */
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 Machine Learning Toolbox - Documentation