SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
KernelDependenceMaximization.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) The Shogun Machine Learning Toolbox
3  * Written (w) 2014 Soumyajit De
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * The views and conclusions contained in the software and documentation are those
27  * of the authors and should not be interpreted as representing official policies,
28  * either expressed or implied, of the Shogun Development Team.
29  */
30 
34 
35 using namespace shogun;
36 
39 {
40  initialize_parameters();
41 }
42 
43 void CKernelDependenceMaximization::initialize_parameters()
44 {
45  SG_ADD((CSGObject**)&m_kernel_features, "kernel_features",
46  "the kernel to be used for features", MS_NOT_AVAILABLE);
47  SG_ADD((CSGObject**)&m_kernel_labels, "kernel_labels",
48  "the kernel to be used for labels", MS_NOT_AVAILABLE);
49 
50  m_kernel_features=NULL;
51  m_kernel_labels=NULL;
52 }
53 
55 {
58 }
59 
61 {
62  SG_DEBUG("Entering!\n");
63 
64  REQUIRE(m_labels_feats, "Features for labels is not initialized!\n");
65  REQUIRE(m_kernel_labels, "Kernel for labels is not initialized!\n");
66 
67  // ASSERT here because the estimator is set internally and cannot
68  // be set via public API
70 
72 
73  // make sure that we have an instance of CKernelIndependenceTest via
74  // proper cast and set this kernel to the estimator
75  CKernelIndependenceTest* estimator
76  =dynamic_cast<CKernelIndependenceTest*>(m_estimator);
77  ASSERT(estimator);
78 
79  // precompute the kernel for labels
81  CCustomKernel* precomputed
83 
84  // replace the kernel for labels with precomputed kernel
86  m_kernel_labels=precomputed;
88 
89  // we can safely SG_UNREF the feature object for labels now
91  m_labels_feats=NULL;
92 
93  // finally set this as kernel for the labels
94  estimator->set_kernel_q(m_kernel_labels);
95 
96  SG_DEBUG("Leaving!\n");
97 }
98 
100 {
101  // sanity check. using assert here because estimator instances are
102  // set internally and cannot be set via public API.
104  CKernelIndependenceTest* estimator
105  =dynamic_cast<CKernelIndependenceTest*>(m_estimator);
106  ASSERT(estimator);
107 
108  SG_REF(kernel);
110  m_kernel_features=kernel;
111 
112  estimator->set_kernel_p(m_kernel_features);
113 }
114 
116 {
117  // sanity check. using assert here because estimator instances are
118  // set internally and cannot be set via public API.
120  CKernelIndependenceTest* estimator
121  =dynamic_cast<CKernelIndependenceTest*>(m_estimator);
122  ASSERT(estimator);
123 
124  SG_REF(kernel);
126  m_kernel_labels=kernel;
127 
128  estimator->set_kernel_q(m_kernel_labels);
129 }
130 
132 {
134  return m_kernel_features;
135 }
136 
138 {
140  return m_kernel_labels;
141 }
virtual bool init(CFeatures *lhs, CFeatures *rhs)
Definition: Kernel.cpp:98
The Custom Kernel allows for custom user provided kernel matrices.
Definition: CustomKernel.h:36
Class CDependenceMaximization, base class for all feature selection preprocessors which select a subs...
#define REQUIRE(x,...)
Definition: SGIO.h:206
virtual void set_kernel_q(CKernel *kernel_q)
SGMatrix< float64_t > get_kernel_matrix()
Definition: Kernel.h:220
#define SG_REF(x)
Definition: SGObject.h:54
#define ASSERT(x)
Definition: SGIO.h:201
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:115
#define SG_UNREF(x)
Definition: SGObject.h:55
#define SG_DEBUG(...)
Definition: SGIO.h:107
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual void set_kernel_p(CKernel *kernel_p)
Kernel independence test base class. Provides an interface for performing an independence test...
The Kernel base class.
Definition: Kernel.h:159
#define SG_ADD(...)
Definition: SGObject.h:84

SHOGUN Machine Learning Toolbox - Documentation