22 #ifdef HAVE_LINALG_LIB
25 using namespace linalg;
26 #endif // HAVE_LINALG_LIB
28 void CCustomKernel::init()
40 "Subset stack of columns", MS_NOT_AVAILABLE);
41 SG_ADD(&m_free_km, "free_km", "Whether kernel matrix should be freed in "
42 "destructor", MS_NOT_AVAILABLE);
43 SG_ADD(&m_is_symmetric, "is_symmetric", "Whether kernel matrix is symmetric",
45 SG_ADD(&kmatrix, "kmatrix", "Kernel matrix.", MS_NOT_AVAILABLE);
46 SG_ADD(&upper_diagonal, "upper_diagonal", "Upper diagonal", MS_NOT_AVAILABLE);
50 new
SGParamInfo("free_km", CT_SCALAR, ST_NONE, PT_BOOL, 1),
56 new SGParamInfo("row_subset_stack", CT_SCALAR, ST_NONE, PT_SGOBJECT, 1),
62 new SGParamInfo("col_subset_stack", CT_SCALAR, ST_NONE, PT_SGOBJECT, 1),
65 m_parameter_map->finalize_map();
69 :
CKernel(10), kmatrix(), upper_diagonal(false)
97 :
CKernel(10), upper_diagonal(false)
106 :
CKernel(10), upper_diagonal(false)
139 REQUIRE(l,
"CFeatures l should not be NULL\n")
140 REQUIRE(r,
"CFeatures r should not be NULL\n")
144 "Different FeatureClass: l is %d, r is %d\n",
147 "Different FeatureType: l is %d, r is %d\n",
183 #ifdef HAVE_LINALG_LIB
186 index_t block_size,
bool no_diag)
192 SG_INFO(
"Row/col subsets initialized! Falling back to "
193 "CKernel::sum_symmetric_block (slower)!\n");
200 "Invalid
block begin index (%d, %d)!\n", block_begin, block_begin)
202 "Invalid
block size (%d) at starting index (%d, %d)! "
203 "Please use smaller blocks!", block_size, block_begin, block_begin)
204 REQUIRE(block_size>=1, "Invalid
block size (%d)!\n", block_size)
208 return sum_symmetric<Backend::EIGEN3>(
block(
kmatrix, block_begin,
209 block_begin, block_size, block_size), no_diag);
214 index_t block_size_col,
bool no_diag)
220 SG_INFO(
"Row/col subsets initialized! Falling back to "
221 "CKernel::sum_block (slower)!\n");
223 block_size_row, block_size_col, no_diag);
226 REQUIRE(kmatrix.matrix,
"The kernel matrix is not initialized!\n")
227 REQUIRE(block_begin_row>=0 && block_begin_row<kmatrix.num_rows &&
228 block_begin_col>=0 && block_begin_col<kmatrix.num_cols,
229 "Invalid
block begin index (%d, %d)!\n",
230 block_begin_row, block_begin_col)
231 REQUIRE(block_begin_row+block_size_row<=kmatrix.num_rows &&
232 block_begin_col+block_size_col<=kmatrix.num_cols,
233 "Invalid
block size (%d, %d) at starting index (%d, %d)! "
234 "Please use smaller blocks!", block_size_row, block_size_col,
235 block_begin_row, block_begin_col)
236 REQUIRE(block_size_row>=1 && block_size_col>=1,
237 "Invalid
block size (%d, %d)!\n", block_size_row, block_size_col)
240 if (no_diag && block_size_row!=block_size_col)
242 SG_WARNING(
"Not removing the main diagonal since block is not square!\n");
248 return sum<Backend::EIGEN3>(
block(kmatrix, block_begin_row, block_begin_col,
249 block_size_row, block_size_col), no_diag);
253 block_begin,
index_t block_size,
bool no_diag)
259 SG_INFO(
"Row/col subsets initialized! Falling back to "
260 "CKernel::row_wise_sum_symmetric_block (slower)!\n");
265 REQUIRE(kmatrix.matrix,
"The kernel matrix is not initialized!\n")
266 REQUIRE(m_is_symmetric, "The
kernel matrix is not symmetric!\n")
267 REQUIRE(block_begin>=0 && block_begin<kmatrix.num_cols,
268 "Invalid
block begin index (%d, %d)!\n", block_begin, block_begin)
269 REQUIRE(block_begin+block_size<=kmatrix.num_cols,
270 "Invalid
block size (%d) at starting index (%d, %d)! "
271 "Please use smaller blocks!", block_size, block_begin, block_begin)
272 REQUIRE(block_size>=1, "Invalid
block size (%d)!\n", block_size)
275 block_begin, block_size, block_size), no_diag);
279 for (
index_t i=0; i<s.vlen; ++i)
294 SG_INFO(
"Row/col subsets initialized! Falling back to "
295 "CKernel::row_wise_sum_squared_sum_symmetric_block (slower)!\n");
297 block_size, no_diag);
300 REQUIRE(kmatrix.matrix,
"The kernel matrix is not initialized!\n")
301 REQUIRE(m_is_symmetric, "The
kernel matrix is not symmetric!\n")
302 REQUIRE(block_begin>=0 && block_begin<kmatrix.num_cols,
303 "Invalid
block begin index (%d, %d)!\n", block_begin, block_begin)
304 REQUIRE(block_begin+block_size<=kmatrix.num_cols,
305 "Invalid
block size (%d) at starting index (%d, %d)! "
306 "Please use smaller blocks!", block_size, block_begin, block_begin)
307 REQUIRE(block_size>=1, "Invalid
block size (%d)!\n", block_size)
315 block_begin, block_begin, block_size, block_size), no_diag);
318 elementwise_square<Backend::EIGEN3>(
block(kmatrix,
319 block_begin, block_begin, block_size, block_size)), no_diag);
321 for (
index_t i=0; i<sum.vlen; ++i)
322 row_sum(i, 0)=sum[i];
324 for (
index_t i=0; i<sq_sum.vlen; ++i)
325 row_sum(i, 1)=sq_sum[i];
334 index_t block_size_col,
bool no_diag)
340 SG_INFO(
"Row/col subsets initialized! Falling back to "
341 "CKernel::row_col_wise_sum_block (slower)!\n");
343 block_size_row, block_size_col, no_diag);
346 REQUIRE(kmatrix.matrix,
"The kernel matrix is not initialized!\n")
347 REQUIRE(block_begin_row>=0 && block_begin_row<kmatrix.num_rows &&
348 block_begin_col>=0 && block_begin_col<kmatrix.num_cols,
349 "Invalid
block begin index (%d, %d)!\n",
350 block_begin_row, block_begin_col)
351 REQUIRE(block_begin_row+block_size_row<=kmatrix.num_rows &&
352 block_begin_col+block_size_col<=kmatrix.num_cols,
353 "Invalid
block size (%d, %d) at starting index (%d, %d)! "
354 "Please use smaller blocks!", block_size_row, block_size_col,
355 block_begin_row, block_begin_col)
356 REQUIRE(block_size_row>=1 && block_size_col>=1,
357 "Invalid
block size (%d, %d)!\n", block_size_row, block_size_col)
360 if (no_diag && block_size_row!=block_size_col)
362 SG_WARNING(
"Not removing the main diagonal since block is not square!\n");
372 block_begin_row, block_begin_col, block_size_row,
373 block_size_col), no_diag);
376 block_begin_row, block_begin_col, block_size_row,
377 block_size_col), no_diag);
382 for (
index_t i=0; i<colwise.vlen; ++i)
383 sum[i+rowwise.
vlen]=colwise[i];
389 #endif // HAVE_EIGEN3
390 #endif // HAVE_LINALG_LIB
Class that holds informations about a certain parameter of an CSGObject. Contains name...
virtual void add_row_subset(SGVector< index_t > subset)
SGMatrix< float32_t > kmatrix
int32_t num_rhs
number of feature vectors on right hand side
The Custom Kernel allows for custom user provided kernel matrices.
The class IndexFeatures implements features that contain the index of the features. This features used in the CCustomKernel::init to make the subset of the kernel matrix. Initial CIndexFeature of row_idx and col_idx, pass them to the CCustomKernel::init(row_idx, col_idx), then use CCustomKernel::get_kernel_matrix() will get the sub kernel matrix specified by the row_idx and col_idx.
SGMatrix< float32_t > get_float32_kernel_matrix()
virtual float64_t sum_block(index_t block_begin_row, index_t block_begin_col, index_t block_size_row, index_t block_size_col, bool no_diag=false)
bool get_lhs_equals_rhs()
CSubsetStack * m_col_subset_stack
virtual int32_t get_num_vectors() const =0
float64_t kernel(int32_t idx_a, int32_t idx_b)
virtual void remove_all_row_subsets()
SGMatrix< float64_t > get_kernel_matrix()
class to add subset support to another class. A CSubsetStackStack instance should be added and wrappe...
virtual SGMatrix< float64_t > row_wise_sum_squared_sum_symmetric_block(index_t block_begin, index_t block_size, bool no_diag=true)
virtual void remove_col_subset()
SGVector< index_t > get_feature_index()
virtual void remove_row_subset()
virtual void add_col_subset(SGVector< index_t > subset)
virtual void add_subset(SGVector< index_t > subset)
Class SGObject is the base class of all shogun objects.
virtual void row_subset_changed_post()
virtual void remove_all_subsets()
virtual SGVector< float64_t > row_col_wise_sum_block(index_t block_begin_row, index_t block_begin_col, index_t block_size_row, index_t block_size_col, bool no_diag=false)
virtual void add_subset_in_place(SGVector< index_t > subset)
virtual float64_t sum_symmetric_block(index_t block_begin, index_t block_size, bool no_diag=true)
bool set_full_kernel_matrix_from_full(SGMatrix< float32_t > full_kernel_matrix, bool check_symmetry=false)
virtual SGVector< float64_t > row_wise_sum_symmetric_block(index_t block_begin, index_t block_size, bool no_diag=true)
virtual EFeatureClass get_feature_class() const =0
int32_t num_lhs
number of feature vectors on left hand side
virtual bool dummy_init(int32_t rows, int32_t cols)
virtual void remove_all_col_subsets()
virtual bool init_normalizer()
CFeatures * rhs
feature vectors to occur on right hand side
The class DummyFeatures implements features that only know the number of feature objects (but don't a...
all of classes and functions are contained in the shogun namespace
virtual EKernelType get_kernel_type()=0
CFeatures * lhs
feature vectors to occur on left hand side
The class Features is the base class of all feature objects.
virtual void col_subset_changed_post()
virtual bool has_subsets() const
virtual void remove_subset()
virtual void add_col_subset_in_place(SGVector< index_t > subset)
CSubsetStack * m_row_subset_stack
virtual void add_row_subset_in_place(SGVector< index_t > subset)
virtual EFeatureType get_feature_type() const =0
Block< Matrix > block(Matrix matrix, index_t row_begin, index_t col_begin, index_t row_size, index_t col_size)