SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
MMDKernelSelectionCombOpt.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 
13 
14 
15 using namespace shogun;
16 
19 {
20  init();
21 }
22 
24  CKernelTwoSampleTest* mmd, float64_t lambda) :
26 {
27  /* currently, this method is only developed for the linear time MMD */
28  REQUIRE(dynamic_cast<CLinearTimeMMD*>(mmd), "%s::%s(): Only "
29  "CLinearTimeMMD is currently supported! Provided instance is "
30  "\"%s\"\n", get_name(), get_name(), mmd->get_name());
31 
32  init();
33 
34  m_lambda=lambda;
35 }
36 
38 {
39 }
40 
41 void CMMDKernelSelectionCombOpt::init()
42 {
43  /* set to a sensible standard value that proved to be useful in
44  * experiments, see NIPS paper */
45  m_lambda=1E-5;
46 
47  SG_ADD(&m_lambda, "lambda", "Regularization parameter lambda",
49 }
50 
52 {
53  /* cast is safe due to assertion in constructor */
55  index_t num_kernels=kernel->get_num_subkernels();
56  SG_UNREF(kernel);
57 
58  /* allocate space for MMDs and Q matrix */
59  SGVector<float64_t> mmds(num_kernels);
60 
61  /* free matrix by hand since it is static */
62  SG_FREE(m_Q.matrix);
63  m_Q.matrix=NULL;
64  m_Q.num_rows=0;
65  m_Q.num_cols=0;
66  m_Q=SGMatrix<float64_t>(num_kernels, num_kernels, false);
67 
68  /* online compute mmds and covariance matrix Q of kernels */
69  ((CLinearTimeMMD*)m_estimator)->compute_statistic_and_Q(mmds, m_Q);
70 
71  /* evtl regularize to avoid numerical problems (see NIPS paper) */
72  if (m_lambda)
73  {
74  SG_DEBUG("regularizing matrix Q by adding %f to diagonal\n", m_lambda)
75  for (index_t i=0; i<num_kernels; ++i)
76  m_Q(i,i)+=m_lambda;
77  }
78 
80  {
81  m_Q.display_matrix("(regularized) Q");
82  mmds.display_vector("mmds");
83  }
84 
85  /* solve the generated problem */
87 
88  /* free matrix by hand since it is static (again) */
89  SG_FREE(m_Q.matrix);
90  m_Q.matrix=NULL;
91  m_Q.num_rows=0;
92  m_Q.num_cols=0;
93 
94  return result;
95 }
96 
void display_matrix(const char *name="matrix") const
Definition: SGMatrix.cpp:394
static SGMatrix< float64_t > m_Q
int32_t index_t
Definition: common.h:62
virtual const char * get_name() const
virtual SGVector< float64_t > solve_optimization(SGVector< float64_t > mmds)
#define REQUIRE(x,...)
Definition: SGIO.h:206
index_t num_cols
Definition: SGMatrix.h:378
Kernel two sample test base class. Provides an interface for performing a two-sample test using a ker...
index_t num_rows
Definition: SGMatrix.h:376
void display_vector(const char *name="vector", const char *prefix="") const
Definition: SGVector.cpp:356
SGIO * sg_io
Definition: init.cpp:36
double float64_t
Definition: common.h:50
The Combined kernel is used to combine a number of kernels into a single CombinedKernel object by lin...
EMessageType get_loglevel() const
Definition: SGIO.cpp:285
virtual const char * get_name() const =0
CKernelTwoSampleTest * m_estimator
#define SG_UNREF(x)
Definition: SGObject.h:52
#define SG_DEBUG(...)
Definition: SGIO.h:107
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual SGVector< float64_t > compute_measures()
This class implements the linear time Maximum Mean Statistic as described in [1] for streaming data (...
Definition: LinearTimeMMD.h:66
#define SG_ADD(...)
Definition: SGObject.h:81
Base class for kernel selection of combined kernels. Given an MMD instance whose underlying kernel is...

SHOGUN 机器学习工具包 - 项目文档