21 using namespace linalg;
23 void CCustomKernel::init()
36 SG_ADD(&m_free_km,
"free_km",
"Whether kernel matrix should be freed in " 38 SG_ADD(&m_is_symmetric,
"is_symmetric",
"Whether kernel matrix is symmetric",
45 :
CKernel(10), kmatrix(), upper_diagonal(false)
115 REQUIRE(l,
"CFeatures l should not be NULL\n")
116 REQUIRE(r,
"CFeatures r should not be NULL\n")
120 "Different FeatureClass: l is %d, r is %d\n",
123 "Different FeatureType: l is %d, r is %d\n",
160 index_t block_size,
bool no_diag)
166 SG_INFO(
"Row/col subsets initialized! Falling back to " 167 "CKernel::sum_symmetric_block (slower)!\n");
174 "Invalid block begin index (%d, %d)!\n", block_begin, block_begin)
176 "Invalid block size (%d) at starting index (%d, %d)! " 177 "Please use smaller blocks!", block_size, block_begin, block_begin)
178 REQUIRE(block_size>=1,
"Invalid block size (%d)!\n", block_size)
183 block_begin, block_size, block_size), no_diag);
188 index_t block_size_col,
bool no_diag)
194 SG_INFO(
"Row/col subsets initialized! Falling back to " 195 "CKernel::sum_block (slower)!\n");
197 block_size_row, block_size_col, no_diag);
203 "Invalid block begin index (%d, %d)!\n",
204 block_begin_row, block_begin_col)
207 "Invalid block size (%d, %d) at starting index (%d, %d)! " 208 "Please use smaller blocks!", block_size_row, block_size_col,
209 block_begin_row, block_begin_col)
210 REQUIRE(block_size_row>=1 && block_size_col>=1,
211 "Invalid block size (%d, %d)!\n", block_size_row, block_size_col)
214 if (no_diag && block_size_row!=block_size_col)
216 SG_WARNING(
"Not removing the main diagonal since block is not square!\n");
223 block_size_row, block_size_col), no_diag);
227 block_begin,
index_t block_size,
bool no_diag)
233 SG_INFO(
"Row/col subsets initialized! Falling back to " 234 "CKernel::row_wise_sum_symmetric_block (slower)!\n");
242 "Invalid block begin index (%d, %d)!\n", block_begin, block_begin)
244 "Invalid block size (%d) at starting index (%d, %d)! " 245 "Please use smaller blocks!", block_size, block_begin, block_begin)
246 REQUIRE(block_size>=1,
"Invalid block size (%d)!\n", block_size)
249 block_begin, block_size, block_size), no_diag);
268 SG_INFO(
"Row/col subsets initialized! Falling back to " 269 "CKernel::row_wise_sum_squared_sum_symmetric_block (slower)!\n");
271 block_size, no_diag);
277 "Invalid block begin index (%d, %d)!\n", block_begin, block_begin)
279 "Invalid block size (%d) at starting index (%d, %d)! " 280 "Please use smaller blocks!", block_size, block_begin, block_begin)
281 REQUIRE(block_size>=1,
"Invalid block size (%d)!\n", block_size)
289 block_begin, block_begin, block_size, block_size), no_diag);
291 auto kmatrix_block =
block(
kmatrix, block_begin, block_begin, block_size, block_size);
296 row_sum(i, 0)=sum[i];
299 row_sum(i, 1)=sq_sum[i];
308 index_t block_size_col,
bool no_diag)
314 SG_INFO(
"Row/col subsets initialized! Falling back to " 315 "CKernel::row_col_wise_sum_block (slower)!\n");
317 block_size_row, block_size_col, no_diag);
323 "Invalid block begin index (%d, %d)!\n",
324 block_begin_row, block_begin_col)
327 "Invalid block size (%d, %d) at starting index (%d, %d)! " 328 "Please use smaller blocks!", block_size_row, block_size_col,
329 block_begin_row, block_begin_col)
330 REQUIRE(block_size_row>=1 && block_size_col>=1,
331 "Invalid block size (%d, %d)!\n", block_size_row, block_size_col)
334 if (no_diag && block_size_row!=block_size_col)
336 SG_WARNING(
"Not removing the main diagonal since block is not square!\n");
346 block_begin_row, block_begin_col, block_size_row,
347 block_size_col), no_diag);
350 block_begin_row, block_begin_col, block_size_row,
351 block_size_col), no_diag);
357 sum[i+rowwise.
vlen]=colwise[i];
T sum_symmetric(const SGMatrix< T > &a, bool no_diag=false)
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.
virtual SGMatrix< float64_t > row_wise_sum_squared_sum_symmetric_block(index_t block_begin, index_t block_size, bool no_diag=true)
SGMatrix< float32_t > get_float32_kernel_matrix()
virtual SGVector< float64_t > row_wise_sum_symmetric_block(index_t block_begin, index_t block_size, bool no_diag=true)
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()
SGVector< T > rowwise_sum(const SGMatrix< T > &mat, bool no_diag=false)
CSubsetStack * m_col_subset_stack
virtual bool has_subsets() const
virtual int32_t get_num_vectors() const =0
virtual float64_t sum_symmetric_block(index_t block_begin, index_t block_size, bool no_diag=true)
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 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)
SGVector< T > colwise_sum(const SGMatrix< T > &mat, bool no_diag=false)
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
T sum(const Container< T > &a, bool no_diag=false)
virtual EKernelType get_kernel_type()=0
CFeatures * lhs
feature vectors to occur on left hand side
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)
The class Features is the base class of all feature objects.
virtual void col_subset_changed_post()
virtual void remove_subset()
virtual void add_col_subset_in_place(SGVector< index_t > subset)
CSubsetStack * m_row_subset_stack
void element_prod(Block< SGMatrix< T >> &a, Block< SGMatrix< T >> &b, SGMatrix< T > &result)
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)