SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CustomKernel.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) 1999-2009 Soeren Sonnenburg
8  * Written (W) 2012 Heiko Strathmann
9  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
10  */
11 
12 #include <shogun/lib/common.h>
16 #include <shogun/io/SGIO.h>
18 
19 using namespace shogun;
20 
21 void
22 CCustomKernel::init()
23 {
28  m_free_km=true;
29 
30  SG_ADD((CSGObject**)&m_row_subset_stack, "row_subset_stack",
31  "Subset stack of rows", MS_NOT_AVAILABLE);
32  SG_ADD((CSGObject**)&m_col_subset_stack, "col_subset_stack",
33  "Subset stack of columns", MS_NOT_AVAILABLE);
34  SG_ADD(&m_free_km, "free_km", "Whether kernel matrix should be freed in "
35  "destructor", MS_NOT_AVAILABLE);
36  SG_ADD(&kmatrix, "kmatrix", "Kernel matrix.", MS_NOT_AVAILABLE);
37  SG_ADD(&upper_diagonal, "upper_diagonal", "Upper diagonal", MS_NOT_AVAILABLE);
38 
39  /* new parameter from param version 0 to 1 */
40  m_parameter_map->put(
41  new SGParamInfo("free_km", CT_SCALAR, ST_NONE, PT_BOOL, 1),
42  new SGParamInfo()
43  );
44 
45  /* new parameter from param version 0 to 1 */
46  m_parameter_map->put(
47  new SGParamInfo("row_subset_stack", CT_SCALAR, ST_NONE, PT_SGOBJECT, 1),
48  new SGParamInfo()
49  );
50 
51  /* new parameter from param version 0 to 1 */
52  m_parameter_map->put(
53  new SGParamInfo("col_subset_stack", CT_SCALAR, ST_NONE, PT_SGOBJECT, 1),
54  new SGParamInfo()
55  );
56  m_parameter_map->finalize_map();
57 }
58 
60 : CKernel(10), kmatrix(), upper_diagonal(false)
61 {
62  SG_DEBUG("created CCustomKernel\n")
63  init();
64 }
65 
67 : CKernel(10)
68 {
69  SG_DEBUG("created CCustomKernel\n")
70  init();
71 
72  /* if constructed from a custom kernel, use same kernel matrix */
73  if (k->get_kernel_type()==K_CUSTOM)
74  {
75  CCustomKernel* casted=(CCustomKernel*)k;
77  m_free_km=false;
78  }
79  else
81 }
82 
84 : CKernel(10), upper_diagonal(false)
85 {
86  SG_DEBUG("Entering CCustomKernel::CCustomKernel(SGMatrix<float64_t>)\n")
87  init();
89  SG_DEBUG("Leaving CCustomKernel::CCustomKernel(SGMatrix<float64_t>)\n")
90 }
91 
93 : CKernel(10), upper_diagonal(false)
94 {
95  SG_DEBUG("Entering CCustomKernel::CCustomKernel(SGMatrix<float64_t>)\n")
96  init();
98  SG_DEBUG("Leaving CCustomKernel::CCustomKernel(SGMatrix<float64_t>)\n")
99 }
100 
102 {
103  SG_DEBUG("Entering CCustomKernel::~CCustomKernel()\n")
104  cleanup();
107  SG_DEBUG("Leaving CCustomKernel::~CCustomKernel()\n")
108 }
109 
110 bool CCustomKernel::dummy_init(int32_t rows, int32_t cols)
111 {
112  return init(new CDummyFeatures(rows), new CDummyFeatures(cols));
113 }
114 
115 bool CCustomKernel::init(CFeatures* l, CFeatures* r)
116 {
117  /* make it possible to call with NULL values since features are useless
118  * for custom kernel matrix */
119  if (!l)
120  l=lhs;
121 
122  if (!r)
123  r=rhs;
124 
125  CKernel::init(l, r);
126 
127  SG_DEBUG("num_vec_lhs: %d vs num_rows %d\n", l->get_num_vectors(), kmatrix.num_rows)
128  SG_DEBUG("num_vec_rhs: %d vs num_cols %d\n", r->get_num_vectors(), kmatrix.num_cols)
131  return init_normalizer();
132 }
133 
135 {
136  SG_DEBUG("Entering CCustomKernel::cleanup_custom()\n")
139 
141  upper_diagonal=false;
142 
143  SG_DEBUG("Leaving CCustomKernel::cleanup_custom()\n")
144 }
145 
147 {
150  cleanup_custom();
152 }
153 
155 {
158 }
159 
161 {
164 }
165 
167 {
170 }
171 
173 {
176  else
178 }
179 
181 {
184 }
185 
187 {
190 }
191 
193 {
196 }
197 
199 {
202  else
204 }

SHOGUN Machine Learning Toolbox - Documentation