73 SG_ERROR(
"Kernel still initialized on destruction.\n")
78 SG_INFO(
"Kernel deleted (%p).\n",
this)
90 REQUIRE(l,
"CKernel::init(%p, %p): Left hand side features required!\n", l, r)
91 REQUIRE(r,
"CKernel::init(%p, %p): Right hand side features required!\n", l, r)
97 "Right hand side of features (%s) must be compatible with left hand side features (%s)\n",
103 "Right hand side of features (%s) must be compatible with left hand side features (%s)\n",
131 SG_DEBUG(
"leaving CKernel::init(%p, %p)\n", l, r)
181 SG_DEBUG(
"entering CKernel::remove_lhs_and_rhs\n")
193 SG_DEBUG(
"leaving CKernel::remove_lhs_and_rhs\n")
219 #define ENUM_CASE(n) case n: SG_INFO(#n " ") break;
226 "SLOWBUTMEMEFFICIENT");
341 int32_t count, int32_t *IDX,
float64_t * weights)
343 SG_ERROR(
"kernel does not support linadd optimization\n")
349 SG_ERROR(
"kernel does not support linadd optimization\n")
355 SG_ERROR(
"kernel does not support linadd optimization\n")
360 int32_t num_vec, int32_t* vec_idx,
float64_t* target, int32_t num_suppvec,
363 SG_ERROR(
"kernel does not support batch computation\n")
368 SG_ERROR(
"kernel does not support linadd optimization, add_to_normal not implemented\n")
373 SG_ERROR(
"kernel does not support linadd optimization, clear_normal not implemented\n")
382 int32_t vector_idx,
float64_t * subkernel_contrib)
384 SG_ERROR(
"kernel compute_by_subkernel not implemented\n")
404 SG_ERROR(
"number of subkernel weights should be one ...\n")
414 REQUIRE(casted,
"CKernel::obtain_from_generic(): Error, provided object"
415 " of class \"%s\" is not a subclass of CKernel!\n",
426 int32_t* sv_idx=SG_MALLOC(int32_t, num_suppvec);
429 for (int32_t i=0; i<num_suppvec; i++)
473 SG_ADD(&
num_lhs,
"num_lhs",
"Number of feature vectors on left hand side.",
475 SG_ADD(&
num_rhs,
"num_rhs",
"Number of feature vectors on right hand side.",
545 "Invalid block begin index (%d, %d)!\n", block_begin, block_begin)
547 "Invalid block size (%d) at starting index (%d, %d)! "
548 "Please use smaller blocks!", block_size, block_begin, block_begin)
549 REQUIRE(block_size>=1,
"Invalid block size (%d)!\n", block_size)
556 #pragma omp parallel for
557 for (
index_t i=0; i<block_size; ++i)
561 for (
index_t j=i+1; j<block_size; ++j)
576 #pragma omp parallel for
577 for (
index_t i=0; i<block_size; ++i)
597 block_begin_col>=0 && block_begin_col<
num_rhs,
598 "Invalid block begin index (%d, %d)!\n",
599 block_begin_row, block_begin_col)
601 block_begin_col+block_size_col<=
num_rhs,
602 "Invalid block size (%d, %d) at starting index (%d, %d)! "
603 "Please use smaller blocks!", block_size_row, block_size_col,
604 block_begin_row, block_begin_col)
605 REQUIRE(block_size_row>=1 && block_size_col>=1,
606 "Invalid block size (%d, %d)!\n", block_size_row, block_size_col)
609 if (no_diag && block_size_row!=block_size_col)
611 SG_WARNING(
"Not removing the main diagonal since block is not square!\n");
618 #pragma omp parallel for
619 for (
index_t i=0; i<block_size_row; ++i)
622 for (
index_t j=0; j<block_size_col; ++j)
625 kernel(i+block_begin_row, j+block_begin_col);
637 index_t block_size,
bool no_diag)
644 "Invalid block begin index (%d, %d)!\n", block_begin, block_begin)
646 "Invalid block size (%d) at starting index (%d, %d)! "
647 "Please use smaller blocks!", block_size, block_begin, block_begin)
648 REQUIRE(block_size>=1,
"Invalid block size (%d)!\n", block_size)
657 #pragma omp parallel for
658 for (
index_t i=0; i<block_size; ++i)
662 for (
index_t j=i+1; j<block_size; ++j)
677 #pragma omp parallel for
678 for (
index_t i=0; i<block_size; ++i)
691 block_begin,
index_t block_size,
bool no_diag)
698 "Invalid block begin index (%d, %d)!\n", block_begin, block_begin)
700 "Invalid block size (%d) at starting index (%d, %d)! "
701 "Please use smaller blocks!", block_size, block_begin, block_begin)
702 REQUIRE(block_size>=1,
"Invalid block size (%d)!\n", block_size)
713 #pragma omp parallel for
714 for (
index_t i=0; i<block_size; ++i)
718 for (
index_t j=i+1; j<block_size; ++j)
735 #pragma omp parallel for
736 for (
index_t i=0; i<block_size; ++i)
740 row_sum(i, 1)+=diag*diag;
751 index_t block_size_col,
bool no_diag)
757 block_begin_col>=0 && block_begin_col<
num_rhs,
758 "Invalid block begin index (%d, %d)!\n",
759 block_begin_row, block_begin_col)
761 block_begin_col+block_size_col<=
num_rhs,
762 "Invalid block size (%d, %d) at starting index (%d, %d)! "
763 "Please use smaller blocks!", block_size_row, block_size_col,
764 block_begin_row, block_begin_col)
765 REQUIRE(block_size_row>=1 && block_size_col>=1,
766 "Invalid block size (%d, %d)!\n", block_size_row, block_size_col)
769 if (no_diag && block_size_row!=block_size_col)
771 SG_WARNING(
"Not removing the main diagonal since block is not square!\n");
782 #pragma omp parallel for
783 for (
index_t i=0; i<block_size_row; ++i)
786 for (
index_t j=0; j<block_size_col; ++j)
789 kernel(i+block_begin_row, j+block_begin_col);
793 sum[j+block_size_row]+=k;
806 int32_t i_start=params->
start;
807 int32_t i_end=params->
end;
816 int64_t total=total_start;
818 for (int32_t i=i_start; i<i_end; i++)
825 for (int32_t j=j_start; j<n; j++)
830 if (symmetric && i!=j)
837 if (symmetric && i!=j)
863 int64_t total_num = int64_t(m)*n;
866 bool symmetric= (
lhs &&
lhs==
rhs && m==n);
868 SG_DEBUG(
"returning kernel matrix of size %dx%d\n", m, n)
870 result=SG_MALLOC(T, total_num);
886 get_kernel_matrix_helper<T>((
void*) ¶ms);
890 pthread_t* threads = SG_MALLOC(pthread_t, num_threads-1);
892 int64_t step= total_num/num_threads;
897 for (t=0; t<num_threads; t++)
900 params[t].
result = result;
910 int code=pthread_create(&threads[t], NULL,
911 CKernel::get_kernel_matrix_helper<T>, (
void*)¶ms[t]);
915 SG_WARNING(
"Thread creation failed (thread %d of %d) "
916 "with error:'%s'\n",t, num_threads, strerror(code));
923 params[t].
result = result;
932 get_kernel_matrix_helper<T>(¶ms[t]);
934 for (t=0; t<num_threads; t++)
936 if (pthread_join(threads[t], NULL) != 0)
937 SG_WARNING(
"pthread_join of thread %d/%d failed\n", t, num_threads)
953 template void* CKernel::get_kernel_matrix_helper<float64_t>(
void* p);
954 template void* CKernel::get_kernel_matrix_helper<float32_t>(
void* p);
virtual void clear_normal()
virtual void load_serializable_post()
virtual bool init(CFeatures *lhs, CFeatures *rhs)
int32_t get_num_support_vectors()
virtual bool support_compatible_class() const
int32_t compute_row_start(int64_t offs, int32_t n, bool symmetric)
virtual EFeatureType get_feature_type() const =0
virtual void set_matrix(const bool *matrix, int32_t num_feat, int32_t num_vec)
virtual void compute_by_subkernel(int32_t vector_idx, float64_t *subkernel_contrib)
virtual bool get_feature_class_compatibility(EFeatureClass rhs) const
int32_t get_num_threads() const
int32_t num_rhs
number of feature vectors on right hand side
static void * get_kernel_matrix_helper(void *p)
Class ShogunException defines an exception which is thrown whenever an error inside of shogun occurs...
virtual bool set_normalizer(CKernelNormalizer *normalizer)
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)
virtual void save_serializable_pre()
virtual bool delete_optimization()
float64_t kernel(int32_t idx_a, int32_t idx_b)
virtual void remove_rhs()
takes all necessary steps if the rhs is removed from kernel
virtual int32_t get_num_vec_lhs()
SGMatrix< float64_t > get_kernel_matrix()
int32_t cache_size
cache_size in MB
bool get_is_initialized()
virtual SGMatrix< float64_t > row_wise_sum_squared_sum_symmetric_block(index_t block_begin, index_t block_size, bool no_diag=true)
float64_t combined_kernel_weight
virtual void register_params()
virtual void remove_lhs_and_rhs()
virtual const char * get_name() const =0
virtual CKernelNormalizer * get_normalizer()
Class SGObject is the base class of all shogun objects.
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)
#define SG_OBJ_PROGRESS(o,...)
virtual float64_t sum_symmetric_block(index_t block_begin, index_t block_size, bool no_diag=true)
virtual SGVector< float64_t > get_subkernel_weights()
virtual EFeatureType get_feature_type()=0
KERNELCACHE_ELEM * kernel_matrix
A File access base class.
virtual void save_serializable_post()
virtual float64_t compute_optimized(int32_t vector_idx)
EOptimizationType get_optimization_type()
virtual void save_serializable_post()
float64_t get_alpha(int32_t idx)
float64_t get_combined_kernel_weight()
virtual SGVector< float64_t > row_wise_sum_symmetric_block(index_t block_begin, index_t block_size, bool no_diag=true)
Identity Kernel Normalization, i.e. no normalization is applied.
int32_t num_lhs
number of feature vectors on left hand side
The class Kernel Normalizer defines a function to post-process kernel values.
int32_t get_support_vector(int32_t idx)
static bool cancel_computations()
virtual int32_t get_num_vec_rhs()
virtual void set_subkernel_weights(SGVector< float64_t > weights)
void set_const(T const_elem)
virtual bool init_normalizer()
virtual EFeatureClass get_feature_class() const =0
bool optimization_initialized
EOptimizationType opt_type
virtual void load_serializable_post()
CFeatures * rhs
feature vectors to occur on right hand side
static CKernel * obtain_from_generic(CSGObject *kernel)
all of classes and functions are contained in the shogun namespace
virtual bool init(CKernel *k)=0
virtual void compute_batch(int32_t num_vec, int32_t *vec_idx, float64_t *target, int32_t num_suppvec, int32_t *IDX, float64_t *alphas, float64_t factor=1.0)
virtual EKernelType get_kernel_type()=0
virtual bool init_optimization(int32_t count, int32_t *IDX, float64_t *weights)
CFeatures * lhs
feature vectors to occur on left hand side
The class Features is the base class of all feature objects.
virtual void save_serializable_pre()
virtual void remove_lhs()
virtual int32_t get_num_subkernels()
bool init_optimization_svm(CSVM *svm)
A generic Support Vector Machine Interface.
CKernelNormalizer * normalizer
void set_const(T const_elem)
virtual bool has_features()
virtual void add_to_normal(int32_t vector_idx, float64_t weight)
virtual int32_t get_num_vectors() const =0
virtual EFeatureClass get_feature_class()=0